MathTrig - Fix Phpstan Accomodations (#2020)
* MathTrig - Fix Phpstan Accomodations This should be the last of my mass changes to MathTrig. All he Phpstan violations found in baseline which are part of MathTrig are now fixed and removed from baseline. There were about 20 of these.
This commit is contained in:
parent
557601f584
commit
a01a401228
|
|
@ -1230,136 +1230,6 @@ parameters:
|
|||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\:\\:COMBIN\\(\\) should return int\\|string but returns float\\|int\\|string\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\:\\:EVEN\\(\\) should return int\\|string but returns float\\|string\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\:\\:FACT\\(\\) should return int\\|string but returns float\\|int\\|string\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\:\\:FACTDOUBLE\\(\\) should return int\\|string but returns float\\|int\\|string\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\:\\:MOD\\(\\) should return int\\|string but returns float\\|int\\|string\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\:\\:ODD\\(\\) should return int\\|string but returns float\\|string\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\:\\:SUMIFS\\(\\) should return float\\|string but returns float\\|string\\|null\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig.php
|
||||
|
||||
-
|
||||
message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig/Arabic.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$number of function base_convert expects string, int\\<0, 9007199254740991\\> given\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig/Base.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Helpers\\:\\:validateNumericNullBool\\(\\) should return float\\|int but returns float\\|int\\|string\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig/Helpers.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Helpers\\:\\:validateNumericNullSubstitution\\(\\) should return float\\|int but returns float\\|int\\|string\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig/Helpers.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Lcm\\:\\:factors\\(\\) has no return typehint specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig/Lcm.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Lcm\\:\\:factors\\(\\) has parameter \\$value with no typehint specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig/Lcm.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Roman\\:\\:romanCut\\(\\) has no return typehint specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig/Roman.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Roman\\:\\:romanCut\\(\\) has parameter \\$n with no typehint specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig/Roman.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Roman\\:\\:romanCut\\(\\) has parameter \\$num with no typehint specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig/Roman.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$precision of function round expects int, float\\|int given\\.$#"
|
||||
count: 2
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig/RoundDown.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#2 \\$precision of function round expects int, float\\|int given\\.$#"
|
||||
count: 2
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig/RoundUp.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Subtotal\\:\\:filterHiddenArgs\\(\\) has no return typehint specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Subtotal\\:\\:filterHiddenArgs\\(\\) has parameter \\$args with no typehint specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Subtotal\\:\\:filterHiddenArgs\\(\\) has parameter \\$cellReference with no typehint specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Subtotal\\:\\:filterFormulaArgs\\(\\) has no return typehint specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Subtotal\\:\\:filterFormulaArgs\\(\\) has parameter \\$args with no typehint specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
|
||||
|
||||
-
|
||||
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\MathTrig\\\\Subtotal\\:\\:filterFormulaArgs\\(\\) has parameter \\$cellReference with no typehint specified\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$function of function call_user_func_array expects callable\\(\\)\\: mixed, array\\('PhpOffice…'\\|'PhpOffice…'\\|'PhpOffice…'\\|'PhpOffice…'\\|'PhpOffice…'\\|'PhpOffice…'\\|'PhpOffice…'\\|'PhpOffice…', string\\) given\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
|
||||
|
||||
-
|
||||
message: "#^Parameter \\#1 \\$str of function rtrim expects string, int given\\.$#"
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php
|
||||
|
||||
-
|
||||
message: "#^Binary operation \"\\-\" between float\\|int and float\\|string results in an error\\.$#"
|
||||
count: 4
|
||||
|
|
@ -8095,16 +7965,6 @@ parameters:
|
|||
count: 1
|
||||
path: tests/PhpSpreadsheetTests/Calculation/Engine/RangeTest.php
|
||||
|
||||
-
|
||||
message: "#^Cannot call method setVisible\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
|
||||
count: 1
|
||||
path: tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SubTotalTest.php
|
||||
|
||||
-
|
||||
message: "#^Cannot call method setVisible\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\RowDimension\\|null\\.$#"
|
||||
count: 1
|
||||
path: tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SubTotalTest.php
|
||||
|
||||
-
|
||||
message: "#^Cannot call method setAutoSize\\(\\) on PhpOffice\\\\PhpSpreadsheet\\\\Worksheet\\\\ColumnDimension\\|null\\.$#"
|
||||
count: 1
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ class MathTrig
|
|||
* @param int $numObjs Number of different objects
|
||||
* @param int $numInSet Number of objects in each combination
|
||||
*
|
||||
* @return int|string Number of combinations, or a string containing an error
|
||||
* @return float|int|string Number of combinations, or a string containing an error
|
||||
*/
|
||||
public static function COMBIN($numObjs, $numInSet)
|
||||
{
|
||||
|
|
@ -150,7 +150,7 @@ class MathTrig
|
|||
*
|
||||
* @param float $number Number to round
|
||||
*
|
||||
* @return int|string Rounded Number, or a string containing an error
|
||||
* @return float|int|string Rounded Number, or a string containing an error
|
||||
*/
|
||||
public static function EVEN($number)
|
||||
{
|
||||
|
|
@ -186,7 +186,7 @@ class MathTrig
|
|||
*
|
||||
* @param float $factVal Factorial Value
|
||||
*
|
||||
* @return int|string Factorial, or a string containing an error
|
||||
* @return float|int|string Factorial, or a string containing an error
|
||||
*/
|
||||
public static function FACT($factVal)
|
||||
{
|
||||
|
|
@ -208,7 +208,7 @@ class MathTrig
|
|||
*
|
||||
* @param float $factVal Factorial Value
|
||||
*
|
||||
* @return int|string Double Factorial, or a string containing an error
|
||||
* @return float|int|string Double Factorial, or a string containing an error
|
||||
*/
|
||||
public static function FACTDOUBLE($factVal)
|
||||
{
|
||||
|
|
@ -452,7 +452,7 @@ class MathTrig
|
|||
* @param int $a Dividend
|
||||
* @param int $b Divisor
|
||||
*
|
||||
* @return int|string Remainder, or a string containing an error
|
||||
* @return float|int|string Remainder, or a string containing an error
|
||||
*/
|
||||
public static function MOD($a = 1, $b = 1)
|
||||
{
|
||||
|
|
@ -510,7 +510,7 @@ class MathTrig
|
|||
*
|
||||
* @param float $number Number to round
|
||||
*
|
||||
* @return int|string Rounded Number, or a string containing an error
|
||||
* @return float|int|string Rounded Number, or a string containing an error
|
||||
*/
|
||||
public static function ODD($number)
|
||||
{
|
||||
|
|
@ -822,7 +822,7 @@ class MathTrig
|
|||
*
|
||||
* @param mixed $args Data values
|
||||
*
|
||||
* @return float|string
|
||||
* @return null|float|string
|
||||
*/
|
||||
public static function SUMIFS(...$args)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -47,11 +47,19 @@ class Arabic
|
|||
return $sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $value
|
||||
*/
|
||||
private static function mollifyScrutinizer($value): array
|
||||
{
|
||||
return is_array($value) ? $value : [];
|
||||
}
|
||||
|
||||
private static function strSplit(string $roman): array
|
||||
{
|
||||
$rslt = str_split($roman);
|
||||
|
||||
return is_array($rslt) ? $rslt : [];
|
||||
return self::mollifyScrutinizer($rslt);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class Base
|
|||
return Functions::NAN(); // Numeric range constraints
|
||||
}
|
||||
|
||||
$outcome = strtoupper((string) base_convert($number, 10, $radix));
|
||||
$outcome = strtoupper((string) base_convert((string) $number, 10, $radix));
|
||||
if ($minLength !== null) {
|
||||
$outcome = str_pad($outcome, (int) $minLength, '0', STR_PAD_LEFT); // String padding
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Helpers
|
|||
return (int) $number;
|
||||
}
|
||||
if (is_numeric($number)) {
|
||||
return $number;
|
||||
return 0 + $number;
|
||||
}
|
||||
|
||||
throw new Exception(Functions::VALUE());
|
||||
|
|
@ -55,7 +55,7 @@ class Helpers
|
|||
return $substitute;
|
||||
}
|
||||
if (is_numeric($number)) {
|
||||
return $number;
|
||||
return 0 + $number;
|
||||
}
|
||||
|
||||
throw new Exception(Functions::VALUE());
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class Lcm
|
|||
//
|
||||
// Private method to return an array of the factors of the input value
|
||||
//
|
||||
private static function factors($value)
|
||||
private static function factors(float $value): array
|
||||
{
|
||||
$startVal = floor(sqrt($value));
|
||||
|
||||
|
|
|
|||
|
|
@ -776,19 +776,14 @@ class Roman
|
|||
const MAX_ROMAN_VALUE = 3999;
|
||||
const MAX_ROMAN_STYLE = 4;
|
||||
|
||||
private static function romanCut($num, $n)
|
||||
{
|
||||
return ($num - ($num % $n)) / $n;
|
||||
}
|
||||
|
||||
private static function valueOk(int $aValue, int $style): string
|
||||
{
|
||||
$origValue = $aValue;
|
||||
$m = self::romanCut($aValue, 1000);
|
||||
$m = \intdiv($aValue, 1000);
|
||||
$aValue %= 1000;
|
||||
$c = self::romanCut($aValue, 100);
|
||||
$c = \intdiv($aValue, 100);
|
||||
$aValue %= 100;
|
||||
$t = self::romanCut($aValue, 10);
|
||||
$t = \intdiv($aValue, 10);
|
||||
$aValue %= 10;
|
||||
$result = self::THOUSANDS[$m] . self::HUNDREDS[$c] . self::TENS[$t] . self::ONES[$aValue];
|
||||
if ($style > 0) {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class RoundDown
|
|||
{
|
||||
try {
|
||||
$number = Helpers::validateNumericNullBool($number);
|
||||
$digits = Helpers::validateNumericNullSubstitution($digits, null);
|
||||
$digits = (int) Helpers::validateNumericNullSubstitution($digits, null);
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class RoundUp
|
|||
{
|
||||
try {
|
||||
$number = Helpers::validateNumericNullBool($number);
|
||||
$digits = Helpers::validateNumericNullSubstitution($digits, null);
|
||||
$digits = (int) Helpers::validateNumericNullSubstitution($digits, null);
|
||||
} catch (Exception $e) {
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,11 @@ use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
|
|||
|
||||
class Subtotal
|
||||
{
|
||||
protected static function filterHiddenArgs($cellReference, $args)
|
||||
/**
|
||||
* @param mixed $cellReference
|
||||
* @param mixed $args
|
||||
*/
|
||||
protected static function filterHiddenArgs($cellReference, $args): array
|
||||
{
|
||||
return array_filter(
|
||||
$args,
|
||||
|
|
@ -21,7 +25,11 @@ class Subtotal
|
|||
);
|
||||
}
|
||||
|
||||
protected static function filterFormulaArgs($cellReference, $args)
|
||||
/**
|
||||
* @param mixed $cellReference
|
||||
* @param mixed $args
|
||||
*/
|
||||
protected static function filterFormulaArgs($cellReference, $args): array
|
||||
{
|
||||
return array_filter(
|
||||
$args,
|
||||
|
|
@ -42,6 +50,7 @@ class Subtotal
|
|||
);
|
||||
}
|
||||
|
||||
/** @var callable[] */
|
||||
private const CALL_FUNCTIONS = [
|
||||
1 => [Statistical\Averages::class, 'AVERAGE'],
|
||||
[Statistical\Counts::class, 'COUNT'], // 2
|
||||
|
|
@ -67,7 +76,7 @@ class Subtotal
|
|||
* list
|
||||
* Numbers 101 to 111 shadow the functions of 1 to 11
|
||||
* but ignore any values in the range that are
|
||||
* in hidden rows or columns
|
||||
* in hidden rows
|
||||
* @param mixed[] $args A mixed data series of values
|
||||
*
|
||||
* @return float|string
|
||||
|
|
@ -91,7 +100,10 @@ class Subtotal
|
|||
|
||||
$aArgs = self::filterFormulaArgs($cellReference, $aArgs);
|
||||
if (array_key_exists($subtotal, self::CALL_FUNCTIONS)) {
|
||||
return call_user_func_array(self::CALL_FUNCTIONS[$subtotal], $aArgs);
|
||||
/** @var callable */
|
||||
$call = self::CALL_FUNCTIONS[$subtotal];
|
||||
|
||||
return call_user_func_array($call, $aArgs);
|
||||
}
|
||||
|
||||
return Functions::VALUE();
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class Trunc
|
|||
// Truncate
|
||||
$adjust = 10 ** $digits;
|
||||
|
||||
if (($digits > 0) && (rtrim((int) ((abs($value) - abs((int) $value)) * $adjust), '0') < $adjust / 10)) {
|
||||
if (($digits > 0) && (rtrim((string) (int) ((abs($value) - abs((int) $value)) * $adjust), '0') < $adjust / 10)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,12 @@ class SubTotalTest extends AllSetupTeardown
|
|||
'L' => false,
|
||||
];
|
||||
foreach ($hiddenColumns as $col => $hidden) {
|
||||
$sheet->getColumnDimension($col)->setVisible($hidden);
|
||||
$colDim = $sheet->getColumnDimension($col);
|
||||
if ($colDim === null) {
|
||||
self::fail('Unexpected null column dimension');
|
||||
} else {
|
||||
$colDim->setVisible($hidden);
|
||||
}
|
||||
}
|
||||
$sheet->getCell('D2')->setValue("=SUBTOTAL($type, A1:$maxCol$maxRow)");
|
||||
$result = $sheet->getCell('D2')->getCalculatedValue();
|
||||
|
|
@ -91,7 +96,12 @@ class SubTotalTest extends AllSetupTeardown
|
|||
'12' => false,
|
||||
];
|
||||
foreach ($visibleRows as $row => $visible) {
|
||||
$sheet->getRowDimension($row)->setVisible($visible);
|
||||
$rowDim = $sheet->getRowDimension($row);
|
||||
if ($rowDim === null) {
|
||||
self::fail('Unexpected null row dimension');
|
||||
} else {
|
||||
$rowDim->setVisible($visible);
|
||||
}
|
||||
}
|
||||
$sheet->getCell('D2')->setValue("=SUBTOTAL($type, A1:$maxCol$maxRow)");
|
||||
$result = $sheet->getCell('D2')->getCalculatedValue();
|
||||
|
|
|
|||
Loading…
Reference in New Issue