Skip to content

Commit bab6fc4

Browse files
committed
More @param to native types
1 parent 4c2f380 commit bab6fc4

Some content is hidden

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

52 files changed

+98
-298
lines changed

phpstan-baseline.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,11 @@ parameters:
11751175
count: 1
11761176
path: src/PhpSpreadsheet/Chart/DataSeriesValues.php
11771177

1178+
-
1179+
message: "#^Argument of an invalid type array\\<int, \\(SimpleXMLElement\\|null\\)\\>\\|SimpleXMLElement\\|null supplied for foreach, only iterables are supported\\.$#"
1180+
count: 2
1181+
path: src/PhpSpreadsheet/Reader/Xlsx/ConditionalStyles.php
1182+
11781183
-
11791184
message: "#^Cannot access property \\$color on SimpleXMLElement\\|null\\.$#"
11801185
count: 2

src/PhpSpreadsheet/Calculation/Calculation.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5526,10 +5526,8 @@ private function getArgumentDefaultValue(ReflectionParameter $methodArgument): m
55265526

55275527
/**
55285528
* Add cell reference if needed while making sure that it is the last argument.
5529-
*
5530-
* @param array|string $functionCall
55315529
*/
5532-
private function addCellReference(array $args, bool $passCellReference, $functionCall, ?Cell $cell = null): array
5530+
private function addCellReference(array $args, bool $passCellReference, array|string $functionCall, ?Cell $cell = null): array
55335531
{
55345532
if ($passCellReference) {
55355533
if (is_array($functionCall)) {

src/PhpSpreadsheet/Calculation/Database/DatabaseAbstract.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88

99
abstract class DatabaseAbstract
1010
{
11-
/**
12-
* @param null|int|string $field
13-
*/
14-
abstract public static function evaluate(array $database, $field, array $criteria): null|float|int|string;
11+
abstract public static function evaluate(array $database, null|int|string $field, array $criteria): null|float|int|string;
1512

1613
/**
1714
* fieldExtract.

src/PhpSpreadsheet/Calculation/DateTimeExcel/Difference.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ class Difference
2222
* @param mixed $endDate Excel date serial value, PHP date/time stamp, PHP DateTime object
2323
* or a standard date string
2424
* Or can be an array of date values
25-
* @param array|string $unit
26-
* Or can be an array of unit values
25+
* @param array|string $unit Or can be an array of unit values
2726
*
2827
* @return array|int|string Interval between the dates
2928
* If an array of values is passed for the $startDate or $endDays,arguments, then the returned result
@@ -80,10 +79,8 @@ private static function initialDiff(float $startDate, float $endDate): float
8079

8180
/**
8281
* Decide whether it's time to set retVal.
83-
*
84-
* @param bool|int $retVal
8582
*/
86-
private static function replaceRetValue($retVal, string $unit, string $compare): null|bool|int
83+
private static function replaceRetValue(bool|int $retVal, string $unit, string $compare): null|bool|int
8784
{
8885
if ($retVal !== false || $unit !== $compare) {
8986
return $retVal;

src/PhpSpreadsheet/Calculation/DateTimeExcel/Helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public static function dateParseSucceeded(array $dateArray): bool
275275
*
276276
* @param array|false $dateArray
277277
*/
278-
private static function forceArray($dateArray): array
278+
private static function forceArray(array|bool $dateArray): array
279279
{
280280
return is_array($dateArray) ? $dateArray : ['error_count' => 1];
281281
}

src/PhpSpreadsheet/Calculation/Engineering/BitWise.php

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ class BitWise
1515
/**
1616
* Split a number into upper and lower portions for full 32-bit support.
1717
*
18-
* @param float|int $number
19-
*
2018
* @return int[]
2119
*/
22-
private static function splitNumber($number): array
20+
private static function splitNumber(float|int $number): array
2321
{
2422
return [(int) floor($number / self::SPLIT_DIVISOR), (int) fmod($number, self::SPLIT_DIVISOR)];
2523
}
@@ -32,15 +30,13 @@ private static function splitNumber($number): array
3230
* Excel Function:
3331
* BITAND(number1, number2)
3432
*
35-
* @param array|int $number1
36-
* Or can be an array of values
37-
* @param array|int $number2
38-
* Or can be an array of values
33+
* @param null|array|bool|float|int|string $number1 Or can be an array of values
34+
* @param null|array|bool|float|int|string $number2 Or can be an array of values
3935
*
4036
* @return array|int|string If an array of numbers is passed as an argument, then the returned result will also be an array
4137
* with the same dimensions
4238
*/
43-
public static function BITAND($number1, $number2): array|string|int
39+
public static function BITAND(null|array|bool|float|int|string $number1, null|array|bool|float|int|string $number2): array|string|int
4440
{
4541
if (is_array($number1) || is_array($number2)) {
4642
return self::evaluateArrayArguments([self::class, __FUNCTION__], $number1, $number2);
@@ -66,15 +62,13 @@ public static function BITAND($number1, $number2): array|string|int
6662
* Excel Function:
6763
* BITOR(number1, number2)
6864
*
69-
* @param array|int $number1
70-
* Or can be an array of values
71-
* @param array|int $number2
72-
* Or can be an array of values
65+
* @param null|array|bool|float|int|string $number1 Or can be an array of values
66+
* @param null|array|bool|float|int|string $number2 Or can be an array of values
7367
*
7468
* @return array|int|string If an array of numbers is passed as an argument, then the returned result will also be an array
7569
* with the same dimensions
7670
*/
77-
public static function BITOR($number1, $number2): array|string|int
71+
public static function BITOR(null|array|bool|float|int|string $number1, null|array|bool|float|int|string $number2): array|string|int
7872
{
7973
if (is_array($number1) || is_array($number2)) {
8074
return self::evaluateArrayArguments([self::class, __FUNCTION__], $number1, $number2);
@@ -101,15 +95,13 @@ public static function BITOR($number1, $number2): array|string|int
10195
* Excel Function:
10296
* BITXOR(number1, number2)
10397
*
104-
* @param array|int $number1
105-
* Or can be an array of values
106-
* @param array|int $number2
107-
* Or can be an array of values
98+
* @param null|array|bool|float|int|string $number1 Or can be an array of values
99+
* @param null|array|bool|float|int|string $number2 Or can be an array of values
108100
*
109101
* @return array|int|string If an array of numbers is passed as an argument, then the returned result will also be an array
110102
* with the same dimensions
111103
*/
112-
public static function BITXOR($number1, $number2): array|string|int
104+
public static function BITXOR(null|array|bool|float|int|string $number1, null|array|bool|float|int|string $number2): array|string|int
113105
{
114106
if (is_array($number1) || is_array($number2)) {
115107
return self::evaluateArrayArguments([self::class, __FUNCTION__], $number1, $number2);
@@ -136,15 +128,13 @@ public static function BITXOR($number1, $number2): array|string|int
136128
* Excel Function:
137129
* BITLSHIFT(number, shift_amount)
138130
*
139-
* @param array|int $number
140-
* Or can be an array of values
141-
* @param array|int $shiftAmount
142-
* Or can be an array of values
131+
* @param null|array|bool|float|int|string $number Or can be an array of values
132+
* @param null|array|bool|float|int|string $shiftAmount Or can be an array of values
143133
*
144134
* @return array|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
145135
* with the same dimensions
146136
*/
147-
public static function BITLSHIFT($number, $shiftAmount): array|string|float
137+
public static function BITLSHIFT(null|array|bool|float|int|string $number, null|array|bool|float|int|string $shiftAmount): array|string|float
148138
{
149139
if (is_array($number) || is_array($shiftAmount)) {
150140
return self::evaluateArrayArguments([self::class, __FUNCTION__], $number, $shiftAmount);
@@ -173,15 +163,13 @@ public static function BITLSHIFT($number, $shiftAmount): array|string|float
173163
* Excel Function:
174164
* BITRSHIFT(number, shift_amount)
175165
*
176-
* @param array|int $number
177-
* Or can be an array of values
178-
* @param array|int $shiftAmount
179-
* Or can be an array of values
166+
* @param null|array|bool|float|int|string $number Or can be an array of values
167+
* @param null|array|bool|float|int|string $shiftAmount Or can be an array of values
180168
*
181169
* @return array|float|string If an array of numbers is passed as an argument, then the returned result will also be an array
182170
* with the same dimensions
183171
*/
184-
public static function BITRSHIFT($number, $shiftAmount): array|string|float
172+
public static function BITRSHIFT(null|array|bool|float|int|string $number, null|array|bool|float|int|string $shiftAmount): array|string|float
185173
{
186174
if (is_array($number) || is_array($shiftAmount)) {
187175
return self::evaluateArrayArguments([self::class, __FUNCTION__], $number, $shiftAmount);

src/PhpSpreadsheet/Calculation/Engineering/Erf.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,8 @@ private static function makeFloat(mixed $value): float
8282

8383
/**
8484
* Method to calculate the erf value.
85-
*
86-
* @param float|int|string $value
8785
*/
88-
public static function erfValue($value): float
86+
public static function erfValue(float|int|string $value): float
8987
{
9088
$value = (float) $value;
9189
if (abs($value) > 2.2) {

src/PhpSpreadsheet/Calculation/Financial/CashFlow/CashFlowValidations.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99

1010
class CashFlowValidations extends FinancialValidations
1111
{
12-
/**
13-
* @param mixed $rate
14-
*/
15-
public static function validateRate($rate): float
12+
public static function validateRate(mixed $rate): float
1613
{
1714
$rate = self::validateFloat($rate);
1815

src/PhpSpreadsheet/Calculation/Functions.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,11 @@ private static function operandSpecialHandling(mixed $operand): mixed
200200
/**
201201
* Convert a multi-dimensional array to a simple 1-dimensional array.
202202
*
203-
* @param array|mixed $array Array to be flattened
203+
* @param mixed $array Array to be flattened
204204
*
205205
* @return array Flattened array
206206
*/
207-
public static function flattenArray($array): array
207+
public static function flattenArray(mixed $array): array
208208
{
209209
if (!is_array($array)) {
210210
return (array) $array;

src/PhpSpreadsheet/Calculation/LookupRef/Indirect.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ private static function a1Format(mixed $a1fmt): bool
3434

3535
/**
3636
* Convert cellAddress to string, verify not null string.
37-
*
38-
* @param array|string $cellAddress
3937
*/
40-
private static function validateAddress($cellAddress): string
38+
private static function validateAddress(array|string|null $cellAddress): string
4139
{
4240
$cellAddress = Functions::flattenSingleValue($cellAddress);
4341
if (!is_string($cellAddress) || !$cellAddress) {

src/PhpSpreadsheet/Calculation/MathTrig/Helpers.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ public static function validateNumericNullBool(mixed $number): int|float
3939

4040
/**
4141
* Validate numeric, but allow substitute for null.
42-
*
43-
* @param null|float|int $substitute
4442
*/
45-
public static function validateNumericNullSubstitution(mixed $number, $substitute): float|int
43+
public static function validateNumericNullSubstitution(mixed $number, null|float|int $substitute): float|int
4644
{
4745
$number = Functions::flattenSingleValue($number);
4846
if ($number === null && $substitute !== null) {
@@ -57,10 +55,8 @@ public static function validateNumericNullSubstitution(mixed $number, $substitut
5755

5856
/**
5957
* Confirm number >= 0.
60-
*
61-
* @param float|int $number
6258
*/
63-
public static function validateNotNegative($number, ?string $except = null): void
59+
public static function validateNotNegative(float|int $number, ?string $except = null): void
6460
{
6561
if ($number >= 0) {
6662
return;
@@ -71,10 +67,8 @@ public static function validateNotNegative($number, ?string $except = null): voi
7167

7268
/**
7369
* Confirm number > 0.
74-
*
75-
* @param float|int $number
7670
*/
77-
public static function validatePositive($number, ?string $except = null): void
71+
public static function validatePositive(float|int $number, ?string $except = null): void
7872
{
7973
if ($number > 0) {
8074
return;
@@ -85,10 +79,8 @@ public static function validatePositive($number, ?string $except = null): void
8579

8680
/**
8781
* Confirm number != 0.
88-
*
89-
* @param float|int $number
9082
*/
91-
public static function validateNotZero($number): void
83+
public static function validateNotZero(float|int $number): void
9284
{
9385
if ($number) {
9486
return;

src/PhpSpreadsheet/Calculation/MathTrig/Operations.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,14 @@ public static function mod(mixed $dividend, mixed $divisor): array|string|float
5252
*
5353
* Computes x raised to the power y.
5454
*
55-
* @param array|float|int $x
56-
* Or can be an array of values
57-
* @param array|float|int $y
58-
* Or can be an array of values
55+
* @param array|float|int|string $x Or can be an array of values
56+
* @param array|float|int|string $y Or can be an array of values
5957
*
6058
* @return array|float|int|string The result, or a string containing an error
6159
* If an array of numbers is passed as an argument, then the returned result will also be an array
6260
* with the same dimensions
6361
*/
64-
public static function power($x, $y)
62+
public static function power(array|float|int|string $x, array|float|int|string $y): array|float|int|string
6563
{
6664
if (is_array($x) || is_array($y)) {
6765
return self::evaluateArrayArguments([self::class, __FUNCTION__], $x, $y);

src/PhpSpreadsheet/Calculation/MathTrig/Trunc.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,14 @@ class Trunc
1414
*
1515
* Truncates value to the number of fractional digits by number_digits.
1616
*
17-
* @param array|float $value
18-
* Or can be an array of values
19-
* @param array|int $digits
20-
* Or can be an array of values
17+
* @param array|float $value Or can be an array of values
18+
* @param array|int $digits Or can be an array of values
2119
*
2220
* @return array|float|string Truncated value, or a string containing an error
2321
* If an array of numbers is passed as an argument, then the returned result will also be an array
2422
* with the same dimensions
2523
*/
26-
public static function evaluate($value = 0, $digits = 0)
24+
public static function evaluate(array|float|string|null $value = 0, array|int|string $digits = 0): array|float|string
2725
{
2826
if (is_array($value) || is_array($digits)) {
2927
return self::evaluateArrayArguments([self::class, __FUNCTION__], $value, $digits);

src/PhpSpreadsheet/Calculation/Statistical/Distributions/StandardNormal.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ public static function inverse(mixed $value)
8787
* Calculates the probability that a member of a standard normal population will fall between
8888
* the mean and z standard deviations from the mean.
8989
*
90-
* @param mixed $value
91-
* Or can be an array of values
90+
* @param mixed $value Or can be an array of values
9291
*
9392
* @return array|float|string The result, or a string containing an error
9493
* If an array of numbers is passed as an argument, then the returned result will also be an array

src/PhpSpreadsheet/Chart/Axis.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,6 @@ public function setAxisType(string $type): self
207207

208208
/**
209209
* Set Fill Property.
210-
*
211-
* @param ?int $alpha
212210
*/
213211
public function setFillParameters(?string $color, ?int $alpha = null, ?string $AlphaType = ChartColor::EXCEL_COLOR_TYPE_RGB): void
214212
{

src/PhpSpreadsheet/Chart/Chart.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,6 @@ public function setTopLeftCell(string $cellAddress): static
398398
/**
399399
* Set the offset position within the Top Left cell for the chart.
400400
*
401-
* @param ?int $xOffset
402-
* @param ?int $yOffset
403-
*
404401
* @return $this
405402
*/
406403
public function setTopLeftOffset(?int $xOffset, ?int $yOffset): static
@@ -514,9 +511,6 @@ public function getBottomRightCell(): string
514511
/**
515512
* Set the offset position within the Bottom Right cell for the chart.
516513
*
517-
* @param ?int $xOffset
518-
* @param ?int $yOffset
519-
*
520514
* @return $this
521515
*/
522516
public function setBottomRightOffset(?int $xOffset, ?int $yOffset): static

src/PhpSpreadsheet/Chart/ChartColor.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ public function setBrightness(?int $brightness): self
8181
return $this;
8282
}
8383

84-
/**
85-
* @param null|float|int|string $alpha
86-
* @param null|float|int|string $brightness
87-
*/
88-
public function setColorProperties(?string $color, $alpha = null, ?string $type = null, $brightness = null): self
84+
public function setColorProperties(?string $color, null|float|int|string $alpha = null, ?string $type = null, null|float|int|string $brightness = null): self
8985
{
9086
if (empty($type) && !empty($color)) {
9187
if (str_starts_with($color, '*')) {
@@ -157,10 +153,7 @@ public static function alphaToXml(int $alpha): string
157153
return (string) (100 - $alpha) . '000';
158154
}
159155

160-
/**
161-
* @param float|int|string $alpha
162-
*/
163-
public static function alphaFromXml($alpha): int
156+
public static function alphaFromXml(float|int|string $alpha): int
164157
{
165158
return 100 - ((int) $alpha / 1000);
166159
}

src/PhpSpreadsheet/Chart/DataSeriesValues.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ public function getDataSource(): ?string
147147
/**
148148
* Set Series Data Source (formula).
149149
*
150-
* @param ?string $dataSource
151-
*
152150
* @return $this
153151
*/
154152
public function setDataSource(?string $dataSource): static
@@ -357,11 +355,9 @@ public function getLineWidth(): null|float|int
357355
/**
358356
* Set line width for the series.
359357
*
360-
* @param null|float|int $width
361-
*
362358
* @return $this
363359
*/
364-
public function setLineWidth($width): static
360+
public function setLineWidth(null|float|int $width): static
365361
{
366362
$this->lineStyleProperties['width'] = $width;
367363

0 commit comments

Comments
 (0)