Merge pull request #4429 from oleibman/stan2lv909

Phpstan Level 9: Last
This commit is contained in:
oleibman
2025-04-04 01:52:29 +00:00
committed by GitHub
20 changed files with 80 additions and 317 deletions
Generated
+6 -6
View File
@@ -1798,16 +1798,16 @@
},
{
"name": "phpstan/phpstan",
"version": "2.1.6",
"version": "2.1.11",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "6eaec7c6c9e90dcfe46ad1e1ffa5171e2dab641c"
"reference": "8ca5f79a8f63c49b2359065832a654e1ec70ac30"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/6eaec7c6c9e90dcfe46ad1e1ffa5171e2dab641c",
"reference": "6eaec7c6c9e90dcfe46ad1e1ffa5171e2dab641c",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/8ca5f79a8f63c49b2359065832a654e1ec70ac30",
"reference": "8ca5f79a8f63c49b2359065832a654e1ec70ac30",
"shasum": ""
},
"require": {
@@ -1852,7 +1852,7 @@
"type": "github"
}
],
"time": "2025-02-19T15:46:42+00:00"
"time": "2025-03-24T13:45:00+00:00"
},
{
"name": "phpstan/phpstan-deprecation-rules",
@@ -5619,5 +5619,5 @@
"platform-overrides": {
"php": "8.1.99"
},
"plugin-api-version": "2.3.0"
"plugin-api-version": "2.6.0"
}
-269
View File
@@ -1,271 +1,2 @@
parameters:
ignoreErrors:
-
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\Hyperlink\:\:set\(\) should return string but returns mixed\.$#'
identifier: return.type
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/Hyperlink.php
-
message: '#^Parameter \#1 \$string of function trim expects string, mixed given\.$#'
identifier: argument.type
count: 2
path: src/PhpSpreadsheet/Calculation/LookupRef/Hyperlink.php
-
message: '#^Parameter \#1 \$tooltip of method PhpOffice\\PhpSpreadsheet\\Cell\\Hyperlink\:\:setTooltip\(\) expects string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/Hyperlink.php
-
message: '#^Parameter \#1 \$url of method PhpOffice\\PhpSpreadsheet\\Cell\\Hyperlink\:\:setUrl\(\) expects string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/Hyperlink.php
-
message: '#^Parameter \#1 \$lookupVector of static method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\Lookup\:\:verifyLookupValues\(\) expects array, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/Lookup.php
-
message: '#^Parameter \#1 \$resultVector of static method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\Lookup\:\:verifyResultVector\(\) expects array, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/Lookup.php
-
message: '#^Parameter \#2 \$resultVector of static method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\Lookup\:\:verifyLookupValues\(\) expects array, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/Lookup.php
-
message: '#^Parameter \#1 \$message of class PhpOffice\\PhpSpreadsheet\\Calculation\\Exception constructor expects string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/LookupRefValidations.php
-
message: '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\.$#'
identifier: foreach.nonIterable
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/Matrix.php
-
message: '#^Cannot access offset int\|string on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/Matrix.php
-
message: '#^Parameter \#1 \$array of function array_keys expects array, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/Matrix.php
-
message: '#^Binary operation "\+\=" between int and mixed results in an error\.$#'
identifier: assignOp.invalid
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/Offset.php
-
message: '#^Binary operation "\+\=" between mixed and int results in an error\.$#'
identifier: assignOp.invalid
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/Offset.php
-
message: '#^Binary operation "\-" between mixed and 1 results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/Offset.php
-
message: '#^Cannot cast mixed to int\.$#'
identifier: cast.int
count: 4
path: src/PhpSpreadsheet/Calculation/LookupRef/Offset.php
-
message: '#^Parameter \#1 \$sortIndex of static method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\Sort\:\:validateArrayArgumentsForSort\(\) expects array, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/Sort.php
-
message: '#^Parameter \#3 \$sortOrder of static method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\Sort\:\:sortByColumn\(\) expects array\<int\>, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/Sort.php
-
message: '#^Parameter \#3 \$sortOrder of static method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\Sort\:\:sortByRow\(\) expects array\<int\>, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/Sort.php
-
message: '#^Cannot access offset \(int\|string\) on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
-
message: '#^Cannot access offset int on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
-
message: '#^Cannot access offset int\|string\|null on mixed\.$#'
identifier: offsetAccess.nonOffsetAccessible
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
-
message: '#^Cannot cast mixed to string\.$#'
identifier: cast.string
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
-
message: '#^Parameter \#1 \$array of function array_keys expects array, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
-
message: '#^Parameter \#1 \$array of function uasort expects TArray of array\<TKey of int\|string, mixed\>, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
-
message: '#^Parameter \#1 \$lookup_array of static method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\LookupBase\:\:validateIndexLookup\(\) expects array, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
-
message: '#^Parameter \#2 \$index_number of static method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\LookupBase\:\:validateIndexLookup\(\) expects float\|int\|string, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
-
message: '#^Parameter \#2 \$lookupArray of static method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\VLookup\:\:vLookupSearch\(\) expects array, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/LookupRef/VLookup.php
-
message: '#^Cannot call method getWorksheet\(\) on mixed\.$#'
identifier: method.nonObject
count: 4
path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
-
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\MathTrig\\Subtotal\:\:evaluate\(\) should return float\|int\|string but returns mixed\.$#'
identifier: return.type
count: 1
path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
-
message: '#^Parameter \#1 \$array of function array_filter expects array, mixed given\.$#'
identifier: argument.type
count: 2
path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
-
message: '#^Parameter \#2 \$string of function explode expects string, mixed given\.$#'
identifier: argument.type
count: 2
path: src/PhpSpreadsheet/Calculation/MathTrig/Subtotal.php
-
message: '#^Binary operation "\+\=" between \(float\|int\) and mixed results in an error\.$#'
identifier: assignOp.invalid
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Averages.php
-
message: '#^Binary operation "\-" between mixed and float\|int\|string results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Averages.php
-
message: '#^Parameter \#2 \$condition of static method PhpOffice\\PhpSpreadsheet\\Calculation\\Statistical\\Conditional\:\:AVERAGEIF\(\) expects array\|string\|null, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Conditional.php
-
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\Statistical\\Confidence\:\:CONFIDENCE\(\) should return array\|float\|string but returns mixed\.$#'
identifier: return.type
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Confidence.php
-
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\Statistical\\Distributions\\ChiSquared\:\:test\(\) should return float\|string but returns mixed\.$#'
identifier: return.type
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php
-
message: '#^Parameter \#1 \$value of function count expects array\|Countable, mixed given\.$#'
identifier: argument.type
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/ChiSquared.php
-
message: '#^Binary operation "\*" between 2 and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 2
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Fisher.php
-
message: '#^Binary operation "\+" between 1 and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Fisher.php
-
message: '#^Binary operation "\-" between 1 and mixed results in an error\.$#'
identifier: binaryOp.invalid
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Distributions/Fisher.php
-
message: '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\.$#'
identifier: foreach.nonIterable
count: 1
path: src/PhpSpreadsheet/Calculation/Statistical/Trends.php
-
message: '#^Parameter \#1 \$yValues of static method PhpOffice\\PhpSpreadsheet\\Calculation\\Statistical\\Trends\:\:validateTrendArrays\(\) expects array, mixed given\.$#'
identifier: argument.type
count: 9
path: src/PhpSpreadsheet/Calculation/Statistical/Trends.php
-
message: '#^Parameter \#2 \$xValues of static method PhpOffice\\PhpSpreadsheet\\Calculation\\Statistical\\Trends\:\:validateTrendArrays\(\) expects array, mixed given\.$#'
identifier: argument.type
count: 9
path: src/PhpSpreadsheet/Calculation/Statistical/Trends.php
-
message: '#^Parameter \#2 \$yValues of static method PhpOffice\\PhpSpreadsheet\\Shared\\Trend\\Trend\:\:calculate\(\) expects array, mixed given\.$#'
identifier: argument.type
count: 9
path: src/PhpSpreadsheet/Calculation/Statistical/Trends.php
-
message: '#^Parameter \#3 \$xValues of static method PhpOffice\\PhpSpreadsheet\\Shared\\Trend\\Trend\:\:calculate\(\) expects array, mixed given\.$#'
identifier: argument.type
count: 9
path: src/PhpSpreadsheet/Calculation/Statistical/Trends.php
+1 -3
View File
@@ -1,14 +1,12 @@
<?php
use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException;
use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;
require __DIR__ . '/../Header.php';
$helper = new Sample();
if ($helper->isCli()) {
$helper->log('This example should only be run from a Web Browser' . PHP_EOL);
@@ -60,7 +58,7 @@ $currencies = [
<div class="mb-3 row">
<label for="position" class="col-sm-2 col-form-label">Currency Position</label>
<div class="col-sm-10">
<input name="position" type="radio" value="1" <?php echo ((isset($_POST['position']) === false) || (isset($_POST['position']) && $_POST['position'] === '1')) ? 'checked' : ''; ?>>Leading
<input name="position" type="radio" value="1" <?php echo ((isset($_POST['position']) === false) || ($_POST['position'] === '1')) ? 'checked' : ''; ?>>Leading
<input name="position" type="radio" value="0" <?php echo (isset($_POST['position']) && $_POST['position'] === '0') ? 'checked' : ''; ?>>Trailing
</div>
</div>
+1 -3
View File
@@ -1,7 +1,6 @@
<?php
use PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException;
use PhpOffice\PhpSpreadsheet\Helper\Sample;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard;
@@ -10,7 +9,6 @@ use PhpOffice\PhpSpreadsheet\Writer\Html as HtmlWriter;
require __DIR__ . '/../Header.php';
$helper = new Sample();
if ($helper->isCli()) {
$helper->log('This example should only be run from a Web Browser' . PHP_EOL);
@@ -75,7 +73,7 @@ $currencies = [
<div class="mb-3 row">
<label for="position" class="col-sm-2 col-form-label">Currency Position</label>
<div class="col-sm-10">
<input name="position" type="radio" value="1" <?php echo ((isset($_POST['position']) === false) || (isset($_POST['position']) && $_POST['position'] === '1')) ? 'checked' : ''; ?>>Leading
<input name="position" type="radio" value="1" <?php echo ((isset($_POST['position']) === false) || ($_POST['position'] === '1')) ? 'checked' : ''; ?>>Leading
<input name="position" type="radio" value="0" <?php echo (isset($_POST['position']) && $_POST['position'] === '0') ? 'checked' : ''; ?>>Trailing
</div>
</div>
@@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
class Hyperlink
{
@@ -22,18 +23,23 @@ class Hyperlink
*/
public static function set(mixed $linkURL = '', mixed $displayName = null, ?Cell $cell = null): string
{
$linkURL = ($linkURL === null) ? '' : Functions::flattenSingleValue($linkURL);
$linkURL = ($linkURL === null) ? '' : StringHelper::convertToString(Functions::flattenSingleValue($linkURL));
$displayName = ($displayName === null) ? '' : Functions::flattenSingleValue($displayName);
if ((!is_object($cell)) || (trim($linkURL) == '')) {
return ExcelError::REF();
}
if ((is_object($displayName)) || trim($displayName) == '') {
if (is_object($displayName)) {
$displayName = $linkURL;
}
$displayName = StringHelper::convertToString($displayName);
if (trim($displayName) === '') {
$displayName = $linkURL;
}
$cell->getHyperlink()->setUrl($linkURL);
$cell->getHyperlink()
->setUrl($linkURL);
$cell->getHyperlink()->setTooltip($displayName);
return $displayName;
@@ -38,13 +38,15 @@ class Lookup
$lookupColumns = self::columnCount($lookupVector);
}
$resultVector = self::verifyResultVector($resultVector ?? $lookupVector);
$resultVector = self::verifyResultVector($resultVector ?? $lookupVector); //* @phpstan-ignore-line
if ($lookupRows === 2 && !$hasResultVector) {
$resultVector = array_pop($lookupVector);
$lookupVector = array_shift($lookupVector);
}
/** @var array $lookupVector */
/** @var array $resultVector */
if ($lookupColumns !== 2) {
$lookupVector = self::verifyLookupValues($lookupVector, $resultVector);
}
@@ -11,7 +11,7 @@ class LookupRefValidations
public static function validateInt(mixed $value): int
{
if (!is_numeric($value)) {
if (ErrorValue::isError($value)) {
if (is_string($value) && ErrorValue::isError($value)) {
throw new Exception($value);
}
@@ -40,6 +40,7 @@ class Matrix
}
$column = 0;
/** @var iterable $matrixData */
foreach ($matrixData as $matrixRow) {
$row = 0;
foreach ($matrixRow as $matrixCell) {
@@ -115,7 +116,7 @@ class Matrix
}
$rowKeys = array_keys($matrix);
$columnKeys = @array_keys($matrix[$rowKeys[0]]);
$columnKeys = @array_keys($matrix[$rowKeys[0]]); //* @phpstan-ignore-line
if ($columnNum > count($columnKeys)) {
return ExcelError::REF();
@@ -133,6 +134,7 @@ class Matrix
);
}
$rowNum = $rowKeys[--$rowNum];
/** @var array[] $matrix */
return $matrix[$rowNum][$columnNum];
}
@@ -25,28 +25,32 @@ class Offset
* @param null|string $cellAddress The reference from which you want to base the offset.
* Reference must refer to a cell or range of adjacent cells;
* otherwise, OFFSET returns the #VALUE! error value.
* @param mixed $rows The number of rows, up or down, that you want the upper-left cell to refer to.
* @param int $rows The number of rows, up or down, that you want the upper-left cell to refer to.
* Using 5 as the rows argument specifies that the upper-left cell in the
* reference is five rows below reference. Rows can be positive (which means
* below the starting reference) or negative (which means above the starting
* reference).
* @param mixed $columns The number of columns, to the left or right, that you want the upper-left cell
* @param int $columns The number of columns, to the left or right, that you want the upper-left cell
* of the result to refer to. Using 5 as the cols argument specifies that the
* upper-left cell in the reference is five columns to the right of reference.
* Cols can be positive (which means to the right of the starting reference)
* or negative (which means to the left of the starting reference).
* @param mixed $height The height, in number of rows, that you want the returned reference to be.
* @param ?int $height The height, in number of rows, that you want the returned reference to be.
* Height must be a positive number.
* @param mixed $width The width, in number of columns, that you want the returned reference to be.
* @param ?int $width The width, in number of columns, that you want the returned reference to be.
* Width must be a positive number.
*
* @return array|string An array containing a cell or range of cells, or a string on error
*/
public static function OFFSET(?string $cellAddress = null, mixed $rows = 0, mixed $columns = 0, mixed $height = null, mixed $width = null, ?Cell $cell = null): string|array
public static function OFFSET(?string $cellAddress = null, $rows = 0, $columns = 0, $height = null, $width = null, ?Cell $cell = null): string|array
{
/** @var int */
$rows = Functions::flattenSingleValue($rows);
/** @var int */
$columns = Functions::flattenSingleValue($columns);
/** @var int */
$height = Functions::flattenSingleValue($height);
/** @var int */
$width = Functions::flattenSingleValue($width);
if ($cellAddress === null || $cellAddress === '') {
@@ -126,7 +130,11 @@ class Offset
return $cellAddress;
}
private static function adjustEndCellColumnForWidth(string $endCellColumn, mixed $width, int $startCellColumn, mixed $columns): int
/**
* @param null|object|scalar $width
* @param scalar $columns
*/
private static function adjustEndCellColumnForWidth(string $endCellColumn, $width, int $startCellColumn, $columns): int
{
$endCellColumn = Coordinate::columnIndexFromString($endCellColumn) - 1;
if (($width !== null) && (!is_object($width))) {
@@ -138,7 +146,11 @@ class Offset
return $endCellColumn;
}
private static function adustEndCellRowForHeight(mixed $height, int $startCellRow, mixed $rows, mixed $endCellRow): int
/**
* @param null|object|scalar $height
* @param scalar $rows
*/
private static function adustEndCellRowForHeight($height, int $startCellRow, $rows, int $endCellRow): int
{
if (($height !== null) && (!is_object($height))) {
$endCellRow = $startCellRow + (int) $height - 1;
@@ -43,7 +43,7 @@ class Sort extends LookupRefValidations
try {
// If $sortIndex and $sortOrder are scalars, then convert them into arrays
if (is_scalar($sortIndex)) {
if (!is_array($sortIndex)) {
$sortIndex = [$sortIndex];
$sortOrder = is_scalar($sortOrder) ? [$sortOrder] : $sortOrder;
}
@@ -53,6 +53,7 @@ class Sort extends LookupRefValidations
} catch (Exception $e) {
return $e->getMessage();
}
/** @var array<int> $sortOrder */
// We want a simple, enumrated array of arrays where we can reference column by its index number.
$sortArray = array_values(array_map('array_values', $sortArray));
@@ -17,14 +17,14 @@ class VLookup extends LookupBase
* in the same row based on the index_number.
*
* @param mixed $lookupValue The value that you want to match in lookup_array
* @param mixed $lookupArray The range of cells being searched
* @param mixed $indexNumber The column number in table_array from which the matching value must be returned.
* @param array $lookupArray The range of cells being searched
* @param array|float|int|string $indexNumber The column number in table_array from which the matching value must be returned.
* The first column is 1.
* @param mixed $notExactMatch determines if you are looking for an exact match based on lookup_value
*
* @return mixed The value of the found cell
*/
public static function lookup(mixed $lookupValue, mixed $lookupArray, mixed $indexNumber, mixed $notExactMatch = true): mixed
public static function lookup(mixed $lookupValue, $lookupArray, mixed $indexNumber, mixed $notExactMatch = true): mixed
{
if (is_array($lookupValue) || is_array($indexNumber)) {
return self::evaluateArrayArgumentsIgnore([self::class, __FUNCTION__], 1, $lookupValue, $lookupArray, $indexNumber, $notExactMatch);
@@ -84,7 +84,7 @@ class VLookup extends LookupBase
*/
private static function vLookupSearch(mixed $lookupValue, array $lookupArray, $column, bool $notExactMatch): ?int
{
$lookupLower = StringHelper::strToLower((string) $lookupValue);
$lookupLower = StringHelper::strToLower(StringHelper::convertToString($lookupValue));
$rowNumber = null;
foreach ($lookupArray as $rowKey => $rowData) {
@@ -6,10 +6,11 @@ use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PhpOffice\PhpSpreadsheet\Cell\Cell;
class Subtotal
{
protected static function filterHiddenArgs(mixed $cellReference, mixed $args): array
protected static function filterHiddenArgs(Cell $cellReference, array $args): array
{
return array_filter(
$args,
@@ -20,13 +21,13 @@ class Subtotal
return true;
}
return $cellReference->getWorksheet()->getRowDimension($row)->getVisible();
return $cellReference->getWorksheet()->getRowDimension((int) $row)->getVisible();
},
ARRAY_FILTER_USE_KEY
);
}
protected static function filterFormulaArgs(mixed $cellReference, mixed $args): array
protected static function filterFormulaArgs(Cell $cellReference, array $args): array
{
return array_filter(
$args,
@@ -40,7 +41,7 @@ class Subtotal
$isFormula = $cellReference->getWorksheet()->getCell($column . $row)->isFormula();
$cellFormula = !preg_match(
'/^=.*\b(SUBTOTAL|AGGREGATE)\s*\(/i',
$cellReference->getWorksheet()->getCell($column . $row)->getValue() ?? ''
$cellReference->getWorksheet()->getCell($column . $row)->getValueString()
);
$retVal = !$isFormula || $cellFormula;
@@ -85,6 +86,7 @@ class Subtotal
*/
public static function evaluate(mixed $functionType, ...$args): float|int|string
{
/** @var Cell */
$cellReference = array_pop($args);
$bArgs = Functions::flattenArrayIndexed($args);
$aArgs = [];
@@ -119,7 +121,7 @@ class Subtotal
if (array_key_exists($subtotal, self::CALL_FUNCTIONS)) {
$call = self::CALL_FUNCTIONS[$subtotal];
return call_user_func_array($call, $aArgs);
return call_user_func_array($call, $aArgs); //* @phpstan-ignore-line
}
return ExcelError::VALUE();
@@ -44,6 +44,8 @@ class Averages extends AggregateBase
return ExcelError::VALUE();
}
if (self::isAcceptedCountable($arg, $k)) {
/** @var float|int|numeric-string $arg */
/** @var float|int|numeric-string $aMean */
$returnValue += abs($arg - $aMean);
++$aCount;
}
@@ -83,6 +85,7 @@ class Averages extends AggregateBase
return ExcelError::VALUE();
}
if (self::isAcceptedCountable($arg, $k)) {
/** @var float|int|numeric-string $arg */
$returnValue += $arg;
++$aCount;
}
@@ -59,8 +59,9 @@ class Conditional
{
if (empty($args)) {
return 0.0;
} elseif (count($args) === 3) {
return self::AVERAGEIF($args[1], $args[2], $args[0]);
}
if (count($args) === 3) {
return self::AVERAGEIF($args[1], $args[2], $args[0]); //* @phpstan-ignore-line
}
foreach ($args as $arg) {
if (is_array($arg) && array_key_exists(0, $arg)) {
@@ -46,6 +46,9 @@ class Confidence
/** @var float $temp */
$temp = Distributions\StandardNormal::inverse(1 - $alpha / 2);
return Functions::scalar($temp * $stdDev / sqrt($size));
/** @var float */
$result = Functions::scalar($temp * $stdDev / sqrt($size));
return $result;
}
}
@@ -181,10 +181,10 @@ class ChiSquared
* (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
* @param array $actual an array of observed frequencies
* @param array $expected an array of expected frequencies
*/
public static function test(mixed $actual, mixed $expected): float|string
public static function test($actual, $expected): float|string
{
$rows = count($actual);
$actual = Functions::flattenArray($actual);
@@ -209,6 +209,7 @@ class ChiSquared
$degrees = self::degrees($rows, $columns);
/** @var float|string */
$result = Functions::scalar(self::distributionRightTail($result, $degrees));
return $result;
@@ -30,7 +30,7 @@ class Fisher
}
try {
DistributionValidations::validateFloat($value);
$value = DistributionValidations::validateFloat($value);
} catch (Exception $e) {
return $e->getMessage();
}
@@ -62,7 +62,7 @@ class Fisher
}
try {
DistributionValidations::validateFloat($probability);
$probability = DistributionValidations::validateFloat($probability);
} catch (Exception $e) {
return $e->getMessage();
}
@@ -24,6 +24,9 @@ class Trends
/**
* @param mixed $array1 should be array, but scalar is made into one
* @param mixed $array2 should be array, but scalar is made into one
*
* @param-out array $array1
* @param-out array $array2
*/
private static function checkTrendArrays(mixed &$array1, mixed &$array2): void
{
@@ -3,6 +3,7 @@
namespace PhpOffice\PhpSpreadsheet\Writer\Xls;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Style\ConditionalFormatting\Wizard;
class ConditionalHelper
@@ -35,9 +36,7 @@ class ConditionalHelper
$this->tokens = pack('Cv', 0x1E, $condition);
} else {
try {
/** @var float|int|string */
$conditionx = $condition; // @phpstan-ignore-line
$formula = Wizard\WizardAbstract::reverseAdjustCellRef((string) $conditionx, $cellRange);
$formula = Wizard\WizardAbstract::reverseAdjustCellRef(StringHelper::convertToString($condition), $cellRange);
$this->parser->parse($formula);
$this->tokens = $this->parser->toReversePolish();
$this->size = strlen($this->tokens ?? '');
@@ -5,13 +5,14 @@ declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
// TODO Convert to Spreadsheet context.
class ChiTestTest extends TestCase
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCHITEST')]
public function testCHITEST(mixed $expectedResult, mixed $actual, mixed $expected): void
#[DataProvider('providerCHITEST')]
public function testCHITEST(mixed $expectedResult, array $actual, array $expected): void
{
$result = Statistical\Distributions\ChiSquared::test($actual, $expected);
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);