Skip to content

Commit 3e93d4d

Browse files
authored
Merge pull request #4463 from oleibman/stan1005
More Phpstan 10 Prep
2 parents 89343c8 + e53a04b commit 3e93d4d

File tree

94 files changed

+613
-242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+613
-242
lines changed

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
parameters:
2-
ignoreErrors: []
2+
ignoreErrors:

src/PhpSpreadsheet/Calculation/Calculation.php

Lines changed: 53 additions & 16 deletions
Large diffs are not rendered by default.

src/PhpSpreadsheet/Calculation/TextData/CaseConvert.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class CaseConvert
1818
* @param mixed $mixedCaseValue The string value to convert to lower case
1919
* Or can be an array of values
2020
*
21-
* @return array|string If an array of values is passed as the argument, then the returned result will also be an array
21+
* @return array<mixed>|string If an array of values is passed as the argument, then the returned result will also be an array
2222
* with the same dimensions
2323
*/
2424
public static function lower(mixed $mixedCaseValue): array|string
@@ -44,7 +44,7 @@ public static function lower(mixed $mixedCaseValue): array|string
4444
* @param mixed $mixedCaseValue The string value to convert to upper case
4545
* Or can be an array of values
4646
*
47-
* @return array|string If an array of values is passed as the argument, then the returned result will also be an array
47+
* @return array<mixed>|string If an array of values is passed as the argument, then the returned result will also be an array
4848
* with the same dimensions
4949
*/
5050
public static function upper(mixed $mixedCaseValue): array|string
@@ -70,7 +70,7 @@ public static function upper(mixed $mixedCaseValue): array|string
7070
* @param mixed $mixedCaseValue The string value to convert to title case
7171
* Or can be an array of values
7272
*
73-
* @return array|string If an array of values is passed as the argument, then the returned result will also be an array
73+
* @return array<mixed>|string If an array of values is passed as the argument, then the returned result will also be an array
7474
* with the same dimensions
7575
*/
7676
public static function proper(mixed $mixedCaseValue): array|string

src/PhpSpreadsheet/Calculation/TextData/CharacterConvert.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CharacterConvert
1717
* @param mixed $character Integer Value to convert to its character representation
1818
* Or can be an array of values
1919
*
20-
* @return array|string The character string
20+
* @return array<mixed>|string The character string
2121
* If an array of values is passed as the argument, then the returned result will also be an array
2222
* with the same dimensions
2323
*/
@@ -48,7 +48,7 @@ public static function character(mixed $character): array|string
4848
* @param mixed $characters String character to convert to its ASCII value
4949
* Or can be an array of values
5050
*
51-
* @return array|int|string A string if arguments are invalid
51+
* @return array<mixed>|int|string A string if arguments are invalid
5252
* If an array of values is passed as the argument, then the returned result will also be an array
5353
* with the same dimensions
5454
*/

src/PhpSpreadsheet/Calculation/TextData/Concatenate.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Concatenate
1717
/**
1818
* This implements the CONCAT function, *not* CONCATENATE.
1919
*
20-
* @param array $args
20+
* @param mixed[] $args
2121
*/
2222
public static function CONCATENATE(...$args): string
2323
{
@@ -47,7 +47,9 @@ public static function CONCATENATE(...$args): string
4747
/**
4848
* This implements the CONCATENATE function.
4949
*
50-
* @param array $args data to be concatenated
50+
* @param mixed[] $args data to be concatenated
51+
*
52+
* @return array<string>|string
5153
*/
5254
public static function actualCONCATENATE(...$args): array|string
5355
{
@@ -65,6 +67,12 @@ public static function actualCONCATENATE(...$args): array|string
6567
return $result;
6668
}
6769

70+
/**
71+
* @param array<string>|string $operand1
72+
* @param null|array<mixed>|bool|float|int|string $operand2
73+
*
74+
* @return array<string>|string
75+
*/
6876
private static function concatenate2Args(array|string $operand1, null|array|bool|float|int|string $operand2): array|string
6977
{
7078
if (is_array($operand1) || is_array($operand2)) {
@@ -74,9 +82,11 @@ private static function concatenate2Args(array|string $operand1, null|array|bool
7482
$errorFound = false;
7583
for ($row = 0; $row < $rows && !$errorFound; ++$row) {
7684
for ($column = 0; $column < $columns; ++$column) {
85+
/** @var string[][] $operand2 */
7786
if (ErrorValue::isError($operand2[$row][$column])) {
7887
return $operand2[$row][$column];
7988
}
89+
/** @var string[][] $operand1 */
8090
$operand1[$row][$column]
8191
= StringHelper::convertToString($operand1[$row][$column], convertBool: true)
8292
. StringHelper::convertToString($operand2[$row][$column], convertBool: true);
@@ -96,6 +106,7 @@ private static function concatenate2Args(array|string $operand1, null|array|bool
96106
$operand1 = ExcelError::CALC();
97107
}
98108
}
109+
/** @var array<string>|string $operand1 */
99110

100111
return $operand1;
101112
}
@@ -109,7 +120,7 @@ private static function concatenate2Args(array|string $operand1, null|array|bool
109120
* Or can be an array of values
110121
* @param mixed $args The values to join
111122
*
112-
* @return array|string The joined string
123+
* @return array<mixed>|string The joined string
113124
* If an array of values is passed for the $delimiter or $ignoreEmpty arguments, then the returned result
114125
* will also be an array with matching dimensions
115126
*/
@@ -127,7 +138,7 @@ public static function TEXTJOIN($delimiter = '', $ignoreEmpty = true, mixed ...$
127138

128139
$delimiter ??= '';
129140
$ignoreEmpty ??= true;
130-
/** @var array */
141+
/** @var mixed[] */
131142
$aArgs = Functions::flattenArray($args);
132143
$returnValue = self::evaluateTextJoinArray($ignoreEmpty, $aArgs);
133144

@@ -139,6 +150,7 @@ public static function TEXTJOIN($delimiter = '', $ignoreEmpty = true, mixed ...$
139150
return $returnValue;
140151
}
141152

153+
/** @param mixed[] $aArgs */
142154
private static function evaluateTextJoinArray(bool $ignoreEmpty, array &$aArgs): ?string
143155
{
144156
foreach ($aArgs as $key => &$arg) {
@@ -167,7 +179,7 @@ private static function evaluateTextJoinArray(bool $ignoreEmpty, array &$aArgs):
167179
* @param mixed $repeatCount The number of times the string value should be repeated
168180
* Or can be an array of values
169181
*
170-
* @return array|string The repeated string
182+
* @return array<mixed>|string The repeated string
171183
* If an array of values is passed for the $stringValue or $repeatCount arguments, then the returned result
172184
* will also be an array with matching dimensions
173185
*/

src/PhpSpreadsheet/Calculation/TextData/Extract.php

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Extract
2020
* @param mixed $chars The number of characters to extract (as an integer)
2121
* Or can be an array of values
2222
*
23-
* @return array|string The joined string
23+
* @return array<mixed>|string The joined string
2424
* If an array of values is passed for the $value or $chars arguments, then the returned result
2525
* will also be an array with matching dimensions
2626
*/
@@ -50,7 +50,7 @@ public static function left(mixed $value, mixed $chars = 1): array|string
5050
* @param mixed $chars The number of characters to extract (as an integer)
5151
* Or can be an array of values
5252
*
53-
* @return array|string The joined string
53+
* @return array<mixed>|string The joined string
5454
* If an array of values is passed for the $value, $start or $chars arguments, then the returned result
5555
* will also be an array with matching dimensions
5656
*/
@@ -79,7 +79,7 @@ public static function mid(mixed $value, mixed $start, mixed $chars): array|stri
7979
* @param mixed $chars The number of characters to extract (as an integer)
8080
* Or can be an array of values
8181
*
82-
* @return array|string The joined string
82+
* @return array<mixed>|string The joined string
8383
* If an array of values is passed for the $value or $chars arguments, then the returned result
8484
* will also be an array with matching dimensions
8585
*/
@@ -104,7 +104,7 @@ public static function right(mixed $value, mixed $chars = 1): array|string
104104
*
105105
* @param mixed $text the text that you're searching
106106
* Or can be an array of values
107-
* @param null|array|string $delimiter the text that marks the point before which you want to extract
107+
* @param null|array<string>|string $delimiter the text that marks the point before which you want to extract
108108
* Multiple delimiters can be passed as an array of string values
109109
* @param mixed $instance The instance of the delimiter after which you want to extract the text.
110110
* By default, this is the first instance (1).
@@ -118,11 +118,11 @@ public static function right(mixed $value, mixed $chars = 1): array|string
118118
* 0 - Don't match the delimiter against the end of the text.
119119
* 1 - Match the delimiter against the end of the text.
120120
* Or can be an array of values
121-
* @param mixed $ifNotFound value to return if no match is found
121+
* @param array<string>|bool|float|int|string $ifNotFound value to return if no match is found
122122
* The default is a #N/A Error
123123
* Or can be an array of values
124124
*
125-
* @return array|string the string extracted from text before the delimiter; or the $ifNotFound value
125+
* @return array<mixed>|string the string extracted from text before the delimiter; or the $ifNotFound value
126126
* If an array of values is passed for any of the arguments, then the returned result
127127
* will also be an array with matching dimensions
128128
*/
@@ -168,7 +168,7 @@ public static function before(mixed $text, $delimiter, mixed $instance = 1, mixe
168168
* TEXTAFTER.
169169
*
170170
* @param mixed $text the text that you're searching
171-
* @param null|array|string $delimiter the text that marks the point before which you want to extract
171+
* @param null|array<string>|string $delimiter the text that marks the point before which you want to extract
172172
* Multiple delimiters can be passed as an array of string values
173173
* @param mixed $instance The instance of the delimiter after which you want to extract the text.
174174
* By default, this is the first instance (1).
@@ -182,11 +182,11 @@ public static function before(mixed $text, $delimiter, mixed $instance = 1, mixe
182182
* 0 - Don't match the delimiter against the end of the text.
183183
* 1 - Match the delimiter against the end of the text.
184184
* Or can be an array of values
185-
* @param mixed $ifNotFound value to return if no match is found
185+
* @param array<string>|scalar $ifNotFound value to return if no match is found
186186
* The default is a #N/A Error
187187
* Or can be an array of values
188188
*
189-
* @return array|string the string extracted from text before the delimiter; or the $ifNotFound value
189+
* @return array<mixed>|string the string extracted from text before the delimiter; or the $ifNotFound value
190190
* If an array of values is passed for any of the arguments, then the returned result
191191
* will also be an array with matching dimensions
192192
*/
@@ -228,6 +228,12 @@ public static function after(mixed $text, $delimiter, mixed $instance = 1, mixed
228228
return implode('', $split);
229229
}
230230

231+
/**
232+
* @param null|array<string>|string $delimiter
233+
* @param array<string>|scalar $ifNotFound
234+
*
235+
* @return array<string>|string
236+
*/
231237
private static function validateTextBeforeAfter(string $text, null|array|string $delimiter, int $instance, int $matchMode, int $matchEnd, mixed $ifNotFound): array|string
232238
{
233239
$flags = self::matchFlags($matchMode);
@@ -256,7 +262,7 @@ private static function validateTextBeforeAfter(string $text, null|array|string
256262
}
257263

258264
/**
259-
* @param null|array|string $delimiter the text that marks the point before which you want to extract
265+
* @param null|array<string>|string $delimiter the text that marks the point before which you want to extract
260266
* Multiple delimiters can be passed as an array of string values
261267
*/
262268
private static function buildDelimiter($delimiter): string

src/PhpSpreadsheet/Calculation/TextData/Format.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Format
3434
* If you omit decimals, it is assumed to be 2
3535
* Or can be an array of values
3636
*
37-
* @return array|string If an array of values is passed for either of the arguments, then the returned result
37+
* @return array<mixed>|string If an array of values is passed for either of the arguments, then the returned result
3838
* will also be an array with matching dimensions
3939
*/
4040
public static function DOLLAR(mixed $value = 0, mixed $decimals = 2)
@@ -76,7 +76,7 @@ public static function DOLLAR(mixed $value = 0, mixed $decimals = 2)
7676
* @param mixed $noCommas Boolean value indicating whether the value should have thousands separators or not
7777
* Or can be an array of values
7878
*
79-
* @return array|string If an array of values is passed for either of the arguments, then the returned result
79+
* @return array<mixed>|string If an array of values is passed for either of the arguments, then the returned result
8080
* will also be an array with matching dimensions
8181
*/
8282
public static function FIXEDFORMAT(mixed $value, mixed $decimals = 2, mixed $noCommas = false): array|string
@@ -116,7 +116,7 @@ public static function FIXEDFORMAT(mixed $value, mixed $decimals = 2, mixed $noC
116116
* @param mixed $format A string with the Format mask that should be used
117117
* Or can be an array of values
118118
*
119-
* @return array|string If an array of values is passed for either of the arguments, then the returned result
119+
* @return array<mixed>|string If an array of values is passed for either of the arguments, then the returned result
120120
* will also be an array with matching dimensions
121121
*/
122122
public static function TEXTFORMAT(mixed $value, mixed $format): array|string
@@ -176,7 +176,7 @@ private static function convertValue(mixed $value, bool $spacesMeanZero = false)
176176
* @param mixed $value Value to check
177177
* Or can be an array of values
178178
*
179-
* @return array|DateTimeInterface|float|int|string A string if arguments are invalid
179+
* @return array<mixed>|DateTimeInterface|float|int|string A string if arguments are invalid
180180
* If an array of values is passed for the argument, then the returned result
181181
* will also be an array with matching dimensions
182182
*/
@@ -236,7 +236,7 @@ public static function VALUE(mixed $value = '')
236236
* @param mixed $value The value to format
237237
* Or can be an array of values
238238
*
239-
* @return array|string If an array of values is passed for either of the arguments, then the returned result
239+
* @return array<mixed>|string If an array of values is passed for either of the arguments, then the returned result
240240
* will also be an array with matching dimensions
241241
*/
242242
public static function valueToText(mixed $value, mixed $format = false): array|string
@@ -279,6 +279,8 @@ private static function getGroupSeparator(mixed $groupSeparator): string
279279
* Or can be an array of values
280280
* @param mixed $groupSeparator A string with the group/thousands separator to use, defaults to locale defined value
281281
* Or can be an array of values
282+
*
283+
* @return array<mixed>|float|string
282284
*/
283285
public static function NUMBERVALUE(mixed $value = '', mixed $decimalSeparator = null, mixed $groupSeparator = null): array|string|float
284286
{
@@ -294,7 +296,7 @@ public static function NUMBERVALUE(mixed $value = '', mixed $decimalSeparator =
294296
return $e->getMessage();
295297
}
296298

297-
/** @var null|array|scalar $value */
299+
/** @var null|array<scalar>|scalar $value */
298300
if (!is_array($value) && !is_numeric($value)) {
299301
$value = StringHelper::convertToString($value);
300302
$decimalPositions = Preg::matchAllWithOffsets('/' . preg_quote($decimalSeparator, '/') . '/', $value, $matches);

src/PhpSpreadsheet/Calculation/TextData/Replace.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Replace
2525
* @param mixed $newText String to replace in the defined position
2626
* Or can be an array of values
2727
*
28-
* @return array|string If an array of values is passed for either of the arguments, then the returned result
28+
* @return array<mixed>|string If an array of values is passed for either of the arguments, then the returned result
2929
* will also be an array with matching dimensions
3030
*/
3131
public static function replace(mixed $oldText, mixed $start, mixed $chars, mixed $newText): array|string
@@ -65,7 +65,7 @@ public static function replace(mixed $oldText, mixed $start, mixed $chars, mixed
6565
* @param mixed $instance Integer instance Number for the occurrence of frmText to change
6666
* Or can be an array of values
6767
*
68-
* @return array|string If an array of values is passed for either of the arguments, then the returned result
68+
* @return array<mixed>|string If an array of values is passed for either of the arguments, then the returned result
6969
* will also be an array with matching dimensions
7070
*/
7171
public static function substitute(mixed $text = '', mixed $fromText = '', mixed $toText = '', mixed $instance = null): array|string

src/PhpSpreadsheet/Calculation/TextData/Search.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Search
2121
* @param mixed $offset Integer offset within $haystack to start searching from
2222
* Or can be an array of values
2323
*
24-
* @return array|int|string The offset where the first occurrence of needle was found in the haystack
24+
* @return array<mixed>|int|string The offset where the first occurrence of needle was found in the haystack
2525
* If an array of values is passed for the $value or $chars arguments, then the returned result
2626
* will also be an array with matching dimensions
2727
*/
@@ -63,7 +63,7 @@ public static function sensitive(mixed $needle, mixed $haystack, mixed $offset =
6363
* @param mixed $offset Integer offset within $haystack to start searching from
6464
* Or can be an array of values
6565
*
66-
* @return array|int|string The offset where the first occurrence of needle was found in the haystack
66+
* @return array<mixed>|int|string The offset where the first occurrence of needle was found in the haystack
6767
* If an array of values is passed for the $value or $chars arguments, then the returned result
6868
* will also be an array with matching dimensions
6969
*/

0 commit comments

Comments
 (0)