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:
parent
ddd07ee504
commit
edca1f573d
|
|
@ -490,36 +490,6 @@ parameters:
|
||||||
count: 1
|
count: 1
|
||||||
path: src/PhpSpreadsheet/Calculation/Engineering.php
|
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\\.$#"
|
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\BesselJ\\:\\:besselj2a\\(\\) has no return typehint specified\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
|
@ -530,71 +500,11 @@ parameters:
|
||||||
count: 1
|
count: 1
|
||||||
path: src/PhpSpreadsheet/Calculation/Engineering/BesselJ.php
|
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\\.$#"
|
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\BesselK\\:\\:besselK2\\(\\) has no return typehint specified\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
path: src/PhpSpreadsheet/Calculation/Engineering/BesselK.php
|
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\\.$#"
|
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Engineering\\\\BitWise\\:\\:validateBitwiseArgument\\(\\) never returns int so it can be removed from the return typehint\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
|
||||||
class BesselI
|
class BesselI
|
||||||
{
|
{
|
||||||
use BaseValidations;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BESSELI.
|
* BESSELI.
|
||||||
*
|
*
|
||||||
|
|
@ -32,12 +30,12 @@ class BesselI
|
||||||
*/
|
*/
|
||||||
public static function BESSELI($x, $ord)
|
public static function BESSELI($x, $ord)
|
||||||
{
|
{
|
||||||
$x = ($x === null) ? 0.0 : Functions::flattenSingleValue($x);
|
$x = Functions::flattenSingleValue($x);
|
||||||
$ord = ($ord === null) ? 0 : Functions::flattenSingleValue($ord);
|
$ord = Functions::flattenSingleValue($ord);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$x = self::validateFloat($x);
|
$x = EngineeringValidations::validateFloat($x);
|
||||||
$ord = self::validateInt($ord);
|
$ord = EngineeringValidations::validateInt($ord);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
|
||||||
class BesselJ
|
class BesselJ
|
||||||
{
|
{
|
||||||
use BaseValidations;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BESSELJ.
|
* BESSELJ.
|
||||||
*
|
*
|
||||||
|
|
@ -31,12 +29,12 @@ class BesselJ
|
||||||
*/
|
*/
|
||||||
public static function BESSELJ($x, $ord)
|
public static function BESSELJ($x, $ord)
|
||||||
{
|
{
|
||||||
$x = ($x === null) ? 0.0 : Functions::flattenSingleValue($x);
|
$x = Functions::flattenSingleValue($x);
|
||||||
$ord = ($ord === null) ? 0.0 : Functions::flattenSingleValue($ord);
|
$ord = Functions::flattenSingleValue($ord);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$x = self::validateFloat($x);
|
$x = EngineeringValidations::validateFloat($x);
|
||||||
$ord = self::validateInt($ord);
|
$ord = EngineeringValidations::validateInt($ord);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
|
||||||
class BesselK
|
class BesselK
|
||||||
{
|
{
|
||||||
use BaseValidations;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BESSELK.
|
* BESSELK.
|
||||||
*
|
*
|
||||||
|
|
@ -29,12 +27,12 @@ class BesselK
|
||||||
*/
|
*/
|
||||||
public static function BESSELK($x, $ord)
|
public static function BESSELK($x, $ord)
|
||||||
{
|
{
|
||||||
$x = ($x === null) ? 0.0 : Functions::flattenSingleValue($x);
|
$x = Functions::flattenSingleValue($x);
|
||||||
$ord = ($ord === null) ? 0 : Functions::flattenSingleValue($ord);
|
$ord = Functions::flattenSingleValue($ord);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$x = self::validateFloat($x);
|
$x = EngineeringValidations::validateFloat($x);
|
||||||
$ord = self::validateInt($ord);
|
$ord = EngineeringValidations::validateInt($ord);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
|
||||||
class BesselY
|
class BesselY
|
||||||
{
|
{
|
||||||
use BaseValidations;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BESSELY.
|
* BESSELY.
|
||||||
*
|
*
|
||||||
|
|
@ -28,12 +26,12 @@ class BesselY
|
||||||
*/
|
*/
|
||||||
public static function BESSELY($x, $ord)
|
public static function BESSELY($x, $ord)
|
||||||
{
|
{
|
||||||
$x = ($x === null) ? 0.0 : Functions::flattenSingleValue($x);
|
$x = Functions::flattenSingleValue($x);
|
||||||
$ord = ($ord === null) ? 0 : Functions::flattenSingleValue($ord);
|
$ord = Functions::flattenSingleValue($ord);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$x = self::validateFloat($x);
|
$x = EngineeringValidations::validateFloat($x);
|
||||||
$ord = self::validateInt($ord);
|
$ord = EngineeringValidations::validateInt($ord);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
|
||||||
class Compare
|
class Compare
|
||||||
{
|
{
|
||||||
use BaseValidations;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DELTA.
|
* DELTA.
|
||||||
*
|
*
|
||||||
|
|
@ -31,8 +29,8 @@ class Compare
|
||||||
$b = Functions::flattenSingleValue($b);
|
$b = Functions::flattenSingleValue($b);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$a = self::validateFloat($a);
|
$a = EngineeringValidations::validateFloat($a);
|
||||||
$b = self::validateFloat($b);
|
$b = EngineeringValidations::validateFloat($b);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
@ -61,8 +59,8 @@ class Compare
|
||||||
$step = Functions::flattenSingleValue($step);
|
$step = Functions::flattenSingleValue($step);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$number = self::validateFloat($number);
|
$number = EngineeringValidations::validateFloat($number);
|
||||||
$step = self::validateFloat($step);
|
$step = EngineeringValidations::validateFloat($step);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||||
|
|
||||||
class Complex
|
class Complex
|
||||||
{
|
{
|
||||||
use BaseValidations;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* COMPLEX.
|
* COMPLEX.
|
||||||
*
|
*
|
||||||
|
|
@ -33,8 +31,8 @@ class Complex
|
||||||
$suffix = ($suffix === null) ? 'i' : Functions::flattenSingleValue($suffix);
|
$suffix = ($suffix === null) ? 'i' : Functions::flattenSingleValue($suffix);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$realNumber = self::validateFloat($realNumber);
|
$realNumber = EngineeringValidations::validateFloat($realNumber);
|
||||||
$imaginary = self::validateFloat($imaginary);
|
$imaginary = EngineeringValidations::validateFloat($imaginary);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return $e->getMessage();
|
return $e->getMessage();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,12 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\Engineering;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
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)) {
|
if (!is_numeric($value)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(Functions::VALUE());
|
||||||
|
|
@ -16,12 +19,15 @@ trait BaseValidations
|
||||||
return (float) $value;
|
return (float) $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function validateInt($value): int
|
/**
|
||||||
|
* @param mixed $value
|
||||||
|
*/
|
||||||
|
public static function validateInt($value): int
|
||||||
{
|
{
|
||||||
if (!is_numeric($value)) {
|
if (!is_numeric($value)) {
|
||||||
throw new Exception(Functions::VALUE());
|
throw new Exception(Functions::VALUE());
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int) floor($value);
|
return (int) floor((float) $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue