mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-04 22:50:27 +00:00
Merge pull request #4428 from oleibman/stan2lv908
Phpstan Level 9 - Part 8 of Many - TextData
This commit is contained in:
@@ -269,117 +269,3 @@ parameters:
|
||||
identifier: argument.type
|
||||
count: 9
|
||||
path: src/PhpSpreadsheet/Calculation/Statistical/Trends.php
|
||||
|
||||
-
|
||||
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\TextData\\CharacterConvert\:\:unicodeToOrd\(\) should return int but returns mixed\.$#'
|
||||
identifier: return.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/TextData/CharacterConvert.php
|
||||
|
||||
-
|
||||
message: '#^Binary operation "\." between mixed and mixed results in an error\.$#'
|
||||
identifier: binaryOp.invalid
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/TextData/Concatenate.php
|
||||
|
||||
-
|
||||
message: '#^Cannot cast mixed to string\.$#'
|
||||
identifier: cast.string
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/TextData/Concatenate.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$ignoreEmpty of static method PhpOffice\\PhpSpreadsheet\\Calculation\\TextData\\Concatenate\:\:evaluateTextJoinArray\(\) expects bool, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/TextData/Concatenate.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$separator of function implode expects array\|string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/TextData/Concatenate.php
|
||||
|
||||
-
|
||||
message: '#^Cannot cast mixed to int\.$#'
|
||||
identifier: cast.int
|
||||
count: 6
|
||||
path: src/PhpSpreadsheet/Calculation/TextData/Extract.php
|
||||
|
||||
-
|
||||
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\TextData\\Extract\:\:validateTextBeforeAfter\(\) should return array\|string but returns mixed\.$#'
|
||||
identifier: return.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/TextData/Extract.php
|
||||
|
||||
-
|
||||
message: '#^Cannot cast mixed to string\.$#'
|
||||
identifier: cast.string
|
||||
count: 3
|
||||
path: src/PhpSpreadsheet/Calculation/TextData/Format.php
|
||||
|
||||
-
|
||||
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\TextData\\Format\:\:VALUE\(\) should return array\|DateTimeInterface\|float\|int\|string but returns mixed\.$#'
|
||||
identifier: return.type
|
||||
count: 2
|
||||
path: src/PhpSpreadsheet/Calculation/TextData/Format.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$dateValue of static method PhpOffice\\PhpSpreadsheet\\Calculation\\DateTimeExcel\\DateValue\:\:fromString\(\) expects array\|bool\|float\|int\|string\|null, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/TextData/Format.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$haystack of function str_contains expects string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/TextData/Format.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$haystack of function strpos expects string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/TextData/Format.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$string of function trim expects string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/TextData/Format.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#1 \$timeValue of static method PhpOffice\\PhpSpreadsheet\\Calculation\\DateTimeExcel\\TimeValue\:\:fromString\(\) expects array\|bool\|float\|int\|string\|null, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/TextData/Format.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#2 \$subject of static method Composer\\Pcre\\Preg\:\:matchAllWithOffsets\(\) expects string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/TextData/Format.php
|
||||
|
||||
-
|
||||
message: '#^Parameter \#3 \$subject of function str_replace expects array\<string\>\|string, mixed given\.$#'
|
||||
identifier: argument.type
|
||||
count: 2
|
||||
path: src/PhpSpreadsheet/Calculation/TextData/Format.php
|
||||
|
||||
-
|
||||
message: '#^Cannot cast mixed to int\.$#'
|
||||
identifier: cast.int
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/TextData/Helpers.php
|
||||
|
||||
-
|
||||
message: '#^Cannot cast mixed to string\.$#'
|
||||
identifier: cast.string
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/TextData/Helpers.php
|
||||
|
||||
-
|
||||
message: '#^Method PhpOffice\\PhpSpreadsheet\\Calculation\\TextData\\Replace\:\:executeSubstitution\(\) should return string but returns mixed\.$#'
|
||||
identifier: return.type
|
||||
count: 1
|
||||
path: src/PhpSpreadsheet/Calculation/TextData/Replace.php
|
||||
|
||||
@@ -81,6 +81,7 @@ class CharacterConvert
|
||||
$retVal = 0;
|
||||
$iconv = iconv('UTF-8', 'UCS-4LE', $character);
|
||||
if ($iconv !== false) {
|
||||
/** @var false|int[] */
|
||||
$result = unpack('V', $iconv);
|
||||
if (is_array($result) && isset($result[1])) {
|
||||
$retVal = $result[1];
|
||||
|
||||
@@ -78,8 +78,8 @@ class Concatenate
|
||||
return $operand2[$row][$column];
|
||||
}
|
||||
$operand1[$row][$column]
|
||||
= Calculation::boolToString($operand1[$row][$column])
|
||||
. Calculation::boolToString($operand2[$row][$column]);
|
||||
= StringHelper::convertToString($operand1[$row][$column], convertBool: true)
|
||||
. StringHelper::convertToString($operand2[$row][$column], convertBool: true);
|
||||
if (mb_strlen($operand1[$row][$column]) > DataType::MAX_STRING_LENGTH) {
|
||||
$operand1 = ExcelError::CALC();
|
||||
$errorFound = true;
|
||||
@@ -91,7 +91,7 @@ class Concatenate
|
||||
} elseif (ErrorValue::isError($operand2, true) === true) {
|
||||
$operand1 = (string) $operand2;
|
||||
} else {
|
||||
$operand1 .= (string) Calculation::boolToString($operand2);
|
||||
$operand1 .= StringHelper::convertToString($operand2, convertBool: true);
|
||||
if (mb_strlen($operand1) > DataType::MAX_STRING_LENGTH) {
|
||||
$operand1 = ExcelError::CALC();
|
||||
}
|
||||
@@ -103,9 +103,9 @@ class Concatenate
|
||||
/**
|
||||
* TEXTJOIN.
|
||||
*
|
||||
* @param mixed $delimiter The delimter to use between the joined arguments
|
||||
* @param null|string|string[] $delimiter The delimiter to use between the joined arguments
|
||||
* Or can be an array of values
|
||||
* @param mixed $ignoreEmpty true/false Flag indicating whether empty arguments should be skipped
|
||||
* @param null|bool|bool[] $ignoreEmpty true/false Flag indicating whether empty arguments should be skipped
|
||||
* Or can be an array of values
|
||||
* @param mixed $args The values to join
|
||||
*
|
||||
@@ -113,7 +113,7 @@ class Concatenate
|
||||
* 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
|
||||
*/
|
||||
public static function TEXTJOIN(mixed $delimiter = '', mixed $ignoreEmpty = true, mixed ...$args): array|string
|
||||
public static function TEXTJOIN($delimiter = '', $ignoreEmpty = true, mixed ...$args): array|string
|
||||
{
|
||||
if (is_array($delimiter) || is_array($ignoreEmpty)) {
|
||||
return self::evaluateArrayArgumentsSubset(
|
||||
@@ -127,6 +127,7 @@ class Concatenate
|
||||
|
||||
$delimiter ??= '';
|
||||
$ignoreEmpty ??= true;
|
||||
/** @var array */
|
||||
$aArgs = Functions::flattenArray($args);
|
||||
$returnValue = self::evaluateTextJoinArray($ignoreEmpty, $aArgs);
|
||||
|
||||
|
||||
@@ -139,9 +139,9 @@ class Extract
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
$instance = (int) $instance;
|
||||
$matchMode = (int) $matchMode;
|
||||
$matchEnd = (int) $matchEnd;
|
||||
$instance = (int) StringHelper::convertToString($instance);
|
||||
$matchMode = (int) StringHelper::convertToString($matchMode);
|
||||
$matchEnd = (int) StringHelper::convertToString($matchEnd);
|
||||
|
||||
$split = self::validateTextBeforeAfter($text, $delimiter, $instance, $matchMode, $matchEnd, $ifNotFound);
|
||||
if (is_string($split)) {
|
||||
@@ -203,9 +203,9 @@ class Extract
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
$instance = (int) $instance;
|
||||
$matchMode = (int) $matchMode;
|
||||
$matchEnd = (int) $matchEnd;
|
||||
$instance = (int) StringHelper::convertToString($instance);
|
||||
$matchMode = (int) StringHelper::convertToString($matchMode);
|
||||
$matchEnd = (int) StringHelper::convertToString($matchEnd);
|
||||
|
||||
$split = self::validateTextBeforeAfter($text, $delimiter, $instance, $matchMode, $matchEnd, $ifNotFound);
|
||||
if (is_string($split)) {
|
||||
@@ -234,7 +234,7 @@ class Extract
|
||||
$delimiter = self::buildDelimiter($delimiter);
|
||||
|
||||
if (preg_match('/' . $delimiter . "/{$flags}", $text) === 0 && $matchEnd === 0) {
|
||||
return $ifNotFound;
|
||||
return is_array($ifNotFound) ? $ifNotFound : StringHelper::convertToString($ifNotFound);
|
||||
}
|
||||
|
||||
$split = preg_split('/' . $delimiter . "/{$flags}", $text, 0, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
|
||||
|
||||
@@ -192,6 +192,7 @@ class Format
|
||||
return $e->getMessage();
|
||||
}
|
||||
if (!is_numeric($value)) {
|
||||
$value = StringHelper::convertToString($value);
|
||||
$numberValue = str_replace(
|
||||
StringHelper::getThousandsSeparator(),
|
||||
'',
|
||||
@@ -212,14 +213,14 @@ class Format
|
||||
if ($timeValue !== ExcelError::VALUE()) {
|
||||
Functions::setReturnDateType($dateSetting);
|
||||
|
||||
return $timeValue;
|
||||
return $timeValue; //* @phpstan-ignore-line
|
||||
}
|
||||
}
|
||||
$dateValue = Functions::scalar(DateTimeExcel\DateValue::fromString($value));
|
||||
if ($dateValue !== ExcelError::VALUE()) {
|
||||
Functions::setReturnDateType($dateSetting);
|
||||
|
||||
return $dateValue;
|
||||
return $dateValue; //* @phpstan-ignore-line
|
||||
}
|
||||
Functions::setReturnDateType($dateSetting);
|
||||
|
||||
@@ -250,23 +251,23 @@ class Format
|
||||
$value = $value->getPlainText();
|
||||
}
|
||||
if (is_string($value)) {
|
||||
$value = ($format === true) ? Calculation::wrapResult($value) : $value;
|
||||
$value = ($format === true) ? StringHelper::convertToString(Calculation::wrapResult($value)) : $value;
|
||||
$value = str_replace("\n", '', $value);
|
||||
} elseif (is_bool($value)) {
|
||||
$value = Calculation::getLocaleBoolean($value ? 'TRUE' : 'FALSE');
|
||||
}
|
||||
|
||||
return (string) $value;
|
||||
return StringHelper::convertToString($value);
|
||||
}
|
||||
|
||||
private static function getDecimalSeparator(mixed $decimalSeparator): string
|
||||
{
|
||||
return empty($decimalSeparator) ? StringHelper::getDecimalSeparator() : (string) $decimalSeparator;
|
||||
return empty($decimalSeparator) ? StringHelper::getDecimalSeparator() : StringHelper::convertToString($decimalSeparator);
|
||||
}
|
||||
|
||||
private static function getGroupSeparator(mixed $groupSeparator): string
|
||||
{
|
||||
return empty($groupSeparator) ? StringHelper::getThousandsSeparator() : (string) $groupSeparator;
|
||||
return empty($groupSeparator) ? StringHelper::getThousandsSeparator() : StringHelper::convertToString($groupSeparator);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -293,7 +294,9 @@ class Format
|
||||
return $e->getMessage();
|
||||
}
|
||||
|
||||
if (!is_numeric($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);
|
||||
if ($decimalPositions > 1) {
|
||||
return ExcelError::VALUE();
|
||||
|
||||
@@ -7,6 +7,7 @@ use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Information\ErrorValue;
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
||||
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
||||
|
||||
class Helpers
|
||||
{
|
||||
@@ -31,7 +32,7 @@ class Helpers
|
||||
throw new CalcExp($value);
|
||||
}
|
||||
|
||||
return (string) $value;
|
||||
return StringHelper::convertToString($value);
|
||||
}
|
||||
|
||||
public static function extractInt(mixed $value, int $minValue, int $gnumericNull = 0, bool $ooBoolOk = false): int
|
||||
@@ -87,6 +88,6 @@ class Helpers
|
||||
throw new CalcExp($value);
|
||||
}
|
||||
|
||||
return (int) $value;
|
||||
return (int) StringHelper::convertToString($value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +111,6 @@ class Replace
|
||||
--$instance;
|
||||
}
|
||||
|
||||
return Functions::scalar(self::REPLACE($text, ++$pos, StringHelper::countCharacters($fromText), $toText));
|
||||
return StringHelper::convertToString(Functions::scalar(self::REPLACE($text, ++$pos, StringHelper::countCharacters($fromText), $toText)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user