Use validation classes rather than traits for Statistical functions, … (#1999)

* Use validation classes rather than traits for Statistical functions, and some verification of nullable arguments
* Eliminate more of the issues resolved in phpstan baseline
This commit is contained in:
Mark Baker 2021-04-13 16:56:21 +02:00 committed by GitHub
parent 33ec70668b
commit ddd07ee504
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 207 additions and 703 deletions

View File

@ -1500,36 +1500,6 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Averages.php path: src/PhpSpreadsheet/Calculation/Statistical/Averages.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Confidence\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Confidence.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Confidence\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Confidence.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Confidence.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Percentiles\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Percentiles.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Percentiles\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Percentiles.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Percentiles.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Percentiles\\:\\:percentileFilterValues\\(\\) has no return typehint specified\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Percentiles\\:\\:percentileFilterValues\\(\\) has no return typehint specified\\.$#"
count: 1 count: 1
@ -1540,36 +1510,6 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Percentiles.php path: src/PhpSpreadsheet/Calculation/Statistical/Percentiles.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Permutations\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Permutations.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Permutations\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Permutations.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Permutations.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Trends\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Trends.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Trends\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Trends.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Trends.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Trends\\:\\:checkTrendArrays\\(\\) has parameter \\$array1 with no typehint specified\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Trends\\:\\:checkTrendArrays\\(\\) has parameter \\$array1 with no typehint specified\\.$#"
count: 1 count: 1
@ -1625,41 +1565,6 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Conditional.php path: src/PhpSpreadsheet/Calculation/Statistical/Conditional.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Beta\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Beta.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Beta\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Beta.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Beta.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Beta\\:\\:validateBool\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Beta.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Beta\\:\\:validateProbability\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Beta.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Beta\\:\\:validateProbability\\(\\) has parameter \\$probability with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Beta.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Beta\\:\\:calculateInverse\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Beta.php
- -
message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Beta\\:\\:\\$logBetaCacheP has no typehint specified\\.$#" message: "#^Property PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Beta\\:\\:\\$logBetaCacheP has no typehint specified\\.$#"
count: 1 count: 1
@ -1675,106 +1580,11 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Beta.php path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Beta.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Binomial\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Binomial.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Binomial\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Binomial.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Binomial.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Binomial\\:\\:validateBool\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Binomial.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Binomial\\:\\:validateProbability\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Binomial.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Binomial\\:\\:validateProbability\\(\\) has parameter \\$probability with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Binomial.php
-
message: "#^Binary operation \"\\*\" between int\\|string and \\(float\\|int\\) results in an error\\.$#"
count: 3
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Binomial.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\ChiSquared\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\ChiSquared\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\ChiSquared\\:\\:validateBool\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\ChiSquared\\:\\:validateProbability\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\ChiSquared\\:\\:validateProbability\\(\\) has parameter \\$probability with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php
- -
message: "#^Binary operation \"\\-\" between 1 and float\\|string results in an error\\.$#" message: "#^Binary operation \"\\-\" between 1 and float\\|string results in an error\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\ChiSquared\\:\\:test\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\ChiSquared\\:\\:test\\(\\) has parameter \\$actual with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\ChiSquared\\:\\:test\\(\\) has parameter \\$expected with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\ChiSquared\\:\\:inverseLeftTailCalculation\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\ChiSquared\\:\\:inverseLeftTailCalculation\\(\\) has parameter \\$degrees with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\ChiSquared\\:\\:inverseLeftTailCalculation\\(\\) has parameter \\$probability with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\ChiSquared\\:\\:pchisq\\(\\) has no return typehint specified\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\ChiSquared\\:\\:pchisq\\(\\) has no return typehint specified\\.$#"
count: 1 count: 1
@ -1835,221 +1645,11 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Exponential\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Exponential.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Exponential\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Exponential.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Exponential.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Exponential\\:\\:validateBool\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Exponential.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Exponential\\:\\:validateProbability\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Exponential.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Exponential\\:\\:validateProbability\\(\\) has parameter \\$probability with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Exponential.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\F\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/F.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\F\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/F.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/F.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\F\\:\\:validateBool\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/F.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\F\\:\\:validateProbability\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/F.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\F\\:\\:validateProbability\\(\\) has parameter \\$probability with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/F.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Fisher\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Fisher.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Fisher\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Fisher.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Fisher.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Fisher\\:\\:validateBool\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Fisher.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Fisher\\:\\:validateProbability\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Fisher.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Fisher\\:\\:validateProbability\\(\\) has parameter \\$probability with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Fisher.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Gamma\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Gamma.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Gamma\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Gamma.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Gamma.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Gamma\\:\\:validateBool\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Gamma.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Gamma\\:\\:validateProbability\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Gamma.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Gamma\\:\\:validateProbability\\(\\) has parameter \\$probability with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Gamma.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\HyperGeometric\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/HyperGeometric.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\HyperGeometric\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/HyperGeometric.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/HyperGeometric.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\HyperGeometric\\:\\:validateBool\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/HyperGeometric.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\HyperGeometric\\:\\:validateProbability\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/HyperGeometric.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\HyperGeometric\\:\\:validateProbability\\(\\) has parameter \\$probability with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/HyperGeometric.php
- -
message: "#^Binary operation \"\\*\" between int\\|string and int\\|string results in an error\\.$#" message: "#^Binary operation \"\\*\" between int\\|string and int\\|string results in an error\\.$#"
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/HyperGeometric.php path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/HyperGeometric.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\LogNormal\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/LogNormal.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\LogNormal\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/LogNormal.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/LogNormal.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\LogNormal\\:\\:validateBool\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/LogNormal.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\LogNormal\\:\\:validateProbability\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/LogNormal.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\LogNormal\\:\\:validateProbability\\(\\) has parameter \\$probability with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/LogNormal.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Normal\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Normal.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Normal\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Normal.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Normal.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Normal\\:\\:validateBool\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Normal.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Normal\\:\\:validateProbability\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Normal.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Normal\\:\\:validateProbability\\(\\) has parameter \\$probability with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Normal.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Normal\\:\\:inverseNcdf\\(\\) has no return typehint specified\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Normal\\:\\:inverseNcdf\\(\\) has no return typehint specified\\.$#"
count: 1 count: 1
@ -2060,96 +1660,6 @@ parameters:
count: 1 count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Normal.php path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Normal.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Poisson\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Poisson.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Poisson\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Poisson.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Poisson.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Poisson\\:\\:validateBool\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Poisson.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Poisson\\:\\:validateProbability\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Poisson.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Poisson\\:\\:validateProbability\\(\\) has parameter \\$probability with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Poisson.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\StudentT\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/StudentT.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\StudentT\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/StudentT.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/StudentT.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\StudentT\\:\\:validateBool\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/StudentT.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\StudentT\\:\\:validateProbability\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/StudentT.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\StudentT\\:\\:validateProbability\\(\\) has parameter \\$probability with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/StudentT.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Weibull\\:\\:validateFloat\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Weibull.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Weibull\\:\\:validateInt\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Weibull.php
-
message: "#^Parameter \\#1 \\$number of function floor expects float, float\\|int\\|string given\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Weibull.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Weibull\\:\\:validateBool\\(\\) has parameter \\$value with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Weibull.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Weibull\\:\\:validateProbability\\(\\) has no return typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Weibull.php
-
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\Weibull\\:\\:validateProbability\\(\\) has parameter \\$probability with no typehint specified\\.$#"
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Weibull.php
- -
message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\GammaBase\\:\\:calculateDistribution\\(\\) has no return typehint specified\\.$#" message: "#^Method PhpOffice\\\\PhpSpreadsheet\\\\Calculation\\\\Statistical\\\\Distributions\\\\GammaBase\\:\\:calculateDistribution\\(\\) has no return typehint specified\\.$#"
count: 1 count: 1

View File

@ -1,27 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
trait BaseValidations
{
protected static function validateFloat($value): float
{
if (!is_numeric($value)) {
throw new Exception(Functions::VALUE());
}
return (float) $value;
}
protected static function validateInt($value): int
{
if (!is_numeric($value)) {
throw new Exception(Functions::VALUE());
}
return (int) floor($value);
}
}

View File

@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Confidence class Confidence
{ {
use BaseValidations;
/** /**
* CONFIDENCE. * CONFIDENCE.
* *
@ -27,9 +25,9 @@ class Confidence
$size = Functions::flattenSingleValue($size); $size = Functions::flattenSingleValue($size);
try { try {
$alpha = self::validateFloat($alpha); $alpha = StatisticalValidations::validateFloat($alpha);
$stdDev = self::validateFloat($stdDev); $stdDev = StatisticalValidations::validateFloat($stdDev);
$size = self::validateInt($size); $size = StatisticalValidations::validateInt($size);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -1,47 +0,0 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
trait BaseValidations
{
protected static function validateFloat($value): float
{
if (!is_numeric($value)) {
throw new Exception(Functions::VALUE());
}
return (float) $value;
}
protected static function validateInt($value): int
{
if (!is_numeric($value)) {
throw new Exception(Functions::VALUE());
}
return (int) floor($value);
}
protected static function validateBool($value): bool
{
if (!is_bool($value) && !is_numeric($value)) {
throw new Exception(Functions::VALUE());
}
return (bool) $value;
}
protected static function validateProbability($probability)
{
$probability = self::validateFloat($probability);
if ($probability < 0.0 || $probability > 1.0) {
throw new Exception(Functions::NAN());
}
return $probability;
}
}

View File

@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Beta class Beta
{ {
use BaseValidations;
private const MAX_ITERATIONS = 256; private const MAX_ITERATIONS = 256;
private const LOG_GAMMA_X_MAX_VALUE = 2.55e305; private const LOG_GAMMA_X_MAX_VALUE = 2.55e305;
@ -28,20 +26,20 @@ class Beta
* *
* @return float|string * @return float|string
*/ */
public static function distribution($value, $alpha, $beta, $rMin = 0, $rMax = 1) public static function distribution($value, $alpha, $beta, $rMin = 0.0, $rMax = 1.0)
{ {
$value = Functions::flattenSingleValue($value); $value = Functions::flattenSingleValue($value);
$alpha = Functions::flattenSingleValue($alpha); $alpha = Functions::flattenSingleValue($alpha);
$beta = Functions::flattenSingleValue($beta); $beta = Functions::flattenSingleValue($beta);
$rMin = Functions::flattenSingleValue($rMin); $rMin = ($rMin === null) ? 0.0 : Functions::flattenSingleValue($rMin);
$rMax = Functions::flattenSingleValue($rMax); $rMax = ($rMax === null) ? 1.0 : Functions::flattenSingleValue($rMax);
try { try {
$value = self::validateFloat($value); $value = DistributionValidations::validateFloat($value);
$alpha = self::validateFloat($alpha); $alpha = DistributionValidations::validateFloat($alpha);
$beta = self::validateFloat($beta); $beta = DistributionValidations::validateFloat($beta);
$rMax = self::validateFloat($rMax); $rMax = DistributionValidations::validateFloat($rMax);
$rMin = self::validateFloat($rMin); $rMin = DistributionValidations::validateFloat($rMin);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -74,20 +72,20 @@ class Beta
* *
* @return float|string * @return float|string
*/ */
public static function inverse($probability, $alpha, $beta, $rMin = 0, $rMax = 1) public static function inverse($probability, $alpha, $beta, $rMin = 0.0, $rMax = 1.0)
{ {
$probability = Functions::flattenSingleValue($probability); $probability = Functions::flattenSingleValue($probability);
$alpha = Functions::flattenSingleValue($alpha); $alpha = Functions::flattenSingleValue($alpha);
$beta = Functions::flattenSingleValue($beta); $beta = Functions::flattenSingleValue($beta);
$rMin = Functions::flattenSingleValue($rMin); $rMin = ($rMin === null) ? 0.0 : Functions::flattenSingleValue($rMin);
$rMax = Functions::flattenSingleValue($rMax); $rMax = ($rMax === null) ? 1.0 : Functions::flattenSingleValue($rMax);
try { try {
$probability = self::validateProbability($probability); $probability = DistributionValidations::validateProbability($probability);
$alpha = self::validateFloat($alpha); $alpha = DistributionValidations::validateFloat($alpha);
$beta = self::validateFloat($beta); $beta = DistributionValidations::validateFloat($beta);
$rMax = self::validateFloat($rMax); $rMax = DistributionValidations::validateFloat($rMax);
$rMin = self::validateFloat($rMin); $rMin = DistributionValidations::validateFloat($rMin);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -104,6 +102,9 @@ class Beta
return self::calculateInverse($probability, $alpha, $beta, $rMin, $rMax); return self::calculateInverse($probability, $alpha, $beta, $rMin, $rMax);
} }
/**
* @return float|string
*/
private static function calculateInverse(float $probability, float $alpha, float $beta, float $rMin, float $rMax) private static function calculateInverse(float $probability, float $alpha, float $beta, float $rMin, float $rMax)
{ {
$a = 0; $a = 0;

View File

@ -8,8 +8,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
class Binomial class Binomial
{ {
use BaseValidations;
/** /**
* BINOMDIST. * BINOMDIST.
* *
@ -33,10 +31,10 @@ class Binomial
$probability = Functions::flattenSingleValue($probability); $probability = Functions::flattenSingleValue($probability);
try { try {
$value = self::validateInt($value); $value = DistributionValidations::validateInt($value);
$trials = self::validateInt($trials); $trials = DistributionValidations::validateInt($trials);
$probability = self::validateProbability($probability); $probability = DistributionValidations::validateProbability($probability);
$cumulative = self::validateBool($cumulative); $cumulative = DistributionValidations::validateBool($cumulative);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -74,10 +72,10 @@ class Binomial
$limit = ($limit === null) ? $successes : Functions::flattenSingleValue($limit); $limit = ($limit === null) ? $successes : Functions::flattenSingleValue($limit);
try { try {
$trials = self::validateInt($trials); $trials = DistributionValidations::validateInt($trials);
$probability = self::validateProbability($probability); $probability = DistributionValidations::validateProbability($probability);
$successes = self::validateInt($successes); $successes = DistributionValidations::validateInt($successes);
$limit = self::validateInt($limit); $limit = DistributionValidations::validateInt($limit);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -122,9 +120,9 @@ class Binomial
$probability = Functions::flattenSingleValue($probability); $probability = Functions::flattenSingleValue($probability);
try { try {
$failures = self::validateInt($failures); $failures = DistributionValidations::validateInt($failures);
$successes = self::validateInt($successes); $successes = DistributionValidations::validateInt($successes);
$probability = self::validateProbability($probability); $probability = DistributionValidations::validateProbability($probability);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -161,9 +159,9 @@ class Binomial
$alpha = Functions::flattenSingleValue($alpha); $alpha = Functions::flattenSingleValue($alpha);
try { try {
$trials = self::validateInt($trials); $trials = DistributionValidations::validateInt($trials);
$probability = self::validateProbability($probability); $probability = DistributionValidations::validateProbability($probability);
$alpha = self::validateFloat($alpha); $alpha = DistributionValidations::validateFloat($alpha);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class ChiSquared class ChiSquared
{ {
use BaseValidations;
private const MAX_ITERATIONS = 256; private const MAX_ITERATIONS = 256;
private const EPS = 2.22e-16; private const EPS = 2.22e-16;
@ -29,8 +27,8 @@ class ChiSquared
$degrees = Functions::flattenSingleValue($degrees); $degrees = Functions::flattenSingleValue($degrees);
try { try {
$value = self::validateFloat($value); $value = DistributionValidations::validateFloat($value);
$degrees = self::validateInt($degrees); $degrees = DistributionValidations::validateInt($degrees);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -67,9 +65,9 @@ class ChiSquared
$cumulative = Functions::flattenSingleValue($cumulative); $cumulative = Functions::flattenSingleValue($cumulative);
try { try {
$value = self::validateFloat($value); $value = DistributionValidations::validateFloat($value);
$degrees = self::validateInt($degrees); $degrees = DistributionValidations::validateInt($degrees);
$cumulative = self::validateBool($cumulative); $cumulative = DistributionValidations::validateBool($cumulative);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -109,8 +107,8 @@ class ChiSquared
$degrees = Functions::flattenSingleValue($degrees); $degrees = Functions::flattenSingleValue($degrees);
try { try {
$probability = self::validateProbability($probability); $probability = DistributionValidations::validateProbability($probability);
$degrees = self::validateInt($degrees); $degrees = DistributionValidations::validateInt($degrees);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -145,8 +143,8 @@ class ChiSquared
$degrees = Functions::flattenSingleValue($degrees); $degrees = Functions::flattenSingleValue($degrees);
try { try {
$probability = self::validateProbability($probability); $probability = DistributionValidations::validateProbability($probability);
$degrees = self::validateInt($degrees); $degrees = DistributionValidations::validateInt($degrees);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -158,6 +156,18 @@ class ChiSquared
return self::inverseLeftTailCalculation($probability, $degrees); return self::inverseLeftTailCalculation($probability, $degrees);
} }
/**
* CHITEST.
*
* Uses the chi-square test to calculate the probability that the differences between two supplied data sets
* (of observed and expected frequencies), are likely to be simply due to sampling error,
* or if they are likely to be real.
*
* @param mixed $actual an array of observed frequencies
* @param mixed $expected an array of expected frequencies
*
* @return float|string
*/
public static function test($actual, $expected) public static function test($actual, $expected)
{ {
$rows = count($actual); $rows = count($actual);
@ -199,7 +209,7 @@ class ChiSquared
return ($columns - 1) * ($rows - 1); return ($columns - 1) * ($rows - 1);
} }
private static function inverseLeftTailCalculation($probability, $degrees) private static function inverseLeftTailCalculation(float $probability, int $degrees): float
{ {
// bracket the root // bracket the root
$min = 0; $min = 0;

View File

@ -0,0 +1,24 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical\StatisticalValidations;
class DistributionValidations extends StatisticalValidations
{
/**
* @param mixed $probability
*/
public static function validateProbability($probability): float
{
$probability = self::validateFloat($probability);
if ($probability < 0.0 || $probability > 1.0) {
throw new Exception(Functions::NAN());
}
return $probability;
}
}

View File

@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Exponential class Exponential
{ {
use BaseValidations;
/** /**
* EXPONDIST. * EXPONDIST.
* *
@ -29,9 +27,9 @@ class Exponential
$cumulative = Functions::flattenSingleValue($cumulative); $cumulative = Functions::flattenSingleValue($cumulative);
try { try {
$value = self::validateFloat($value); $value = DistributionValidations::validateFloat($value);
$lambda = self::validateFloat($lambda); $lambda = DistributionValidations::validateFloat($lambda);
$cumulative = self::validateBool($cumulative); $cumulative = DistributionValidations::validateBool($cumulative);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class F class F
{ {
use BaseValidations;
/** /**
* F.DIST. * F.DIST.
* *
@ -32,10 +30,10 @@ class F
$cumulative = Functions::flattenSingleValue($cumulative); $cumulative = Functions::flattenSingleValue($cumulative);
try { try {
$value = self::validateFloat($value); $value = DistributionValidations::validateFloat($value);
$u = self::validateInt($u); $u = DistributionValidations::validateInt($u);
$v = self::validateInt($v); $v = DistributionValidations::validateInt($v);
$cumulative = self::validateBool($cumulative); $cumulative = DistributionValidations::validateBool($cumulative);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Fisher class Fisher
{ {
use BaseValidations;
/** /**
* FISHER. * FISHER.
* *
@ -25,7 +23,7 @@ class Fisher
$value = Functions::flattenSingleValue($value); $value = Functions::flattenSingleValue($value);
try { try {
self::validateFloat($value); DistributionValidations::validateFloat($value);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -53,7 +51,7 @@ class Fisher
$probability = Functions::flattenSingleValue($probability); $probability = Functions::flattenSingleValue($probability);
try { try {
self::validateFloat($probability); DistributionValidations::validateFloat($probability);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Gamma extends GammaBase class Gamma extends GammaBase
{ {
use BaseValidations;
/** /**
* GAMMA. * GAMMA.
* *
@ -23,7 +21,7 @@ class Gamma extends GammaBase
$value = Functions::flattenSingleValue($value); $value = Functions::flattenSingleValue($value);
try { try {
$value = self::validateFloat($value); $value = DistributionValidations::validateFloat($value);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -54,10 +52,10 @@ class Gamma extends GammaBase
$b = Functions::flattenSingleValue($b); $b = Functions::flattenSingleValue($b);
try { try {
$value = self::validateFloat($value); $value = DistributionValidations::validateFloat($value);
$a = self::validateFloat($a); $a = DistributionValidations::validateFloat($a);
$b = self::validateFloat($b); $b = DistributionValidations::validateFloat($b);
$cumulative = self::validateBool($cumulative); $cumulative = DistributionValidations::validateBool($cumulative);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -87,9 +85,9 @@ class Gamma extends GammaBase
$beta = Functions::flattenSingleValue($beta); $beta = Functions::flattenSingleValue($beta);
try { try {
$probability = self::validateProbability($probability); $probability = DistributionValidations::validateProbability($probability);
$alpha = self::validateFloat($alpha); $alpha = DistributionValidations::validateFloat($alpha);
$beta = self::validateFloat($beta); $beta = DistributionValidations::validateFloat($beta);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -115,7 +113,7 @@ class Gamma extends GammaBase
$value = Functions::flattenSingleValue($value); $value = Functions::flattenSingleValue($value);
try { try {
$value = self::validateFloat($value); $value = DistributionValidations::validateFloat($value);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -8,8 +8,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
class HyperGeometric class HyperGeometric
{ {
use BaseValidations;
/** /**
* HYPGEOMDIST. * HYPGEOMDIST.
* *
@ -31,10 +29,10 @@ class HyperGeometric
$populationNumber = Functions::flattenSingleValue($populationNumber); $populationNumber = Functions::flattenSingleValue($populationNumber);
try { try {
$sampleSuccesses = self::validateInt($sampleSuccesses); $sampleSuccesses = DistributionValidations::validateInt($sampleSuccesses);
$sampleNumber = self::validateInt($sampleNumber); $sampleNumber = DistributionValidations::validateInt($sampleNumber);
$populationSuccesses = self::validateInt($populationSuccesses); $populationSuccesses = DistributionValidations::validateInt($populationSuccesses);
$populationNumber = self::validateInt($populationNumber); $populationNumber = DistributionValidations::validateInt($populationNumber);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class LogNormal class LogNormal
{ {
use BaseValidations;
/** /**
* LOGNORMDIST. * LOGNORMDIST.
* *
@ -28,9 +26,9 @@ class LogNormal
$stdDev = Functions::flattenSingleValue($stdDev); $stdDev = Functions::flattenSingleValue($stdDev);
try { try {
$value = self::validateFloat($value); $value = DistributionValidations::validateFloat($value);
$mean = self::validateFloat($mean); $mean = DistributionValidations::validateFloat($mean);
$stdDev = self::validateFloat($stdDev); $stdDev = DistributionValidations::validateFloat($stdDev);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -63,10 +61,10 @@ class LogNormal
$cumulative = Functions::flattenSingleValue($cumulative); $cumulative = Functions::flattenSingleValue($cumulative);
try { try {
$value = self::validateFloat($value); $value = DistributionValidations::validateFloat($value);
$mean = self::validateFloat($mean); $mean = DistributionValidations::validateFloat($mean);
$stdDev = self::validateFloat($stdDev); $stdDev = DistributionValidations::validateFloat($stdDev);
$cumulative = self::validateBool($cumulative); $cumulative = DistributionValidations::validateBool($cumulative);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -105,9 +103,9 @@ class LogNormal
$stdDev = Functions::flattenSingleValue($stdDev); $stdDev = Functions::flattenSingleValue($stdDev);
try { try {
$probability = self::validateProbability($probability); $probability = DistributionValidations::validateProbability($probability);
$mean = self::validateFloat($mean); $mean = DistributionValidations::validateFloat($mean);
$stdDev = self::validateFloat($stdDev); $stdDev = DistributionValidations::validateFloat($stdDev);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -8,8 +8,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Normal class Normal
{ {
use BaseValidations;
public const SQRT2PI = 2.5066282746310005024157652848110452530069867406099; public const SQRT2PI = 2.5066282746310005024157652848110452530069867406099;
/** /**
@ -33,10 +31,10 @@ class Normal
$stdDev = Functions::flattenSingleValue($stdDev); $stdDev = Functions::flattenSingleValue($stdDev);
try { try {
$value = self::validateFloat($value); $value = DistributionValidations::validateFloat($value);
$mean = self::validateFloat($mean); $mean = DistributionValidations::validateFloat($mean);
$stdDev = self::validateFloat($stdDev); $stdDev = DistributionValidations::validateFloat($stdDev);
$cumulative = self::validateBool($cumulative); $cumulative = DistributionValidations::validateBool($cumulative);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -70,9 +68,9 @@ class Normal
$stdDev = Functions::flattenSingleValue($stdDev); $stdDev = Functions::flattenSingleValue($stdDev);
try { try {
$probability = self::validateProbability($probability); $probability = DistributionValidations::validateProbability($probability);
$mean = self::validateFloat($mean); $mean = DistributionValidations::validateFloat($mean);
$stdDev = self::validateFloat($stdDev); $stdDev = DistributionValidations::validateFloat($stdDev);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -8,8 +8,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
class Poisson class Poisson
{ {
use BaseValidations;
/** /**
* POISSON. * POISSON.
* *
@ -29,9 +27,9 @@ class Poisson
$mean = Functions::flattenSingleValue($mean); $mean = Functions::flattenSingleValue($mean);
try { try {
$value = self::validateFloat($value); $value = DistributionValidations::validateFloat($value);
$mean = self::validateFloat($mean); $mean = DistributionValidations::validateFloat($mean);
$cumulative = self::validateBool($cumulative); $cumulative = DistributionValidations::validateBool($cumulative);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class StudentT class StudentT
{ {
use BaseValidations;
private const MAX_ITERATIONS = 256; private const MAX_ITERATIONS = 256;
/** /**
@ -29,9 +27,9 @@ class StudentT
$tails = Functions::flattenSingleValue($tails); $tails = Functions::flattenSingleValue($tails);
try { try {
$value = self::validateFloat($value); $value = DistributionValidations::validateFloat($value);
$degrees = self::validateInt($degrees); $degrees = DistributionValidations::validateInt($degrees);
$tails = self::validateInt($tails); $tails = DistributionValidations::validateInt($tails);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -59,8 +57,8 @@ class StudentT
$degrees = Functions::flattenSingleValue($degrees); $degrees = Functions::flattenSingleValue($degrees);
try { try {
$probability = self::validateProbability($probability); $probability = DistributionValidations::validateProbability($probability);
$degrees = self::validateInt($degrees); $degrees = DistributionValidations::validateInt($degrees);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Weibull class Weibull
{ {
use BaseValidations;
/** /**
* WEIBULL. * WEIBULL.
* *
@ -30,10 +28,10 @@ class Weibull
$cumulative = Functions::flattenSingleValue($cumulative); $cumulative = Functions::flattenSingleValue($cumulative);
try { try {
$value = self::validateFloat($value); $value = DistributionValidations::validateFloat($value);
$alpha = self::validateFloat($alpha); $alpha = DistributionValidations::validateFloat($alpha);
$beta = self::validateFloat($beta); $beta = DistributionValidations::validateFloat($beta);
$cumulative = self::validateBool($cumulative); $cumulative = DistributionValidations::validateBool($cumulative);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -7,8 +7,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class Percentiles class Percentiles
{ {
use BaseValidations;
public const RANK_SORT_DESCENDING = 0; public const RANK_SORT_DESCENDING = 0;
public const RANK_SORT_ASCENDING = 1; public const RANK_SORT_ASCENDING = 1;
@ -33,7 +31,7 @@ class Percentiles
$entry = array_pop($aArgs); $entry = array_pop($aArgs);
try { try {
$entry = self::validateFloat($entry); $entry = StatisticalValidations::validateFloat($entry);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -82,8 +80,8 @@ class Percentiles
$significance = ($significance === null) ? 3 : Functions::flattenSingleValue($significance); $significance = ($significance === null) ? 3 : Functions::flattenSingleValue($significance);
try { try {
$value = self::validateFloat($value); $value = StatisticalValidations::validateFloat($value);
$significance = self::validateInt($significance); $significance = StatisticalValidations::validateInt($significance);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -132,7 +130,7 @@ class Percentiles
$entry = array_pop($aArgs); $entry = array_pop($aArgs);
try { try {
$entry = self::validateFloat($entry); $entry = StatisticalValidations::validateFloat($entry);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -164,8 +162,8 @@ class Percentiles
$order = ($order === null) ? self::RANK_SORT_DESCENDING : Functions::flattenSingleValue($order); $order = ($order === null) ? self::RANK_SORT_DESCENDING : Functions::flattenSingleValue($order);
try { try {
$value = self::validateFloat($value); $value = StatisticalValidations::validateFloat($value);
$order = self::validateInt($order); $order = StatisticalValidations::validateInt($order);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -8,8 +8,6 @@ use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
class Permutations class Permutations
{ {
use BaseValidations;
/** /**
* PERMUT. * PERMUT.
* *
@ -30,8 +28,8 @@ class Permutations
$numInSet = Functions::flattenSingleValue($numInSet); $numInSet = Functions::flattenSingleValue($numInSet);
try { try {
$numObjs = self::validateInt($numObjs); $numObjs = StatisticalValidations::validateInt($numObjs);
$numInSet = self::validateInt($numInSet); $numInSet = StatisticalValidations::validateInt($numInSet);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }
@ -60,8 +58,8 @@ class Permutations
$numInSet = Functions::flattenSingleValue($numInSet); $numInSet = Functions::flattenSingleValue($numInSet);
try { try {
$numObjs = self::validateInt($numObjs); $numObjs = StatisticalValidations::validateInt($numObjs);
$numInSet = self::validateInt($numInSet); $numInSet = StatisticalValidations::validateInt($numInSet);
} catch (Exception $e) { } catch (Exception $e) {
return $e->getMessage(); return $e->getMessage();
} }

View File

@ -0,0 +1,45 @@
<?php
namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class StatisticalValidations
{
/**
* @param mixed $value
*/
public static function validateFloat($value): float
{
if (!is_numeric($value)) {
throw new Exception(Functions::VALUE());
}
return (float) $value;
}
/**
* @param mixed $value
*/
public static function validateInt($value): int
{
if (!is_numeric($value)) {
throw new Exception(Functions::VALUE());
}
return (int) floor((float) $value);
}
/**
* @param mixed $value
*/
public static function validateBool($value): bool
{
if (!is_bool($value) && !is_numeric($value)) {
throw new Exception(Functions::VALUE());
}
return (bool) $value;
}
}

View File

@ -8,8 +8,6 @@ use PhpOffice\PhpSpreadsheet\Shared\Trend\Trend;
class Trends class Trends
{ {
use BaseValidations;
private static function filterTrendValues(array &$array1, array &$array2): void private static function filterTrendValues(array &$array1, array &$array2): void
{ {
foreach ($array1 as $key => $value) { foreach ($array1 as $key => $value) {
@ -120,7 +118,7 @@ class Trends
$xValue = Functions::flattenSingleValue($xValue); $xValue = Functions::flattenSingleValue($xValue);
try { try {
$xValue = self::validateFloat($xValue); $xValue = StatisticalValidations::validateFloat($xValue);
self::checkTrendArrays($yValues, $xValues); self::checkTrendArrays($yValues, $xValues);
self::validateTrendArrays($yValues, $xValues); self::validateTrendArrays($yValues, $xValues);
} catch (Exception $e) { } catch (Exception $e) {

View File

@ -29,6 +29,10 @@ return [
0.4059136, 0.4059136,
0.4, 4, 5, 0.4, 4, 5,
], ],
[
0.4059136,
0.4, 4, 5, null, null,
],
[ [
'#VALUE!', '#VALUE!',
'NAN', 8, 10, 1, 3, 'NAN', 8, 10, 1, 3,

View File

@ -25,6 +25,10 @@ return [
0.303225844664, 0.303225844664,
0.2, 4, 5, 0, 1, 0.2, 4, 5, 0, 1,
], ],
[
0.303225844664,
0.2, 4, 5, null, null,
],
[ [
'#VALUE!', '#VALUE!',
'NAN', 4, 5, 0, 1, 'NAN', 4, 5, 0, 1,

View File

@ -25,6 +25,10 @@ return [
0.079589237387, 0.079589237387,
100, 0.5, 50, 100, 0.5, 50,
], ],
[
0.079589237387,
100, 0.5, 50, null,
],
[ [
'#VALUE!', '#VALUE!',
'NaN', 0.5, 50, 100, 'NaN', 0.5, 50, 100,

View File

@ -37,6 +37,12 @@ return [
[24, 22, 19, 21, 18, 19, 20, 23], [24, 22, 19, 21, 18, 19, 20, 23],
22, 22,
], ],
[
0.952209647727,
[24, 22, 19, 21, 18, 19, 20, 23],
22,
null,
],
[ [
'#VALUE!', '#VALUE!',
[1, 2, 3, 3, 4, 4, 8, 10, 12], [1, 2, 3, 3, 4, 4, 8, 10, 12],