Use validation classes rather than traits for Engineering functions (#2001)

* Use validation classes rather than traits for Engineering functions

* Re-baseline phpstan
This commit is contained in:
Mark Baker 2021-04-13 17:24:45 +02:00 committed by GitHub
parent ddd07ee504
commit edca1f573d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 32 additions and 128 deletions

View File

@ -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

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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);
}
}