mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-03 05:57:46 +00:00
Phpstan Level 9 - Part 7 of Many: Functions, LookupRef
This commit is contained in:
@@ -1,155 +1,5 @@
|
||||
parameters:
|
||||
ignoreErrors:
|
||||
-
|
||||
message: '#^Binary operation "\." between ''\='' and mixed results in an error\.$#'
|
||||
identifier: binaryOp.invalid
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/Functions.php
|
||||
|
||||
-
|
||||
message: '#^Binary operation "\." between string and mixed results in an error\.$#'
|
||||
identifier: binaryOp.invalid
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/Functions.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$dateValue of static method PhpOffice\\PhpSpreadsheet\\Shared\\Date\:\:stringToExcel\(\) expects string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/Functions.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$haystack of function substr_count expects string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 3
|
||||
path: src/PhpSpreadsheet/Calculation/Functions.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$string of function rtrim expects string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/Functions.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$string of function strtoupper expects string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 3
|
||||
path: src/PhpSpreadsheet/Calculation/Functions.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$string of function trim expects string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 2
|
||||
path: src/PhpSpreadsheet/Calculation/Functions.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#2 \$subject of function preg_match expects string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 2
|
||||
path: src/PhpSpreadsheet/Calculation/Functions.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#3 \$subject of function preg_replace expects array\<float\|int\|string\>\|string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/Functions.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#3 \$subject of function str_replace expects array\<string\>\|string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/Functions.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$row of static method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\Address\:\:formatAsA1\(\) expects int, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/Address.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$row of static method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\Address\:\:formatAsR1C1\(\) expects int, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/Address.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$sheetName of static method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\Address\:\:sheetName\(\) expects string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/Address.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#2 \$column of static method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\Address\:\:formatAsA1\(\) expects int, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/Address.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#2 \$column of static method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\Address\:\:formatAsR1C1\(\) expects int, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/Address.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#3 \$relativity of static method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\Address\:\:formatAsA1\(\) expects int, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/Address.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#3 \$relativity of static method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\Address\:\:formatAsR1C1\(\) expects int, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/Address.php
|
||||
|
||||
-
|
||||
message: '#^Cannot use \+\+ on mixed\.$#'
|
||||
identifier: preInc.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/ExcelMatch.php
|
||||
|
||||
-
|
||||
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\Formula\:\:text\(\) should return string but returns mixed\.$#'
|
||||
identifier: return.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/Formula.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$coordinate of method PhpOffice\\PhpSpreadsheet\\Worksheet\\Worksheet\:\:cellExists\(\) expects array\{int, int\}\|PhpOffice\\PhpSpreadsheet\\Cell\\CellAddress\|string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/Formula.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$coordinate of method PhpOffice\\PhpSpreadsheet\\Worksheet\\Worksheet\:\:getCell\(\) expects array\{int, int\}\|PhpOffice\\PhpSpreadsheet\\Cell\\CellAddress\|string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 2
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/Formula.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#2 \$subject of function preg_match expects string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/Formula.php
|
||||
|
||||
-
|
||||
message: '#^Cannot cast mixed to string\.$#'
|
||||
identifier: cast.string
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/HLookup.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$lookupArray of static method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\HLookup\:\:convertLiteralArray\(\) expects array, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/LookupRef/HLookup.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/HLookup.php
|
||||
|
||||
-
|
||||
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\LookupRef\\Hyperlink\:\:set\(\) should return string but returns mixed\.$#'
|
||||
identifier: return.type
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
||||
|
||||
class Functions
|
||||
{
|
||||
@@ -130,16 +131,22 @@ class Functions
|
||||
|
||||
public static function isMatrixValue(mixed $idx): bool
|
||||
{
|
||||
$idx = StringHelper::convertToString($idx);
|
||||
|
||||
return (substr_count($idx, '.') <= 1) || (preg_match('/\.[A-Z]/', $idx) > 0);
|
||||
}
|
||||
|
||||
public static function isValue(mixed $idx): bool
|
||||
{
|
||||
$idx = StringHelper::convertToString($idx);
|
||||
|
||||
return substr_count($idx, '.') === 0;
|
||||
}
|
||||
|
||||
public static function isCellValue(mixed $idx): bool
|
||||
{
|
||||
$idx = StringHelper::convertToString($idx);
|
||||
|
||||
return substr_count($idx, '.') > 1;
|
||||
}
|
||||
|
||||
@@ -154,7 +161,8 @@ class Functions
|
||||
$condition = self::operandSpecialHandling($condition);
|
||||
if (is_bool($condition)) {
|
||||
return '=' . ($condition ? 'TRUE' : 'FALSE');
|
||||
} elseif (!is_numeric($condition)) {
|
||||
}
|
||||
if (!is_numeric($condition)) {
|
||||
if ($condition !== '""') { // Not an empty string
|
||||
// Escape any quotes in the string value
|
||||
$condition = (string) preg_replace('/"/ui', '""', $condition);
|
||||
@@ -162,29 +170,32 @@ class Functions
|
||||
$condition = Calculation::wrapResult(strtoupper($condition));
|
||||
}
|
||||
|
||||
return str_replace('""""', '""', '=' . $condition);
|
||||
return str_replace('""""', '""', '=' . StringHelper::convertToString($condition));
|
||||
}
|
||||
$operator = $operand = '';
|
||||
if (1 === preg_match('/(=|<[>=]?|>=?)(.*)/', $condition, $matches)) {
|
||||
[, $operator, $operand] = $matches;
|
||||
}
|
||||
|
||||
$operand = self::operandSpecialHandling($operand);
|
||||
$operand = (string) self::operandSpecialHandling($operand);
|
||||
if (is_numeric(trim($operand, '"'))) {
|
||||
$operand = trim($operand, '"');
|
||||
} elseif (!is_numeric($operand) && $operand !== 'FALSE' && $operand !== 'TRUE') {
|
||||
$operand = str_replace('"', '""', $operand);
|
||||
$operand = Calculation::wrapResult(strtoupper($operand));
|
||||
$operand = StringHelper::convertToString($operand);
|
||||
}
|
||||
|
||||
return str_replace('""""', '""', $operator . $operand);
|
||||
}
|
||||
|
||||
private static function operandSpecialHandling(mixed $operand): mixed
|
||||
private static function operandSpecialHandling(mixed $operand): bool|float|int|string
|
||||
{
|
||||
if (is_numeric($operand) || is_bool($operand)) {
|
||||
return $operand;
|
||||
} elseif (strtoupper($operand) === Calculation::getTRUE() || strtoupper($operand) === Calculation::getFALSE()) {
|
||||
}
|
||||
$operand = StringHelper::convertToString($operand);
|
||||
if (strtoupper($operand) === Calculation::getTRUE() || strtoupper($operand) === Calculation::getFALSE()) {
|
||||
return strtoupper($operand);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\ArrayEnabled;
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\AddressHelper;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
|
||||
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
||||
|
||||
class Address
|
||||
{
|
||||
@@ -63,14 +64,16 @@ class Address
|
||||
);
|
||||
}
|
||||
|
||||
$relativity = $relativity ?? 1;
|
||||
$relativity = ($relativity === null) ? 1 : (int) StringHelper::convertToString($relativity);
|
||||
$referenceStyle = $referenceStyle ?? true;
|
||||
$row = (int) StringHelper::convertToString($row);
|
||||
$column = (int) StringHelper::convertToString($column);
|
||||
|
||||
if (($row < 1) || ($column < 1)) {
|
||||
return ExcelError::VALUE();
|
||||
}
|
||||
|
||||
$sheetName = self::sheetName($sheetName);
|
||||
$sheetName = self::sheetName(StringHelper::convertToString($sheetName));
|
||||
|
||||
if (is_int($referenceStyle)) {
|
||||
$referenceStyle = (bool) $referenceStyle;
|
||||
|
||||
@@ -70,7 +70,7 @@ class ExcelMatch
|
||||
};
|
||||
|
||||
if ($valueKey !== null) {
|
||||
return ++$valueKey;
|
||||
return ++$valueKey; //* @phpstan-ignore-line
|
||||
}
|
||||
|
||||
// Unsuccessful in finding a match, return #N/A error value
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
||||
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
||||
|
||||
class Formula
|
||||
{
|
||||
@@ -21,6 +22,7 @@ class Formula
|
||||
}
|
||||
|
||||
$worksheet = null;
|
||||
$cellReference = StringHelper::convertToString($cellReference);
|
||||
if (1 === preg_match('/^' . Calculation::CALCULATION_REGEXP_CELLREF . '$/i', $cellReference, $matches)) {
|
||||
$cellReference = $matches[6] . $matches[7];
|
||||
$worksheetName = trim($matches[3], "'");
|
||||
@@ -37,6 +39,6 @@ class Formula
|
||||
return ExcelError::NA();
|
||||
}
|
||||
|
||||
return $worksheet->getCell($cellReference)->getValue();
|
||||
return $worksheet->getCell($cellReference)->getValueString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,14 @@ class HLookup extends LookupBase
|
||||
* in the same column 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 row 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 row number in table_array from which the matching value must be returned.
|
||||
* The first row 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, $indexNumber, mixed $notExactMatch = true): mixed
|
||||
{
|
||||
if (is_array($lookupValue) || is_array($indexNumber)) {
|
||||
return self::evaluateArrayArgumentsIgnore([self::class, __FUNCTION__], 1, $lookupValue, $lookupArray, $indexNumber, $notExactMatch);
|
||||
@@ -66,7 +66,7 @@ class HLookup extends LookupBase
|
||||
*/
|
||||
private static function hLookupSearch(mixed $lookupValue, array $lookupArray, $column, bool $notExactMatch): ?int
|
||||
{
|
||||
$lookupLower = StringHelper::strToLower((string) $lookupValue);
|
||||
$lookupLower = StringHelper::strToLower(StringHelper::convertToString($lookupValue));
|
||||
|
||||
$rowNumber = null;
|
||||
foreach ($lookupArray[$column] as $rowKey => $rowData) {
|
||||
|
||||
Reference in New Issue
Block a user