diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 4e5b7385..1c6070ab 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -490,36 +490,6 @@ parameters: count: 1 path: src/PhpSpreadsheet/Calculation/Engineering.php - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\BesselI\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering/BesselI.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\BesselI\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering/BesselI.php - - - - message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering/BesselI.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\BesselJ\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering/BesselJ.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\BesselJ\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering/BesselJ.php - - - - message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering/BesselJ.php - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\BesselJ\\:\\:besselj2a\\(\\) has no return typehint specified\\.$#" count: 1 @@ -530,71 +500,11 @@ parameters: count: 1 path: src/PhpSpreadsheet/Calculation/Engineering/BesselJ.php - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\BesselK\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering/BesselK.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\BesselK\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering/BesselK.php - - - - message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering/BesselK.php - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\BesselK\\:\\:besselK2\\(\\) has no return typehint specified\\.$#" count: 1 path: src/PhpSpreadsheet/Calculation/Engineering/BesselK.php - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\BesselY\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering/BesselY.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\BesselY\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering/BesselY.php - - - - message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering/BesselY.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\Compare\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering/Compare.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\Compare\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering/Compare.php - - - - message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering/Compare.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\Complex\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering/Complex.php - - - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\Complex\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering/Complex.php - - - - message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#" - count: 1 - path: src/PhpSpreadsheet/Calculation/Engineering/Complex.php - - message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\BitWise\\:\\:validateBitwiseArgument\\(\\) never returns int so it can be removed from the return typehint\\.$#" count: 1 diff --git a/src/PhpSpreadsheet/Calculation/Engineering/BesselI.php b/src/PhpSpreadsheet/Calculation/Engineering/BesselI.php index bbb24bd4..ea2577cd 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/BesselI.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/BesselI.php @@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions; class BesselI { - use BaseValidations; - /** * BESSELI. * @@ -32,12 +30,12 @@ class BesselI */ public static function BESSELI($x, $ord) { - $x = ($x === null) ? 0.0 : Functions::flattenSingleValue($x); - $ord = ($ord === null) ? 0 : Functions::flattenSingleValue($ord); + $x = Functions::flattenSingleValue($x); + $ord = Functions::flattenSingleValue($ord); try { - $x = self::validateFloat($x); - $ord = self::validateInt($ord); + $x = EngineeringValidations::validateFloat($x); + $ord = EngineeringValidations::validateInt($ord); } catch (Exception $e) { return $e->getMessage(); } diff --git a/src/PhpSpreadsheet/Calculation/Engineering/BesselJ.php b/src/PhpSpreadsheet/Calculation/Engineering/BesselJ.php index 730e2870..7ea45a74 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/BesselJ.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/BesselJ.php @@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions; class BesselJ { - use BaseValidations; - /** * BESSELJ. * @@ -31,12 +29,12 @@ class BesselJ */ public static function BESSELJ($x, $ord) { - $x = ($x === null) ? 0.0 : Functions::flattenSingleValue($x); - $ord = ($ord === null) ? 0.0 : Functions::flattenSingleValue($ord); + $x = Functions::flattenSingleValue($x); + $ord = Functions::flattenSingleValue($ord); try { - $x = self::validateFloat($x); - $ord = self::validateInt($ord); + $x = EngineeringValidations::validateFloat($x); + $ord = EngineeringValidations::validateInt($ord); } catch (Exception $e) { return $e->getMessage(); } diff --git a/src/PhpSpreadsheet/Calculation/Engineering/BesselK.php b/src/PhpSpreadsheet/Calculation/Engineering/BesselK.php index 18a2ac5c..8facdffc 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/BesselK.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/BesselK.php @@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions; class BesselK { - use BaseValidations; - /** * BESSELK. * @@ -29,12 +27,12 @@ class BesselK */ public static function BESSELK($x, $ord) { - $x = ($x === null) ? 0.0 : Functions::flattenSingleValue($x); - $ord = ($ord === null) ? 0 : Functions::flattenSingleValue($ord); + $x = Functions::flattenSingleValue($x); + $ord = Functions::flattenSingleValue($ord); try { - $x = self::validateFloat($x); - $ord = self::validateInt($ord); + $x = EngineeringValidations::validateFloat($x); + $ord = EngineeringValidations::validateInt($ord); } catch (Exception $e) { return $e->getMessage(); } diff --git a/src/PhpSpreadsheet/Calculation/Engineering/BesselY.php b/src/PhpSpreadsheet/Calculation/Engineering/BesselY.php index 19932c64..7f387497 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/BesselY.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/BesselY.php @@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions; class BesselY { - use BaseValidations; - /** * BESSELY. * @@ -28,12 +26,12 @@ class BesselY */ public static function BESSELY($x, $ord) { - $x = ($x === null) ? 0.0 : Functions::flattenSingleValue($x); - $ord = ($ord === null) ? 0 : Functions::flattenSingleValue($ord); + $x = Functions::flattenSingleValue($x); + $ord = Functions::flattenSingleValue($ord); try { - $x = self::validateFloat($x); - $ord = self::validateInt($ord); + $x = EngineeringValidations::validateFloat($x); + $ord = EngineeringValidations::validateInt($ord); } catch (Exception $e) { return $e->getMessage(); } diff --git a/src/PhpSpreadsheet/Calculation/Engineering/Compare.php b/src/PhpSpreadsheet/Calculation/Engineering/Compare.php index c764d8ea..0a634206 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/Compare.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/Compare.php @@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions; class Compare { - use BaseValidations; - /** * DELTA. * @@ -31,8 +29,8 @@ class Compare $b = Functions::flattenSingleValue($b); try { - $a = self::validateFloat($a); - $b = self::validateFloat($b); + $a = EngineeringValidations::validateFloat($a); + $b = EngineeringValidations::validateFloat($b); } catch (Exception $e) { return $e->getMessage(); } @@ -61,8 +59,8 @@ class Compare $step = Functions::flattenSingleValue($step); try { - $number = self::validateFloat($number); - $step = self::validateFloat($step); + $number = EngineeringValidations::validateFloat($number); + $step = EngineeringValidations::validateFloat($step); } catch (Exception $e) { return $e->getMessage(); } diff --git a/src/PhpSpreadsheet/Calculation/Engineering/Complex.php b/src/PhpSpreadsheet/Calculation/Engineering/Complex.php index f2718e4a..1c2f5f77 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/Complex.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/Complex.php @@ -9,8 +9,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions; class Complex { - use BaseValidations; - /** * COMPLEX. * @@ -33,8 +31,8 @@ class Complex $suffix = ($suffix === null) ? 'i' : Functions::flattenSingleValue($suffix); try { - $realNumber = self::validateFloat($realNumber); - $imaginary = self::validateFloat($imaginary); + $realNumber = EngineeringValidations::validateFloat($realNumber); + $imaginary = EngineeringValidations::validateFloat($imaginary); } catch (Exception $e) { return $e->getMessage(); } diff --git a/src/PhpSpreadsheet/Calculation/Engineering/BaseValidations.php b/src/PhpSpreadsheet/Calculation/Engineering/EngineeringValidations.php similarity index 61% rename from src/PhpSpreadsheet/Calculation/Engineering/BaseValidations.php rename to src/PhpSpreadsheet/Calculation/Engineering/EngineeringValidations.php index 48317635..01630af3 100644 --- a/src/PhpSpreadsheet/Calculation/Engineering/BaseValidations.php +++ b/src/PhpSpreadsheet/Calculation/Engineering/EngineeringValidations.php @@ -5,9 +5,12 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering; use PhpOffice\PhpSpreadsheet\Calculation\Exception; use PhpOffice\PhpSpreadsheet\Calculation\Functions; -trait BaseValidations +class EngineeringValidations { - protected static function validateFloat($value): float + /** + * @param mixed $value + */ + public static function validateFloat($value): float { if (!is_numeric($value)) { throw new Exception(Functions::VALUE()); @@ -16,12 +19,15 @@ trait BaseValidations return (float) $value; } - protected static function validateInt($value): int + /** + * @param mixed $value + */ + public static function validateInt($value): int { if (!is_numeric($value)) { throw new Exception(Functions::VALUE()); } - return (int) floor($value); + return (int) floor((float) $value); } }