validation-bugsnag-email

This commit is contained in:
RafficMohammed
2023-01-31 13:17:59 +05:30
parent 2ec836b447
commit 9dd3f53910
769 changed files with 20242 additions and 14060 deletions

View File

@@ -33,23 +33,9 @@ class Operations
*/
public static function logicalAnd(...$args)
{
$args = Functions::flattenArray($args);
if (count($args) == 0) {
return ExcelError::VALUE();
}
$args = array_filter($args, function ($value) {
return $value !== null || (is_string($value) && trim($value) == '');
return self::countTrueValues($args, function (int $trueValueCount, int $count): bool {
return $trueValueCount === $count;
});
$returnValue = self::countTrueValues($args);
if (is_string($returnValue)) {
return $returnValue;
}
$argCount = count($args);
return ($returnValue > 0) && ($returnValue == $argCount);
}
/**
@@ -74,22 +60,9 @@ class Operations
*/
public static function logicalOr(...$args)
{
$args = Functions::flattenArray($args);
if (count($args) == 0) {
return ExcelError::VALUE();
}
$args = array_filter($args, function ($value) {
return $value !== null || (is_string($value) && trim($value) == '');
return self::countTrueValues($args, function (int $trueValueCount): bool {
return $trueValueCount > 0;
});
$returnValue = self::countTrueValues($args);
if (is_string($returnValue)) {
return $returnValue;
}
return $returnValue > 0;
}
/**
@@ -116,22 +89,9 @@ class Operations
*/
public static function logicalXor(...$args)
{
$args = Functions::flattenArray($args);
if (count($args) == 0) {
return ExcelError::VALUE();
}
$args = array_filter($args, function ($value) {
return $value !== null || (is_string($value) && trim($value) == '');
return self::countTrueValues($args, function (int $trueValueCount): bool {
return $trueValueCount % 2 === 1;
});
$returnValue = self::countTrueValues($args);
if (is_string($returnValue)) {
return $returnValue;
}
return $returnValue % 2 == 1;
}
/**
@@ -177,31 +137,36 @@ class Operations
}
/**
* @return int|string
* @return bool|string
*/
private static function countTrueValues(array $args)
private static function countTrueValues(array $args, callable $func)
{
$trueValueCount = 0;
$count = 0;
foreach ($args as $arg) {
$aArgs = Functions::flattenArrayIndexed($args);
foreach ($aArgs as $k => $arg) {
++$count;
// Is it a boolean value?
if (is_bool($arg)) {
$trueValueCount += $arg;
} elseif ((is_numeric($arg)) && (!is_string($arg))) {
$trueValueCount += ((int) $arg != 0);
} elseif (is_string($arg)) {
$isLiteral = !Functions::isCellValue($k);
$arg = mb_strtoupper($arg, 'UTF-8');
if (($arg == 'TRUE') || ($arg == Calculation::getTRUE())) {
$arg = true;
} elseif (($arg == 'FALSE') || ($arg == Calculation::getFALSE())) {
$arg = false;
if ($isLiteral && ($arg == 'TRUE' || $arg == Calculation::getTRUE())) {
++$trueValueCount;
} elseif ($isLiteral && ($arg == 'FALSE' || $arg == Calculation::getFALSE())) {
//$trueValueCount += 0;
} else {
return ExcelError::VALUE();
--$count;
}
$trueValueCount += ($arg != 0);
} elseif (is_int($arg) || is_float($arg)) {
$trueValueCount += (int) ($arg != 0);
} else {
--$count;
}
}
return $trueValueCount;
return ($count === 0) ? ExcelError::VALUE() : $func($trueValueCount, $count);
}
}