Skip to content

Commit 9edc1b8

Browse files
authored
Fix: Improve reduce() signature to exclude null from return type when non-null initial value is passed (#35)
1 parent 70b4a54 commit 9edc1b8

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

phpstan-baseline.neon

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Parameter \\#1 \\$ of callable callable\\(TResult, TValue\\)\\: TResult expects TResult, TResult\\|null given\\.$#"
5+
count: 1
6+
path: src/iterable-functions.php
7+
8+
-
9+
message: "#^Function BenTools\\\\IterableFunctions\\\\iterable_reduce\\(\\) should return TResult but returns TResult\\|null\\.$#"
10+
count: 1
11+
path: src/iterable-functions.php
12+

phpstan.neon.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ parameters:
1010
- '~Method BenTools\\IterableFunctions\\IterableObject::map\(\) should return BenTools\\IterableFunctions\\IterableObject<TKey, TResult> but returns BenTools\\IterableFunctions\\IterableObject<int\|string, TResult>~'
1111

1212
- '~Function BenTools\\IterableFunctions\\iterable_map\(\) should return iterable<TKey, TResult> but returns array<TResult>\|BenTools\\IterableFunctions\\IterableObject<TKey, TResult>~'
13+
14+
includes:
15+
- phpstan-baseline.neon

src/iterable-functions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ function iterable_filter(iterable $iterable, ?callable $filter = null): iterable
9595
* Reduces an iterable.
9696
*
9797
* @param iterable<TValue> $iterable
98-
* @param callable(TResult|null, TValue):TResult $reduce
99-
* @param TResult|null $initial
98+
* @param TResult $initial
99+
* @param callable(TResult, TValue):TResult $reduce
100100
*
101-
* @return TResult|null
101+
* @return TResult
102102
*
103103
* @template TValue
104104
* @template TResult

0 commit comments

Comments
 (0)