From e53a04b016f291329d25efa064a81827c4c3db57 Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Thu, 8 May 2025 22:44:13 -0700 Subject: [PATCH] Start Calculation Changes --- phpstan-baseline.neon | 2 +- .../Calculation/Calculation.php | 69 ++++++++++++++----- .../Calculation/TextData/CaseConvert.php | 6 +- .../Calculation/TextData/CharacterConvert.php | 4 +- .../Calculation/TextData/Concatenate.php | 22 ++++-- .../Calculation/TextData/Extract.php | 26 ++++--- .../Calculation/TextData/Format.php | 14 ++-- .../Calculation/TextData/Replace.php | 4 +- .../Calculation/TextData/Search.php | 4 +- .../Calculation/TextData/Text.php | 24 ++++--- .../Calculation/TextData/Trim.php | 4 +- .../Calculation/CalculationTest.php | 6 ++ .../Functions/TextData/ArrayToTextTest.php | 5 +- .../Functions/TextData/CharTest.php | 6 +- .../Functions/TextData/CleanTest.php | 6 +- .../Functions/TextData/CodeTest.php | 6 +- .../Functions/TextData/DollarTest.php | 6 +- .../Functions/TextData/ExactTest.php | 6 +- .../Functions/TextData/FindTest.php | 6 +- .../Functions/TextData/FixedTest.php | 6 +- .../Functions/TextData/LeftTest.php | 14 ++-- .../Functions/TextData/LenTest.php | 6 +- .../Functions/TextData/LowerTest.php | 8 ++- .../Functions/TextData/MidTest.php | 14 ++-- .../Functions/TextData/NumberValueTest.php | 6 +- .../Functions/TextData/ProperTest.php | 8 ++- .../Functions/TextData/ReplaceTest.php | 6 +- .../Functions/TextData/ReptTest.php | 6 +- .../Functions/TextData/RightTest.php | 14 ++-- .../Functions/TextData/SearchTest.php | 6 +- .../Functions/TextData/SubstituteTest.php | 6 +- .../Calculation/Functions/TextData/TTest.php | 7 +- .../Functions/TextData/TextAfterTest.php | 5 +- .../Functions/TextData/TextBeforeTest.php | 5 +- .../Functions/TextData/TextJoinTest.php | 7 +- .../Functions/TextData/TextSplitTest.php | 8 ++- .../Functions/TextData/TextTest.php | 6 +- .../Functions/TextData/TrimTest.php | 6 +- .../Functions/TextData/UpperTest.php | 8 ++- .../Functions/TextData/ValueTest.php | 6 +- .../Functions/Web/WebServiceTest.php | 4 +- 41 files changed, 262 insertions(+), 126 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index aab499115..364905f71 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,2 +1,2 @@ parameters: - ignoreErrors: [] + ignoreErrors: diff --git a/src/PhpSpreadsheet/Calculation/Calculation.php b/src/PhpSpreadsheet/Calculation/Calculation.php index cca6ca446..04b5c5e1b 100644 --- a/src/PhpSpreadsheet/Calculation/Calculation.php +++ b/src/PhpSpreadsheet/Calculation/Calculation.php @@ -132,6 +132,7 @@ class Calculation extends CalculationLocale */ private CyclicReferenceStack $cyclicReferenceStack; + /** @var mixed[] */ private array $cellStack = []; /** @@ -496,6 +497,7 @@ class Calculation extends CalculationLocale if ($cellAddress === null) { throw new Exception('null cellAddress in calculateCellValue'); } + /** @var array{sheet: string, cell: string} $cellAddress */ $testSheet = $this->spreadsheet->getSheetByName($cellAddress['sheet']); if ($testSheet === null) { throw new Exception('worksheet not found in calculateCellValue'); @@ -509,6 +511,7 @@ class Calculation extends CalculationLocale $sheetName = $cellAddress['sheet'] ?? null; $testSheet = is_string($sheetName) ? $this->spreadsheet->getSheetByName($sheetName) : null; if ($testSheet !== null && array_key_exists('cell', $cellAddress)) { + /** @var array{cell: string} $cellAddress */ $testSheet->getCell($cellAddress['cell']); } } @@ -537,6 +540,8 @@ class Calculation extends CalculationLocale * Validate and parse a formula string. * * @param string $formula Formula to parse + * + * @return array|bool */ public function parseFormula(string $formula): array|bool { @@ -705,11 +710,11 @@ class Calculation extends CalculationLocale * * @param mixed $operand1 First matrix operand * - * @param-out array $operand1 + * @param-out mixed[] $operand1 * * @param mixed $operand2 Second matrix operand * - * @param-out array $operand2 + * @param-out mixed[] $operand2 * * @param int $resize Flag indicating whether the matrices should be resized to match * and (if so), whether the smaller dimension should grow or the @@ -845,6 +850,7 @@ class Calculation extends CalculationLocale if (($matrix2Columns < $matrix1Columns) || ($matrix2Rows < $matrix1Rows)) { if ($matrix2Columns < $matrix1Columns) { for ($i = 0; $i < $matrix2Rows; ++$i) { + /** @var mixed[][] $matrix2 */ $x = $matrix2[$i][$matrix2Columns - 1]; for ($j = $matrix2Columns; $j < $matrix1Columns; ++$j) { $matrix2[$i][$j] = $x; @@ -862,6 +868,7 @@ class Calculation extends CalculationLocale if (($matrix1Columns < $matrix2Columns) || ($matrix1Rows < $matrix2Rows)) { if ($matrix1Columns < $matrix2Columns) { for ($i = 0; $i < $matrix1Rows; ++$i) { + /** @var mixed[][] $matrix1 */ $x = $matrix1[$i][$matrix1Columns - 1]; for ($j = $matrix1Columns; $j < $matrix2Columns; ++$j) { $matrix1[$i][$j] = $x; @@ -954,14 +961,14 @@ class Calculation extends CalculationLocale return null; } + private const MATRIX_REPLACE_FROM = [self::FORMULA_OPEN_MATRIX_BRACE, ';', self::FORMULA_CLOSE_MATRIX_BRACE]; + private const MATRIX_REPLACE_TO = ['MKMATRIX(MKMATRIX(', '),MKMATRIX(', '))']; + /** * @return false|string False indicates an error */ private function convertMatrixReferences(string $formula): false|string { - static $matrixReplaceFrom = [self::FORMULA_OPEN_MATRIX_BRACE, ';', self::FORMULA_CLOSE_MATRIX_BRACE]; - static $matrixReplaceTo = ['MKMATRIX(MKMATRIX(', '),MKMATRIX(', '))']; - // Convert any Excel matrix references to the MKMATRIX() function if (str_contains($formula, self::FORMULA_OPEN_MATRIX_BRACE)) { // If there is the possibility of braces within a quoted string, then we don't treat those as matrix indicators @@ -978,7 +985,7 @@ class Calculation extends CalculationLocale if ($notWithinQuotes === true) { $openCount += substr_count($value, self::FORMULA_OPEN_MATRIX_BRACE); $closeCount += substr_count($value, self::FORMULA_CLOSE_MATRIX_BRACE); - $value = str_replace($matrixReplaceFrom, $matrixReplaceTo, $value); + $value = str_replace(self::MATRIX_REPLACE_FROM, self::MATRIX_REPLACE_TO, $value); } } unset($value); @@ -988,7 +995,7 @@ class Calculation extends CalculationLocale // If there's no quoted strings, then we do a simple count/replace $openCount = substr_count($formula, self::FORMULA_OPEN_MATRIX_BRACE); $closeCount = substr_count($formula, self::FORMULA_CLOSE_MATRIX_BRACE); - $formula = str_replace($matrixReplaceFrom, $matrixReplaceTo, $formula); + $formula = str_replace(self::MATRIX_REPLACE_FROM, self::MATRIX_REPLACE_TO, $formula); } // Trap for mismatched braces and trigger an appropriate error if ($openCount < $closeCount) { @@ -1120,7 +1127,7 @@ class Calculation extends CalculationLocale // call or a parenthesis $this->branchPruner->decrementDepth(); - if (is_array($d) && preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', $d['value'], $matches)) { + if (is_array($d) && preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', StringHelper::convertToString($d['value']), $matches)) { // Did this parenthesis just close a function? try { $this->branchPruner->closingBrace($d['value']); @@ -1184,6 +1191,7 @@ class Calculation extends CalculationLocale } } if ($argumentCountError) { + /** @var int $argumentCount */ return $this->raiseFormulaError("Formula Error: Wrong number of arguments for $functionName() function: $argumentCount given, " . $expectedArgumentCountString . ' expected'); } } @@ -1205,7 +1213,9 @@ class Calculation extends CalculationLocale } // make sure there was a function $d = $stack->last(2); - if (!preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', $d['value'] ?? '', $matches)) { + /** @var string */ + $temp = $d['value'] ?? ''; + if (!preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', $temp, $matches)) { // Can we inject a dummy function at this point so that the braces at least have some context // because at least the braces are paired up (at this stage in the formula) // MS Excel allows this if the content is cell references; but doesn't allow actual values, @@ -1273,6 +1283,7 @@ class Calculation extends CalculationLocale // Do we have chained range operators? $rangeStartCellRef = $output[count($output) - 2]['value'] ?? ''; } + /** @var string $rangeStartCellRef */ preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '$/miu', $rangeStartCellRef, $rangeStartMatches); if (array_key_exists(2, $rangeStartMatches)) { if ($rangeStartMatches[2] > '') { @@ -1287,6 +1298,7 @@ class Calculation extends CalculationLocale // Do we have chained range operators? $rangeStartCellRef = $output[count($output) - 2]['value'] ?? ''; } + /** @var string $rangeStartCellRef */ preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '$/miu', $rangeStartCellRef, $rangeStartMatches); if (isset($rangeStartMatches[2]) && $rangeStartMatches[2] !== $matches[2]) { return $this->raiseFormulaError('3D Range references are not yet supported'); @@ -1547,6 +1559,8 @@ class Calculation extends CalculationLocale private static int $matchIndex10 = 10; /** + * @param array|false $tokens + * * @return array|false|string */ private function processTokenStack(false|array $tokens, ?string $cellID = null, ?Cell $cell = null) @@ -1569,14 +1583,17 @@ class Calculation extends CalculationLocale $branchStore = []; // Loop through each token in turn foreach ($tokens as $tokenIdx => $tokenData) { + /** @var mixed[] $tokenData */ $this->processingAnchorArray = false; - if ($tokenData['type'] === 'Cell Reference' && isset($tokens[$tokenIdx + 1]) && $tokens[$tokenIdx + 1]['type'] === 'Operand Count for Function ANCHORARRAY()') { + if ($tokenData['type'] === 'Cell Reference' && isset($tokens[$tokenIdx + 1]) && $tokens[$tokenIdx + 1]['type'] === 'Operand Count for Function ANCHORARRAY()') { //* @phpstan-ignore-line $this->processingAnchorArray = true; } $token = $tokenData['value']; // Branch pruning: skip useless resolutions + /** @var ?string */ $storeKey = $tokenData['storeKey'] ?? null; if ($this->branchPruningEnabled && isset($tokenData['onlyIf'])) { + /** @var string */ $onlyIfStoreKey = $tokenData['onlyIf']; $storeValue = $branchStore[$onlyIfStoreKey] ?? null; $storeValueAsBool = ($storeValue === null) @@ -1591,7 +1608,9 @@ class Calculation extends CalculationLocale && (!$storeValueAsBool || Information\ErrorValue::isError($storeValue) || ($storeValue === 'Pruned branch')) ) { // If branching value is not true, we don't need to compute + /** @var string $onlyIfStoreKey */ if (!isset($fakedForBranchPruning['onlyIf-' . $onlyIfStoreKey])) { + /** @var string $token */ $stack->push('Value', 'Pruned branch (only if ' . $onlyIfStoreKey . ') ' . $token); $fakedForBranchPruning['onlyIf-' . $onlyIfStoreKey] = true; } @@ -1609,6 +1628,7 @@ class Calculation extends CalculationLocale } if ($this->branchPruningEnabled && isset($tokenData['onlyIfNot'])) { + /** @var string */ $onlyIfNotStoreKey = $tokenData['onlyIfNot']; $storeValue = $branchStore[$onlyIfNotStoreKey] ?? null; $storeValueAsBool = ($storeValue === null) @@ -1624,6 +1644,7 @@ class Calculation extends CalculationLocale ) { // If branching value is true, we don't need to compute if (!isset($fakedForBranchPruning['onlyIfNot-' . $onlyIfNotStoreKey])) { + /** @var string $token */ $stack->push('Value', 'Pruned branch (only if not ' . $onlyIfNotStoreKey . ') ' . $token); $fakedForBranchPruning['onlyIfNot-' . $onlyIfNotStoreKey] = true; } @@ -1706,19 +1727,22 @@ class Calculation extends CalculationLocale // Binary Operators case ':': // Range if ($operand1Data['type'] === 'Defined Name') { + /** @var array{reference: string} $operand1Data */ if (preg_match('/$' . self::CALCULATION_REGEXP_DEFINEDNAME . '^/mui', $operand1Data['reference']) !== false && $this->spreadsheet !== null) { + /** @var string[] $operand1Data */ $definedName = $this->spreadsheet->getNamedRange($operand1Data['reference']); if ($definedName !== null) { $operand1Data['reference'] = $operand1Data['value'] = str_replace('$', '', $definedName->getValue()); } } } + /** @var array{reference?: ?string} $operand1Data */ if (str_contains($operand1Data['reference'] ?? '', '!')) { [$sheet1, $operand1Data['reference']] = Worksheet::extractSheetTitle($operand1Data['reference'], true, true); } else { $sheet1 = ($pCellWorksheet !== null) ? $pCellWorksheet->getTitle() : ''; } - $sheet1 ??= ''; + //$sheet1 ??= ''; // phpstan level 10 says this is unneeded /** @var string */ $op2ref = $operand2Data['reference']; @@ -1728,6 +1752,7 @@ class Calculation extends CalculationLocale } if ($sheet1 === $sheet2) { + /** @var array{reference: ?string, value: string|string[]} $operand1Data */ if ($operand1Data['reference'] === null && $cell !== null) { if (is_array($operand1Data['value'])) { $operand1Data['reference'] = $cell->getCoordinate(); @@ -1739,6 +1764,7 @@ class Calculation extends CalculationLocale $operand1Data['reference'] = $operand1Data['value'] . $cell->getRow(); } } + /** @var array{reference: ?string, value: string|string[]} $operand2Data */ if ($operand2Data['reference'] === null && $cell !== null) { if (is_array($operand2Data['value'])) { $operand2Data['reference'] = $cell->getCoordinate(); @@ -1813,7 +1839,9 @@ class Calculation extends CalculationLocale for ($row = 0; $row < $rows; ++$row) { for ($column = 0; $column < $columns; ++$column) { + /** @var mixed[][] $operand1 */ $op1x = self::boolToString($operand1[$row][$column]); + /** @var mixed[][] $operand2 */ $op2x = self::boolToString($operand2[$row][$column]); if (Information\ErrorValue::isError($op1x)) { // no need to do anything @@ -1898,8 +1926,11 @@ class Calculation extends CalculationLocale [$rows, $columns] = self::checkMatrixOperands($result, $operand2, 0); for ($row = 0; $row < $rows; ++$row) { for ($column = 0; $column < $columns; ++$column) { + /** @var mixed[][] $result */ if (self::isNumericOrBool($result[$row][$column])) { - $result[$row][$column] *= $multiplier; + /** @var float|int|numeric-string */ + $temp = $result[$row][$column]; + $result[$row][$column] = $temp * $multiplier; } else { $result[$row][$column] = self::makeError($result[$row][$column]); } @@ -1914,7 +1945,7 @@ class Calculation extends CalculationLocale } else { $this->executeNumericBinaryOperation($multiplier, $arg, '*', $stack); } - } elseif (preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '$/i', $token ?? '', $matches)) { + } elseif (preg_match('/^' . self::CALCULATION_REGEXP_CELLREF . '$/i', StringHelper::convertToString($token ?? ''), $matches)) { $cellRef = null; /* Phpstan says matches[8/9/10] is never set, @@ -2005,7 +2036,7 @@ class Calculation extends CalculationLocale if (isset($storeKey)) { $branchStore[$storeKey] = $cellValue; } - } elseif (preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', $token ?? '', $matches)) { + } elseif (preg_match('/^' . self::CALCULATION_REGEXP_FUNCTION . '$/miu', StringHelper::convertToString($token ?? ''), $matches)) { // if the token is a function, pop arguments off the stack, hand them to the function, and push the result back on if ($cell !== null && $pCellParent !== null) { $cell->attach($pCellParent); @@ -2131,14 +2162,16 @@ class Calculation extends CalculationLocale } } else { // if the token is a number, boolean, string or an Excel error, push it onto the stack + /** @var ?string $token */ if (isset(self::EXCEL_CONSTANTS[strtoupper($token ?? '')])) { - $excelConstant = strtoupper($token); + $excelConstant = strtoupper("$token"); $stack->push('Constant Value', self::EXCEL_CONSTANTS[$excelConstant]); if (isset($storeKey)) { $branchStore[$storeKey] = self::EXCEL_CONSTANTS[$excelConstant]; } $this->debugLog->writeDebugLog('Evaluating Constant %s as %s', $excelConstant, $this->showTypeDetails(self::EXCEL_CONSTANTS[$excelConstant])); - } elseif ((is_numeric($token)) || ($token === null) || (is_bool($token)) || ($token == '') || ($token[0] == self::FORMULA_STRING_QUOTE) || ($token[0] == '#')) { + } elseif ((is_numeric($token)) || ($token === null) || (is_bool($token)) || ($token == '') || ($token[0] == self::FORMULA_STRING_QUOTE) || ($token[0] == '#')) { //* @phpstan-ignore-line + /** @var array{type: string, reference: ?string} $tokenData */ $stack->push($tokenData['type'], $token, $tokenData['reference']); if (isset($storeKey)) { $branchStore[$storeKey] = $token; @@ -2334,6 +2367,7 @@ class Calculation extends CalculationLocale for ($row = 0; $row < $rows; ++$row) { for ($column = 0; $column < $columns; ++$column) { + /** @var mixed[][] $operand1 */ if ($operand1[$row][$column] === null) { $operand1[$row][$column] = 0; } elseif (!self::isNumericOrBool($operand1[$row][$column])) { @@ -2341,6 +2375,7 @@ class Calculation extends CalculationLocale continue; } + /** @var mixed[][] $operand2 */ if ($operand2[$row][$column] === null) { $operand2[$row][$column] = 0; } elseif (!self::isNumericOrBool($operand2[$row][$column])) { @@ -2464,6 +2499,7 @@ class Calculation extends CalculationLocale public function extractCellRange(string &$range = 'A1', ?Worksheet $worksheet = null, bool $resetLog = true): array { // Return value + /** @var mixed[][] */ $returnValue = []; if ($worksheet !== null) { @@ -2557,6 +2593,7 @@ class Calculation extends CalculationLocale if (!isset($aReferences[1])) { // Single cell (or single column or row) in range [$currentCol, $currentRow] = Coordinate::coordinateFromString($aReferences[0]); + /** @var mixed[][] $returnValue */ if ($worksheet !== null && $worksheet->cellExists($aReferences[0])) { $returnValue[$currentRow][$currentCol] = $worksheet->getCell($aReferences[0])->getCalculatedValue($resetLog); } else { diff --git a/src/PhpSpreadsheet/Calculation/TextData/CaseConvert.php b/src/PhpSpreadsheet/Calculation/TextData/CaseConvert.php index 6667bac54..ff67feb99 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/CaseConvert.php +++ b/src/PhpSpreadsheet/Calculation/TextData/CaseConvert.php @@ -18,7 +18,7 @@ class CaseConvert * @param mixed $mixedCaseValue The string value to convert to lower case * Or can be an array of values * - * @return array|string If an array of values is passed as the argument, then the returned result will also be an array + * @return array|string If an array of values is passed as the argument, then the returned result will also be an array * with the same dimensions */ public static function lower(mixed $mixedCaseValue): array|string @@ -44,7 +44,7 @@ class CaseConvert * @param mixed $mixedCaseValue The string value to convert to upper case * Or can be an array of values * - * @return array|string If an array of values is passed as the argument, then the returned result will also be an array + * @return array|string If an array of values is passed as the argument, then the returned result will also be an array * with the same dimensions */ public static function upper(mixed $mixedCaseValue): array|string @@ -70,7 +70,7 @@ class CaseConvert * @param mixed $mixedCaseValue The string value to convert to title case * Or can be an array of values * - * @return array|string If an array of values is passed as the argument, then the returned result will also be an array + * @return array|string If an array of values is passed as the argument, then the returned result will also be an array * with the same dimensions */ public static function proper(mixed $mixedCaseValue): array|string diff --git a/src/PhpSpreadsheet/Calculation/TextData/CharacterConvert.php b/src/PhpSpreadsheet/Calculation/TextData/CharacterConvert.php index 0f14ee468..2f15bfcd2 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/CharacterConvert.php +++ b/src/PhpSpreadsheet/Calculation/TextData/CharacterConvert.php @@ -17,7 +17,7 @@ class CharacterConvert * @param mixed $character Integer Value to convert to its character representation * Or can be an array of values * - * @return array|string The character string + * @return array|string The character string * If an array of values is passed as the argument, then the returned result will also be an array * with the same dimensions */ @@ -48,7 +48,7 @@ class CharacterConvert * @param mixed $characters String character to convert to its ASCII value * Or can be an array of values * - * @return array|int|string A string if arguments are invalid + * @return array|int|string A string if arguments are invalid * If an array of values is passed as the argument, then the returned result will also be an array * with the same dimensions */ diff --git a/src/PhpSpreadsheet/Calculation/TextData/Concatenate.php b/src/PhpSpreadsheet/Calculation/TextData/Concatenate.php index dfb490af9..d51d44b0b 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Concatenate.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Concatenate.php @@ -17,7 +17,7 @@ class Concatenate /** * This implements the CONCAT function, *not* CONCATENATE. * - * @param array $args + * @param mixed[] $args */ public static function CONCATENATE(...$args): string { @@ -47,7 +47,9 @@ class Concatenate /** * This implements the CONCATENATE function. * - * @param array $args data to be concatenated + * @param mixed[] $args data to be concatenated + * + * @return array|string */ public static function actualCONCATENATE(...$args): array|string { @@ -65,6 +67,12 @@ class Concatenate return $result; } + /** + * @param array|string $operand1 + * @param null|array|bool|float|int|string $operand2 + * + * @return array|string + */ private static function concatenate2Args(array|string $operand1, null|array|bool|float|int|string $operand2): array|string { if (is_array($operand1) || is_array($operand2)) { @@ -74,9 +82,11 @@ class Concatenate $errorFound = false; for ($row = 0; $row < $rows && !$errorFound; ++$row) { for ($column = 0; $column < $columns; ++$column) { + /** @var string[][] $operand2 */ if (ErrorValue::isError($operand2[$row][$column])) { return $operand2[$row][$column]; } + /** @var string[][] $operand1 */ $operand1[$row][$column] = StringHelper::convertToString($operand1[$row][$column], convertBool: true) . StringHelper::convertToString($operand2[$row][$column], convertBool: true); @@ -96,6 +106,7 @@ class Concatenate $operand1 = ExcelError::CALC(); } } + /** @var array|string $operand1 */ return $operand1; } @@ -109,7 +120,7 @@ class Concatenate * Or can be an array of values * @param mixed $args The values to join * - * @return array|string The joined string + * @return array|string The joined string * If an array of values is passed for the $delimiter or $ignoreEmpty arguments, then the returned result * will also be an array with matching dimensions */ @@ -127,7 +138,7 @@ class Concatenate $delimiter ??= ''; $ignoreEmpty ??= true; - /** @var array */ + /** @var mixed[] */ $aArgs = Functions::flattenArray($args); $returnValue = self::evaluateTextJoinArray($ignoreEmpty, $aArgs); @@ -139,6 +150,7 @@ class Concatenate return $returnValue; } + /** @param mixed[] $aArgs */ private static function evaluateTextJoinArray(bool $ignoreEmpty, array &$aArgs): ?string { foreach ($aArgs as $key => &$arg) { @@ -167,7 +179,7 @@ class Concatenate * @param mixed $repeatCount The number of times the string value should be repeated * Or can be an array of values * - * @return array|string The repeated string + * @return array|string The repeated string * If an array of values is passed for the $stringValue or $repeatCount arguments, then the returned result * will also be an array with matching dimensions */ diff --git a/src/PhpSpreadsheet/Calculation/TextData/Extract.php b/src/PhpSpreadsheet/Calculation/TextData/Extract.php index 2cfec1ae4..98f65b0ce 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Extract.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Extract.php @@ -20,7 +20,7 @@ class Extract * @param mixed $chars The number of characters to extract (as an integer) * Or can be an array of values * - * @return array|string The joined string + * @return array|string The joined string * If an array of values is passed for the $value or $chars arguments, then the returned result * will also be an array with matching dimensions */ @@ -50,7 +50,7 @@ class Extract * @param mixed $chars The number of characters to extract (as an integer) * Or can be an array of values * - * @return array|string The joined string + * @return array|string The joined string * If an array of values is passed for the $value, $start or $chars arguments, then the returned result * will also be an array with matching dimensions */ @@ -79,7 +79,7 @@ class Extract * @param mixed $chars The number of characters to extract (as an integer) * Or can be an array of values * - * @return array|string The joined string + * @return array|string The joined string * If an array of values is passed for the $value or $chars arguments, then the returned result * will also be an array with matching dimensions */ @@ -104,7 +104,7 @@ class Extract * * @param mixed $text the text that you're searching * Or can be an array of values - * @param null|array|string $delimiter the text that marks the point before which you want to extract + * @param null|array|string $delimiter the text that marks the point before which you want to extract * Multiple delimiters can be passed as an array of string values * @param mixed $instance The instance of the delimiter after which you want to extract the text. * By default, this is the first instance (1). @@ -118,11 +118,11 @@ class Extract * 0 - Don't match the delimiter against the end of the text. * 1 - Match the delimiter against the end of the text. * Or can be an array of values - * @param mixed $ifNotFound value to return if no match is found + * @param array|bool|float|int|string $ifNotFound value to return if no match is found * The default is a #N/A Error * Or can be an array of values * - * @return array|string the string extracted from text before the delimiter; or the $ifNotFound value + * @return array|string the string extracted from text before the delimiter; or the $ifNotFound value * If an array of values is passed for any of the arguments, then the returned result * will also be an array with matching dimensions */ @@ -168,7 +168,7 @@ class Extract * TEXTAFTER. * * @param mixed $text the text that you're searching - * @param null|array|string $delimiter the text that marks the point before which you want to extract + * @param null|array|string $delimiter the text that marks the point before which you want to extract * Multiple delimiters can be passed as an array of string values * @param mixed $instance The instance of the delimiter after which you want to extract the text. * By default, this is the first instance (1). @@ -182,11 +182,11 @@ class Extract * 0 - Don't match the delimiter against the end of the text. * 1 - Match the delimiter against the end of the text. * Or can be an array of values - * @param mixed $ifNotFound value to return if no match is found + * @param array|scalar $ifNotFound value to return if no match is found * The default is a #N/A Error * Or can be an array of values * - * @return array|string the string extracted from text before the delimiter; or the $ifNotFound value + * @return array|string the string extracted from text before the delimiter; or the $ifNotFound value * If an array of values is passed for any of the arguments, then the returned result * will also be an array with matching dimensions */ @@ -228,6 +228,12 @@ class Extract return implode('', $split); } + /** + * @param null|array|string $delimiter + * @param array|scalar $ifNotFound + * + * @return array|string + */ private static function validateTextBeforeAfter(string $text, null|array|string $delimiter, int $instance, int $matchMode, int $matchEnd, mixed $ifNotFound): array|string { $flags = self::matchFlags($matchMode); @@ -256,7 +262,7 @@ class Extract } /** - * @param null|array|string $delimiter the text that marks the point before which you want to extract + * @param null|array|string $delimiter the text that marks the point before which you want to extract * Multiple delimiters can be passed as an array of string values */ private static function buildDelimiter($delimiter): string diff --git a/src/PhpSpreadsheet/Calculation/TextData/Format.php b/src/PhpSpreadsheet/Calculation/TextData/Format.php index f1b08a504..23bf74f03 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Format.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Format.php @@ -34,7 +34,7 @@ class Format * If you omit decimals, it is assumed to be 2 * Or can be an array of values * - * @return array|string If an array of values is passed for either of the arguments, then the returned result + * @return array|string If an array of values is passed for either of the arguments, then the returned result * will also be an array with matching dimensions */ public static function DOLLAR(mixed $value = 0, mixed $decimals = 2) @@ -76,7 +76,7 @@ class Format * @param mixed $noCommas Boolean value indicating whether the value should have thousands separators or not * Or can be an array of values * - * @return array|string If an array of values is passed for either of the arguments, then the returned result + * @return array|string If an array of values is passed for either of the arguments, then the returned result * will also be an array with matching dimensions */ public static function FIXEDFORMAT(mixed $value, mixed $decimals = 2, mixed $noCommas = false): array|string @@ -116,7 +116,7 @@ class Format * @param mixed $format A string with the Format mask that should be used * Or can be an array of values * - * @return array|string If an array of values is passed for either of the arguments, then the returned result + * @return array|string If an array of values is passed for either of the arguments, then the returned result * will also be an array with matching dimensions */ public static function TEXTFORMAT(mixed $value, mixed $format): array|string @@ -176,7 +176,7 @@ class Format * @param mixed $value Value to check * Or can be an array of values * - * @return array|DateTimeInterface|float|int|string A string if arguments are invalid + * @return array|DateTimeInterface|float|int|string A string if arguments are invalid * If an array of values is passed for the argument, then the returned result * will also be an array with matching dimensions */ @@ -236,7 +236,7 @@ class Format * @param mixed $value The value to format * Or can be an array of values * - * @return array|string If an array of values is passed for either of the arguments, then the returned result + * @return array|string If an array of values is passed for either of the arguments, then the returned result * will also be an array with matching dimensions */ public static function valueToText(mixed $value, mixed $format = false): array|string @@ -279,6 +279,8 @@ class Format * Or can be an array of values * @param mixed $groupSeparator A string with the group/thousands separator to use, defaults to locale defined value * Or can be an array of values + * + * @return array|float|string */ public static function NUMBERVALUE(mixed $value = '', mixed $decimalSeparator = null, mixed $groupSeparator = null): array|string|float { @@ -294,7 +296,7 @@ class Format return $e->getMessage(); } - /** @var null|array|scalar $value */ + /** @var null|array|scalar $value */ if (!is_array($value) && !is_numeric($value)) { $value = StringHelper::convertToString($value); $decimalPositions = Preg::matchAllWithOffsets('/' . preg_quote($decimalSeparator, '/') . '/', $value, $matches); diff --git a/src/PhpSpreadsheet/Calculation/TextData/Replace.php b/src/PhpSpreadsheet/Calculation/TextData/Replace.php index d2494c0ee..6931c9329 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Replace.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Replace.php @@ -25,7 +25,7 @@ class Replace * @param mixed $newText String to replace in the defined position * Or can be an array of values * - * @return array|string If an array of values is passed for either of the arguments, then the returned result + * @return array|string If an array of values is passed for either of the arguments, then the returned result * will also be an array with matching dimensions */ public static function replace(mixed $oldText, mixed $start, mixed $chars, mixed $newText): array|string @@ -65,7 +65,7 @@ class Replace * @param mixed $instance Integer instance Number for the occurrence of frmText to change * Or can be an array of values * - * @return array|string If an array of values is passed for either of the arguments, then the returned result + * @return array|string If an array of values is passed for either of the arguments, then the returned result * will also be an array with matching dimensions */ public static function substitute(mixed $text = '', mixed $fromText = '', mixed $toText = '', mixed $instance = null): array|string diff --git a/src/PhpSpreadsheet/Calculation/TextData/Search.php b/src/PhpSpreadsheet/Calculation/TextData/Search.php index 663d49fc2..0c4b97781 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Search.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Search.php @@ -21,7 +21,7 @@ class Search * @param mixed $offset Integer offset within $haystack to start searching from * Or can be an array of values * - * @return array|int|string The offset where the first occurrence of needle was found in the haystack + * @return array|int|string The offset where the first occurrence of needle was found in the haystack * If an array of values is passed for the $value or $chars arguments, then the returned result * will also be an array with matching dimensions */ @@ -63,7 +63,7 @@ class Search * @param mixed $offset Integer offset within $haystack to start searching from * Or can be an array of values * - * @return array|int|string The offset where the first occurrence of needle was found in the haystack + * @return array|int|string The offset where the first occurrence of needle was found in the haystack * If an array of values is passed for the $value or $chars arguments, then the returned result * will also be an array with matching dimensions */ diff --git a/src/PhpSpreadsheet/Calculation/TextData/Text.php b/src/PhpSpreadsheet/Calculation/TextData/Text.php index b5e841b66..f42227334 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Text.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Text.php @@ -20,7 +20,7 @@ class Text * @param mixed $value String Value * Or can be an array of values * - * @return array|int|string If an array of values is passed for the argument, then the returned result + * @return array|int|string If an array of values is passed for the argument, then the returned result * will also be an array with matching dimensions */ public static function length(mixed $value = ''): array|int|string @@ -48,7 +48,7 @@ class Text * @param mixed $value2 String Value * Or can be an array of values * - * @return array|bool|string If an array of values is passed for either of the arguments, then the returned result + * @return array|bool|string If an array of values is passed for either of the arguments, then the returned result * will also be an array with matching dimensions */ public static function exact(mixed $value1, mixed $value2): array|bool|string @@ -73,7 +73,7 @@ class Text * @param mixed $testValue Value to check * Or can be an array of values * - * @return array|string If an array of values is passed for the argument, then the returned result + * @return array|string If an array of values is passed for the argument, then the returned result * will also be an array with matching dimensions */ public static function test(mixed $testValue = ''): array|string @@ -93,9 +93,9 @@ class Text * TEXTSPLIT. * * @param mixed $text the text that you're searching - * @param null|array|string $columnDelimiter The text that marks the point where to spill the text across columns. + * @param null|array|string $columnDelimiter The text that marks the point where to spill the text across columns. * Multiple delimiters can be passed as an array of string values - * @param null|array|string $rowDelimiter The text that marks the point where to spill the text down rows. + * @param null|array|string $rowDelimiter The text that marks the point where to spill the text down rows. * Multiple delimiters can be passed as an array of string values * @param bool $ignoreEmpty Specify FALSE to create an empty cell when two delimiters are consecutive. * true = create empty cells @@ -108,7 +108,7 @@ class Text * @param mixed $padding The value with which to pad the result. * The default is #N/A. * - * @return array|string the array built from the text, split by the row and column delimiters, or an error string + * @return array|string the array built from the text, split by the row and column delimiters, or an error string */ public static function split(mixed $text, $columnDelimiter = null, $rowDelimiter = null, bool $ignoreEmpty = false, bool $matchMode = true, mixed $padding = '#N/A'): array|string { @@ -162,16 +162,21 @@ class Text return self::applyPadding($rows, $padding); } + /** + * @param mixed[] $rows + * + * @return mixed[] + */ private static function applyPadding(array $rows, mixed $padding): array { $columnCount = array_reduce( $rows, - fn (int $counter, array $row): int => max($counter, count($row)), + fn (int $counter, array $row): int => max($counter, count($row)), //* @phpstan-ignore-line 0 ); return array_map( - fn (array $row): array => (count($row) < $columnCount) + fn (array $row): array => (count($row) < $columnCount) //* @phpstan-ignore-line ? array_merge($row, array_fill(0, $columnCount - count($row), $padding)) : $row, $rows @@ -179,7 +184,7 @@ class Text } /** - * @param null|array|string $delimiter the text that marks the point before which you want to split + * @param null|array|string $delimiter the text that marks the point before which you want to split * Multiple delimiters can be passed as an array of string values */ private static function buildDelimiter($delimiter): string @@ -204,6 +209,7 @@ class Text return ($matchMode === true) ? 'miu' : 'mu'; } + /** @param mixed[][] $array */ public static function fromArray(array $array, int $format = 0): string { $result = []; diff --git a/src/PhpSpreadsheet/Calculation/TextData/Trim.php b/src/PhpSpreadsheet/Calculation/TextData/Trim.php index d83e14dd4..0a7bb2542 100644 --- a/src/PhpSpreadsheet/Calculation/TextData/Trim.php +++ b/src/PhpSpreadsheet/Calculation/TextData/Trim.php @@ -14,7 +14,7 @@ class Trim * @param mixed $stringValue String Value to check * Or can be an array of values * - * @return array|string If an array of values is passed as the argument, then the returned result will also be an array + * @return array|string If an array of values is passed as the argument, then the returned result will also be an array * with the same dimensions */ public static function nonPrintable(mixed $stringValue = '') @@ -34,7 +34,7 @@ class Trim * @param mixed $stringValue String Value to check * Or can be an array of values * - * @return array|string If an array of values is passed as the argument, then the returned result will also be an array + * @return array|string If an array of values is passed as the argument, then the returned result will also be an array * with the same dimensions */ public static function spaces(mixed $stringValue = ''): array|string diff --git a/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php b/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php index a7b1baf85..beff0611a 100644 --- a/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/CalculationTest.php @@ -51,12 +51,14 @@ class CalculationTest extends TestCase $tree = $calculation->parseFormula('=_xlfn.ISFORMULA(A1)'); self::assertIsArray($tree); self::assertCount(3, $tree); + /** @var mixed[] */ $function = $tree[2]; self::assertEquals('Function', $function['type']); $tree = $calculation->parseFormula('=_xlfn.STDEV.S(A1:B2)'); self::assertIsArray($tree); self::assertCount(5, $tree); + /** @var mixed[] */ $function = $tree[4]; self::assertEquals('Function', $function['type']); } @@ -253,6 +255,7 @@ class CalculationTest extends TestCase $foundEqualAssociatedToStoreKey = false; $foundConditionalOnB1 = false; foreach ($tokens as $token) { + /** @var mixed[] $token */ $isBinaryOperator = $token['type'] == 'Binary Operator'; $isEqual = $token['value'] == '='; $correctStoreKey = ($token['storeKey'] ?? '') == 'storeKey-0'; @@ -283,6 +286,7 @@ class CalculationTest extends TestCase $plusGotTagged = false; $productFunctionCorrectlyTagged = false; foreach ($tokens as $token) { + /** @var mixed[] $token */ $isBinaryOperator = $token['type'] == 'Binary Operator'; $isPlus = $token['value'] == '+'; $anyStoreKey = isset($token['storeKey']); @@ -315,6 +319,7 @@ class CalculationTest extends TestCase $notFunctionCorrectlyTagged = false; $findOneOperandCountTagged = false; foreach ($tokens as $token) { + /** @var mixed[] $token */ $value = $token['value']; $isPlus = $value == '+'; $isProductFunction = $value == 'PRODUCT('; @@ -357,6 +362,7 @@ class CalculationTest extends TestCase $properlyTaggedPlus = false; foreach ($tokens as $token) { + /** @var mixed[] $token */ $isPlus = $token['value'] === '+'; $hasOnlyIf = !empty($token['onlyIf']); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ArrayToTextTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ArrayToTextTest.php index a65b3a18f..3ec22ddda 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ArrayToTextTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ArrayToTextTest.php @@ -4,9 +4,12 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; +use PHPUnit\Framework\Attributes\DataProvider; + class ArrayToTextTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerARRAYTOTEXT')] + /** @param mixed[] $testData */ + #[DataProvider('providerARRAYTOTEXT')] public function testArrayToText(string $expectedResult, array $testData, int $mode): void { $worksheet = $this->getSheet(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CharTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CharTest.php index 4782e9d66..2695af5aa 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CharTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CharTest.php @@ -5,10 +5,11 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; +use PHPUnit\Framework\Attributes\DataProvider; class CharTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerCHAR')] + #[DataProvider('providerCHAR')] public function testCHAR(mixed $expectedResult, mixed $character = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -28,7 +29,8 @@ class CharTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/CHAR.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCharArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerCharArray')] public function testCharArray(array $expectedResult, string $array): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CleanTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CleanTest.php index 196f5a8d5..6c45269b9 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CleanTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CleanTest.php @@ -5,10 +5,11 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; +use PHPUnit\Framework\Attributes\DataProvider; class CleanTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerCLEAN')] + #[DataProvider('providerCLEAN')] public function testCLEAN(mixed $expectedResult, mixed $value = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -28,7 +29,8 @@ class CleanTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/CLEAN.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCleanArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerCleanArray')] public function testCleanArray(array $expectedResult, string $array): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php index c1ff8d8ca..756e1fc64 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php @@ -5,10 +5,11 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; +use PHPUnit\Framework\Attributes\DataProvider; class CodeTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerCODE')] + #[DataProvider('providerCODE')] public function testCODE(mixed $expectedResult, mixed $character = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -28,7 +29,8 @@ class CodeTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/CODE.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCodeArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerCodeArray')] public function testCodeArray(array $expectedResult, string $array): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/DollarTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/DollarTest.php index c383285fd..27afb3a30 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/DollarTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/DollarTest.php @@ -5,10 +5,11 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; +use PHPUnit\Framework\Attributes\DataProvider; class DollarTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerDOLLAR')] + #[DataProvider('providerDOLLAR')] public function testDOLLAR(mixed $expectedResult, mixed $amount = 'omitted', mixed $decimals = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -32,7 +33,8 @@ class DollarTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/DOLLAR.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerDollarArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerDollarArray')] public function testDollarArray(array $expectedResult, string $argument1, string $argument2): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ExactTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ExactTest.php index 9f3a15f63..94f804542 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ExactTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ExactTest.php @@ -5,10 +5,11 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; +use PHPUnit\Framework\Attributes\DataProvider; class ExactTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerEXACT')] + #[DataProvider('providerEXACT')] public function testEXACT(mixed $expectedResult, mixed $string1 = 'omitted', mixed $string2 = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -32,7 +33,8 @@ class ExactTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/EXACT.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerExactArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerExactArray')] public function testExactArray(array $expectedResult, string $argument1, string $argument2): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FindTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FindTest.php index 5497f69c9..e928bea4d 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FindTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FindTest.php @@ -5,10 +5,11 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; +use PHPUnit\Framework\Attributes\DataProvider; class FindTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerFIND')] + #[DataProvider('providerFIND')] public function testFIND(mixed $expectedResult, mixed $string1 = 'omitted', mixed $string2 = 'omitted', mixed $start = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -37,7 +38,8 @@ class FindTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/FIND.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerFindArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerFindArray')] public function testFindArray(array $expectedResult, string $argument1, string $argument2): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FixedTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FixedTest.php index a9ad67712..039ae8e26 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FixedTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/FixedTest.php @@ -5,10 +5,11 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; +use PHPUnit\Framework\Attributes\DataProvider; class FixedTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerFIXED')] + #[DataProvider('providerFIXED')] public function testFIXED(mixed $expectedResult, mixed $number = 'omitted', mixed $decimals = 'omitted', mixed $noCommas = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -37,7 +38,8 @@ class FixedTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/FIXED.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerFixedArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerFixedArray')] public function testFixedArray(array $expectedResult, string $argument1, string $argument2): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LeftTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LeftTest.php index f59e53311..2e4d38cc7 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LeftTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LeftTest.php @@ -7,6 +7,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Settings; +use PHPUnit\Framework\Attributes\DataProvider; class LeftTest extends AllSetupTeardown { @@ -14,7 +15,7 @@ class LeftTest extends AllSetupTeardown * @param mixed $str string from which to extract * @param mixed $cnt number of characters to extract */ - #[\PHPUnit\Framework\Attributes\DataProvider('providerLEFT')] + #[DataProvider('providerLEFT')] public function testLEFT(mixed $expectedResult, mixed $str = 'omitted', mixed $cnt = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -38,7 +39,7 @@ class LeftTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/LEFT.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerLocaleLEFT')] + #[DataProvider('providerLocaleLEFT')] public function testLowerWithLocaleBoolean(string $expectedResult, string $locale, mixed $value, mixed $characters): void { $newLocale = Settings::setLocale($locale); @@ -68,7 +69,7 @@ class LeftTest extends AllSetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCalculationTypeLEFTTrue')] + #[DataProvider('providerCalculationTypeLEFTTrue')] public function testCalculationTypeTrue(string $type, string $resultB1, string $resultB2): void { Functions::setCompatibilityMode($type); @@ -102,7 +103,7 @@ class LeftTest extends AllSetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCalculationTypeLEFTFalse')] + #[DataProvider('providerCalculationTypeLEFTFalse')] public function testCalculationTypeFalse(string $type, string $resultB1, string $resultB2): void { Functions::setCompatibilityMode($type); @@ -136,7 +137,7 @@ class LeftTest extends AllSetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCalculationTypeLEFTNull')] + #[DataProvider('providerCalculationTypeLEFTNull')] public function testCalculationTypeNull(string $type, string $resultB1, string $resultB2): void { Functions::setCompatibilityMode($type); @@ -169,7 +170,8 @@ class LeftTest extends AllSetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerLeftArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerLeftArray')] public function testLeftArray(array $expectedResult, string $argument1, string $argument2): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LenTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LenTest.php index 029a51010..356145187 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LenTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LenTest.php @@ -5,10 +5,11 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; +use PHPUnit\Framework\Attributes\DataProvider; class LenTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerLEN')] + #[DataProvider('providerLEN')] public function testLEN(mixed $expectedResult, mixed $str = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -28,7 +29,8 @@ class LenTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/LEN.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerLenArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerLenArray')] public function testLenArray(array $expectedResult, string $array): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LowerTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LowerTest.php index e254c07c9..b19a6f6bb 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LowerTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/LowerTest.php @@ -6,10 +6,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Settings; +use PHPUnit\Framework\Attributes\DataProvider; class LowerTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerLOWER')] + #[DataProvider('providerLOWER')] public function testLOWER(mixed $expectedResult, mixed $str = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -29,7 +30,7 @@ class LowerTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/LOWER.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerLocaleLOWER')] + #[DataProvider('providerLocaleLOWER')] public function testLowerWithLocaleBoolean(string $expectedResult, string $locale, mixed $value): void { $newLocale = Settings::setLocale($locale); @@ -57,7 +58,8 @@ class LowerTest extends AllSetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerLowerArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerLowerArray')] public function testLowerArray(array $expectedResult, string $array): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/MidTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/MidTest.php index 2b36d8cf4..463f4f13a 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/MidTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/MidTest.php @@ -7,6 +7,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Settings; +use PHPUnit\Framework\Attributes\DataProvider; class MidTest extends AllSetupTeardown { @@ -15,7 +16,7 @@ class MidTest extends AllSetupTeardown * @param mixed $start position at which to start * @param mixed $cnt number of characters to extract */ - #[\PHPUnit\Framework\Attributes\DataProvider('providerMID')] + #[DataProvider('providerMID')] public function testMID(mixed $expectedResult, mixed $str = 'omitted', mixed $start = 'omitted', mixed $cnt = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -44,7 +45,7 @@ class MidTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/MID.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerLocaleMID')] + #[DataProvider('providerLocaleMID')] public function testMiddleWithLocaleBoolean(string $expectedResult, string $locale, mixed $value, mixed $offset, mixed $characters): void { $newLocale = Settings::setLocale($locale); @@ -75,7 +76,7 @@ class MidTest extends AllSetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCalculationTypeMIDTrue')] + #[DataProvider('providerCalculationTypeMIDTrue')] public function testCalculationTypeTrue(string $type, string $resultB1, string $resultB2, string $resultB3): void { Functions::setCompatibilityMode($type); @@ -114,7 +115,7 @@ class MidTest extends AllSetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCalculationTypeMIDFalse')] + #[DataProvider('providerCalculationTypeMIDFalse')] public function testCalculationTypeFalse(string $type, string $resultB1, string $resultB2): void { Functions::setCompatibilityMode($type); @@ -152,7 +153,7 @@ class MidTest extends AllSetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCalculationTypeMIDNull')] + #[DataProvider('providerCalculationTypeMIDNull')] public function testCalculationTypeNull(string $type, string $resultB1, string $resultB2, string $resultB3): void { Functions::setCompatibilityMode($type); @@ -190,7 +191,8 @@ class MidTest extends AllSetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerMidArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerMidArray')] public function testMidArray(array $expectedResult, string $argument1, string $argument2, string $argument3): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/NumberValueTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/NumberValueTest.php index 15afdcd63..088ad7b0d 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/NumberValueTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/NumberValueTest.php @@ -5,12 +5,13 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; +use PHPUnit\Framework\Attributes\DataProvider; class NumberValueTest extends AllSetupTeardown { const NV_PRECISION = 1.0E-8; - #[\PHPUnit\Framework\Attributes\DataProvider('providerNUMBERVALUE')] + #[DataProvider('providerNUMBERVALUE')] public function testNUMBERVALUE(mixed $expectedResult, mixed $number = 'omitted', mixed $decimal = 'omitted', mixed $group = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -39,7 +40,8 @@ class NumberValueTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/NUMBERVALUE.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerNumberValueArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerNumberValueArray')] public function testNumberValueArray(array $expectedResult, string $argument1, string $argument2, string $argument3): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ProperTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ProperTest.php index 3767f9118..43838ca2a 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ProperTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ProperTest.php @@ -6,10 +6,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Settings; +use PHPUnit\Framework\Attributes\DataProvider; class ProperTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerPROPER')] + #[DataProvider('providerPROPER')] public function testPROPER(mixed $expectedResult, mixed $str = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -29,7 +30,7 @@ class ProperTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/PROPER.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerLocaleLOWER')] + #[DataProvider('providerLocaleLOWER')] public function testLowerWithLocaleBoolean(string $expectedResult, string $locale, mixed $value): void { $newLocale = Settings::setLocale($locale); @@ -57,7 +58,8 @@ class ProperTest extends AllSetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerProperArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerProperArray')] public function testProperArray(array $expectedResult, string $array): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ReplaceTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ReplaceTest.php index 8478bb69b..a064ea814 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ReplaceTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ReplaceTest.php @@ -5,10 +5,11 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; +use PHPUnit\Framework\Attributes\DataProvider; class ReplaceTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerREPLACE')] + #[DataProvider('providerREPLACE')] public function testREPLACE(mixed $expectedResult, mixed $oldText = 'omitted', mixed $start = 'omitted', mixed $count = 'omitted', mixed $newText = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -43,7 +44,8 @@ class ReplaceTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/REPLACE.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerReplaceArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerReplaceArray')] public function testReplaceArray( array $expectedResult, string $oldText, diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ReptTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ReptTest.php index 3a04a346f..1977b90bb 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ReptTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ReptTest.php @@ -5,10 +5,11 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; +use PHPUnit\Framework\Attributes\DataProvider; class ReptTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerREPT')] + #[DataProvider('providerREPT')] public function testReptThroughEngine(mixed $expectedResult, mixed $val = 'omitted', mixed $rpt = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -32,7 +33,8 @@ class ReptTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/REPT.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerReptArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerReptArray')] public function testReptArray(array $expectedResult, string $argument1, string $argument2): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/RightTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/RightTest.php index 007ad28c2..7e127b9cc 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/RightTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/RightTest.php @@ -7,6 +7,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Calculation\Functions; use PhpOffice\PhpSpreadsheet\Settings; +use PHPUnit\Framework\Attributes\DataProvider; class RightTest extends AllSetupTeardown { @@ -14,7 +15,7 @@ class RightTest extends AllSetupTeardown * @param mixed $str string from which to extract * @param mixed $cnt number of characters to extract */ - #[\PHPUnit\Framework\Attributes\DataProvider('providerRIGHT')] + #[DataProvider('providerRIGHT')] public function testRIGHT(mixed $expectedResult, mixed $str = 'omitted', mixed $cnt = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -38,7 +39,7 @@ class RightTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/RIGHT.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerLocaleRIGHT')] + #[DataProvider('providerLocaleRIGHT')] public function testLowerWithLocaleBoolean(string $expectedResult, string $locale, mixed $value, mixed $characters): void { $newLocale = Settings::setLocale($locale); @@ -68,7 +69,7 @@ class RightTest extends AllSetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCalculationTypeRIGHTTrue')] + #[DataProvider('providerCalculationTypeRIGHTTrue')] public function testCalculationTypeTrue(string $type, string $resultB1, string $resultB2): void { Functions::setCompatibilityMode($type); @@ -102,7 +103,7 @@ class RightTest extends AllSetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCalculationTypeRIGHTFalse')] + #[DataProvider('providerCalculationTypeRIGHTFalse')] public function testCalculationTypeFalse(string $type, string $resultB1, string $resultB2): void { Functions::setCompatibilityMode($type); @@ -136,7 +137,7 @@ class RightTest extends AllSetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerCalculationTypeRIGHTNull')] + #[DataProvider('providerCalculationTypeRIGHTNull')] public function testCalculationTypeNull(string $type, string $resultB1, string $resultB2): void { Functions::setCompatibilityMode($type); @@ -169,7 +170,8 @@ class RightTest extends AllSetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerRightArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerRightArray')] public function testRightArray(array $expectedResult, string $argument1, string $argument2): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SearchTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SearchTest.php index 656762cb3..cdb36fc81 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SearchTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SearchTest.php @@ -5,10 +5,11 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; +use PHPUnit\Framework\Attributes\DataProvider; class SearchTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerSEARCH')] + #[DataProvider('providerSEARCH')] public function testSEARCH(mixed $expectedResult, mixed $findText = 'omitted', mixed $withinText = 'omitted', mixed $start = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -37,7 +38,8 @@ class SearchTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/SEARCH.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerSearchArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerSearchArray')] public function testSearchArray(array $expectedResult, string $argument1, string $argument2): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SubstituteTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SubstituteTest.php index 51bce11af..216aae1cc 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SubstituteTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/SubstituteTest.php @@ -5,10 +5,11 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; +use PHPUnit\Framework\Attributes\DataProvider; class SubstituteTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerSUBSTITUTE')] + #[DataProvider('providerSUBSTITUTE')] public function testSUBSTITUTE(mixed $expectedResult, mixed $text = 'omitted', mixed $oldText = 'omitted', mixed $newText = 'omitted', mixed $instance = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -43,7 +44,8 @@ class SubstituteTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/SUBSTITUTE.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerSubstituteArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerSubstituteArray')] public function testSubstituteArray(array $expectedResult, string $oldText, string $fromText, string $toText): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TTest.php index 46886d5bc..5e09eceda 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TTest.php @@ -5,10 +5,12 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; +use PHPUnit\Framework\Attributes\DataProvider; class TTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerT')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerT')] public function testT(mixed $expectedResult, mixed $value = 'no arguments'): void { $this->mightHaveException($expectedResult); @@ -27,7 +29,8 @@ class TTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/T.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerTArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerTArray')] public function testTArray(array $expectedResult, string $argument): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextAfterTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextAfterTest.php index ea3c38f8e..7d660f408 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextAfterTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextAfterTest.php @@ -4,9 +4,12 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; +use PHPUnit\Framework\Attributes\DataProvider; + class TextAfterTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerTEXTAFTER')] + /** @param array{0: string, 1: mixed[]|string, 2?: string, 3?: string, 4?: string} $arguments */ + #[DataProvider('providerTEXTAFTER')] public function testTextAfter(string $expectedResult, array $arguments): void { $text = $arguments[0]; diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextBeforeTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextBeforeTest.php index d49457317..e4d589b2a 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextBeforeTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextBeforeTest.php @@ -4,9 +4,12 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; +use PHPUnit\Framework\Attributes\DataProvider; + class TextBeforeTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerTEXTBEFORE')] + /** @param array{0: string, 1: mixed[]|string, 2?: string, 3?: string, 4?: string} $arguments */ + #[DataProvider('providerTEXTBEFORE')] public function testTextBefore(string $expectedResult, array $arguments): void { $text = $arguments[0]; diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextJoinTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextJoinTest.php index 6a23a1550..9b1d65b36 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextJoinTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextJoinTest.php @@ -5,10 +5,12 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; +use PHPUnit\Framework\Attributes\DataProvider; class TextJoinTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerTEXTJOIN')] + /** @param mixed[] $args */ + #[DataProvider('providerTEXTJOIN')] public function testTEXTJOIN(mixed $expectedResult, array $args): void { $this->mightHaveException($expectedResult); @@ -33,7 +35,8 @@ class TextJoinTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/TEXTJOIN.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerTextjoinArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerTextjoinArray')] public function testTextjoinArray(array $expectedResult, string $delimiter, string $blanks, string $texts): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextSplitTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextSplitTest.php index 9ac0c9465..ca19343bc 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextSplitTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextSplitTest.php @@ -6,9 +6,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; +use PHPUnit\Framework\Attributes\DataProvider; class TextSplitTest extends AllSetupTeardown { + /** @param mixed[] $argument */ private function setDelimiterArgument(array $argument, string $column): string { return '{' . $column . implode(',' . $column, range(1, count($argument))) . '}'; @@ -26,7 +28,11 @@ class TextSplitTest extends AllSetupTeardown } } - #[\PHPUnit\Framework\Attributes\DataProvider('providerTEXTSPLIT')] + /** + * @param mixed[] $expectedResult + * @param array{0: string, 1: mixed[]|string, 2: mixed[]|string, 3?: string, 4?: string, 5?: string} $arguments + */ + #[DataProvider('providerTEXTSPLIT')] public function testTextSplit(array $expectedResult, array $arguments): void { Calculation::getInstance($this->getSpreadsheet())->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextTest.php index 111d8cd9b..19e2b1721 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TextTest.php @@ -5,10 +5,11 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; +use PHPUnit\Framework\Attributes\DataProvider; class TextTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerTEXT')] + #[DataProvider('providerTEXT')] public function testTEXT(mixed $expectedResult, mixed $value = 'omitted', mixed $format = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -32,7 +33,8 @@ class TextTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/TEXT.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerTextArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerTextArray')] public function testTextArray(array $expectedResult, string $argument1, string $argument2): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TrimTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TrimTest.php index 32c10329b..89f12155d 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TrimTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/TrimTest.php @@ -5,10 +5,11 @@ declare(strict_types=1); namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; +use PHPUnit\Framework\Attributes\DataProvider; class TrimTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerTRIM')] + #[DataProvider('providerTRIM')] public function testTRIM(mixed $expectedResult, mixed $character = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -28,7 +29,8 @@ class TrimTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/TRIM.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerTrimArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerTrimArray')] public function testTrimArray(array $expectedResult, string $array): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/UpperTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/UpperTest.php index 9d6b2210e..e0e8937e0 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/UpperTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/UpperTest.php @@ -6,10 +6,11 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Settings; +use PHPUnit\Framework\Attributes\DataProvider; class UpperTest extends AllSetupTeardown { - #[\PHPUnit\Framework\Attributes\DataProvider('providerUPPER')] + #[DataProvider('providerUPPER')] public function testUPPER(mixed $expectedResult, mixed $str = 'omitted'): void { $this->mightHaveException($expectedResult); @@ -29,7 +30,7 @@ class UpperTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/UPPER.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerLocaleLOWER')] + #[DataProvider('providerLocaleLOWER')] public function testLowerWithLocaleBoolean(string $expectedResult, string $locale, mixed $value): void { $newLocale = Settings::setLocale($locale); @@ -57,7 +58,8 @@ class UpperTest extends AllSetupTeardown ]; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerUpperArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerUpperArray')] public function testUpperArray(array $expectedResult, string $array): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ValueTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ValueTest.php index 124df5278..a18bdf8e4 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ValueTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ValueTest.php @@ -6,6 +6,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; use PhpOffice\PhpSpreadsheet\Calculation\Calculation; use PhpOffice\PhpSpreadsheet\Shared\StringHelper; +use PHPUnit\Framework\Attributes\DataProvider; class ValueTest extends AllSetupTeardown { @@ -17,7 +18,7 @@ class ValueTest extends AllSetupTeardown StringHelper::setThousandsSeparator(null); } - #[\PHPUnit\Framework\Attributes\DataProvider('providerVALUE')] + #[DataProvider('providerVALUE')] public function testVALUE(mixed $expectedResult, mixed $value = 'omitted'): void { StringHelper::setDecimalSeparator('.'); @@ -41,7 +42,8 @@ class ValueTest extends AllSetupTeardown return require 'tests/data/Calculation/TextData/VALUE.php'; } - #[\PHPUnit\Framework\Attributes\DataProvider('providerValueArray')] + /** @param mixed[] $expectedResult */ + #[DataProvider('providerValueArray')] public function testValueArray(array $expectedResult, string $argument): void { $calculation = Calculation::getInstance(); diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/Web/WebServiceTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/Web/WebServiceTest.php index 812ad8a05..f38b19c81 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/Web/WebServiceTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/Web/WebServiceTest.php @@ -6,6 +6,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Web; use PhpOffice\PhpSpreadsheet\Settings; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; @@ -26,7 +27,8 @@ class WebServiceTest extends TestCase Settings::unsetHttpClient(); } - #[\PHPUnit\Framework\Attributes\DataProvider('providerWEBSERVICE')] + /** @param null|mixed[] $responseData */ + #[DataProvider('providerWEBSERVICE')] public function testWEBSERVICE(string $expectedResult, string $url, ?array $responseData): void { if (!empty($responseData)) {