Skip to content

Commit 56c1cd5

Browse files
authored
bump phpstan level to 5 (#108)
1 parent e9173fa commit 56c1cd5

File tree

10 files changed

+47
-25
lines changed

10 files changed

+47
-25
lines changed

phpstan.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ includes:
22
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
33
parameters:
44
phpVersion: 80100
5-
level: 4
5+
level: 5
66
paths:
77
- src
88
- tests

src/Collection/Map.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,30 @@ public function dropWhile(callable $predicate)
285285
return self::fromPointer($map);
286286
}
287287

288+
/**
289+
* @param callable(Tuple2<K, V>):bool $predicate
290+
*
291+
* @return Map<K,V>
292+
*/
293+
public function dropUntil(callable $predicate)
294+
{
295+
return parent::dropUntil($predicate);
296+
}
297+
298+
/**
299+
* @param callable(V): void $action
300+
*
301+
* @return Map<K,V>
302+
*/
303+
public function peek(callable $action)
304+
{
305+
if (!$this->isEmpty()) {
306+
$action($this->get()->get());
307+
}
308+
309+
return $this;
310+
}
311+
288312
/**
289313
* Take n next entries of map.
290314
*

tests/Collection/GenericListTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public function testListContainsAll(): void
221221
self::assertFalse(GenericList::ofAll([1, 2, 3])->containsAll(GenericList::ofAll([1, 2, 3, 4])));
222222
self::assertFalse(GenericList::ofAll([1, 2, 3])->containsAll(GenericList::ofAll([1, 2, 4])));
223223
self::assertFalse(GenericList::ofAll([1, 2, 3])->containsAll(GenericList::ofAll([1, 4])));
224-
self::assertFalse(GenericList::ofAll([1, 2, 3])->containsAll(GenericList::ofAll(['a'])));
224+
self::assertFalse(GenericList::ofAll([1, 2, 3])->containsAll(GenericList::ofAll([0])));
225225
}
226226

227227
public function testFlatMap(): void

tests/Collection/MapTest.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ public function testEmptyMapPeek(): void
9292
public function testMapPeek(): void
9393
{
9494
$counter = 0;
95-
Map::fromArray(['a' => 1])->peek(function (Option $head) use (&$counter) {$counter = $head->get(); });
95+
Map::fromArray(['a' => 1])->peek(function (int $head) use (&$counter) {$counter = $head; });
9696
self::assertEquals(1, $counter);
9797
}
9898

9999
public function testMapTake(): void
100100
{
101-
$map = Map::fromArray(['a' => 'apple', 'b' => 'banana', '42' => 'pear', 'd' => 'orange']);
101+
$map = Map::fromArray(['a' => 'apple', 'b' => 'banana', 'a42' => 'pear', 'd' => 'orange']);
102102

103103
self::assertTrue(Map::fromArray(['a' => 'apple', 'b' => 'banana'])->equals($map->take(2)));
104104
self::assertTrue(Map::fromArray(['a' => 'apple'])->equals($map->take(1)));
@@ -109,9 +109,9 @@ public function testMapTake(): void
109109

110110
public function testMapDrop(): void
111111
{
112-
$map = Map::fromArray(['a' => 'apple', 'b' => 'banana', '42' => 'pear', 'd' => 'orange']);
112+
$map = Map::fromArray(['a' => 'apple', 'b' => 'banana', 'a42' => 'pear', 'd' => 'orange']);
113113

114-
self::assertTrue(Map::fromArray(['42' => 'pear', 'd' => 'orange'])->equals($map->drop(2)));
114+
self::assertTrue(Map::fromArray(['a42' => 'pear', 'd' => 'orange'])->equals($map->drop(2)));
115115
self::assertTrue(Map::fromArray(['d' => 'orange'])->equals($map->drop(3)));
116116
self::assertTrue($map->equals($map->drop(0)));
117117
self::assertSame($map, $map->drop(-1));
@@ -120,14 +120,14 @@ public function testMapDrop(): void
120120

121121
public function testMapFilter(): void
122122
{
123-
$map = Map::fromArray(['a' => 'apple', 'b' => 'banana', '42' => 'pear', 'd' => 'orange']);
123+
$map = Map::fromArray(['a' => 'apple', 'b' => 'banana', 'a42' => 'pear', 'd' => 'orange']);
124124

125125
self::assertTrue(Map::fromArray(['a' => 'apple'])->equals(
126126
$map->filter(function ($entry) {return $entry[1] === 'apple'; })
127127
));
128128

129-
self::assertTrue(Map::fromArray(['42' => 'pear'])->equals(
130-
$map->filter(function ($entry) {return is_numeric($entry[0]); })
129+
self::assertTrue(Map::fromArray(['a42' => 'pear'])->equals(
130+
$map->filter(function ($entry) {return $entry[0] === 'a42'; })
131131
));
132132

133133
self::assertNotSame($map, $map->filter(function () {return true; }));
@@ -190,8 +190,8 @@ public function testMapContainsValue(): void
190190
$map = Map::fromArray(['a' => 'b', 'c' => 'd', 'e' => Option::of('munus')]);
191191

192192
self::assertTrue($map->containsValue('d'));
193-
self::assertFalse($map->containsValue('a'));
194-
self::assertTrue($map->containsValue('munus'));
193+
self::assertFalse($map->containsValue('a')); // @phpstan-ignore-line phpstan is too smart and knows what exactly is in map
194+
self::assertTrue($map->containsValue('munus')); // @phpstan-ignore-line phpstan is too smart and knows what exactly is in map
195195
}
196196

197197
public function testMapValues(): void
@@ -231,9 +231,7 @@ public function testMapDropUntil(): void
231231
self::assertTrue(Map::fromArray(['c' => 3, 'd' => 4])->equals($map->dropUntil(function (Tuple $node): bool {
232232
return $node[0] === 'c';
233233
})));
234-
self::assertTrue(Map::empty()->equals($map->dropUntil(function (Tuple $node): bool {
235-
return false;
236-
})));
234+
self::assertTrue(Map::empty()->equals($map->dropUntil(fn () => false)));
237235
}
238236

239237
public function testMapMerge(): void

tests/Collection/SetTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function testSetCanHoldObjects(): void
129129
$set = Set::ofAll([Set::of(1, 2, 3), Set::of(4, 5, 6)]);
130130

131131
self::assertEquals(2, $set->length());
132-
self::assertFalse($set->contains(new \stdClass()));
132+
self::assertFalse($set->contains(Set::empty()));
133133
self::assertTrue($set->contains(Set::of(1, 2, 3)));
134134
}
135135

tests/Collection/Stream/CollectorsTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ public function testToSetCollector(): void
3030
public function testToMapWithDefaultValueMapperCollector(): void
3131
{
3232
$map = Stream::from(1)->take(3)->collect(Collectors::toMap(
33-
fn (int $value): string => (string) $value
33+
fn (int $value): string => 'a'.$value
3434
));
3535

36-
self::assertTrue(Map::fromArray(['1' => 1, '2' => 2, '3' => 3])->equals($map));
36+
self::assertTrue(Map::fromArray(['a1' => 1, 'a2' => 2, 'a3' => 3])->equals($map));
3737
}
3838

3939
public function testToMapCollector(): void
4040
{
4141
$map = Stream::from(1)->take(3)->collect(Collectors::toMap(
42-
fn (int $value): string => (string) $value,
42+
fn (int $value): string => 'a'.$value,
4343
fn (int $value): int => $value * 2,
4444
));
4545

46-
self::assertTrue(Map::fromArray(['1' => 2, '2' => 4, '3' => 6])->equals($map));
46+
self::assertTrue(Map::fromArray(['a1' => 2, 'a2' => 4, 'a3' => 6])->equals($map));
4747
}
4848

4949
public function testSummingCollector(): void

tests/Collection/StreamTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function testStreamContainsAll(): void
113113
self::assertFalse(Stream::ofAll([1, 2, 3])->containsAll(Stream::ofAll([1, 2, 3, 4])));
114114
self::assertFalse(Stream::ofAll([1, 2, 3])->containsAll(Stream::ofAll([1, 2, 4])));
115115
self::assertFalse(Stream::ofAll([1, 2, 3])->containsAll(Stream::ofAll([1, 4])));
116-
self::assertFalse(Stream::ofAll([1, 2, 3])->containsAll(Stream::ofAll(['a'])));
116+
self::assertFalse(Stream::ofAll([1, 2, 3])->containsAll(Stream::ofAll([0])));
117117
}
118118

119119
public function testStreamMapSingle(): void

tests/Control/OptionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function testGetOrSomething(): void
5353
/** @var Option<string> $option */
5454
$option = Option::of(null);
5555
self::assertNull($option->getOrNull());
56-
self::assertTrue($option->getOrElse(true));
56+
self::assertSame('string', $option->getOrElse('string'));
5757
}
5858

5959
public function testMap(): void

tests/Control/TryToTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ public function testMapFailure(): void
5959

6060
public function testMapWithMapperFailure(): void
6161
{
62-
$try = TryTo::run('time');
62+
$try = TryTo::run(fn () => 0);
6363

64-
self::assertInstanceOf(\TypeError::class, $try->map('strtoupper')->getCause());
64+
self::assertInstanceOf(\DivisionByZeroError::class, $try->map(fn (int $x) => 1 / $x)->getCause());
6565
}
6666

6767
public function testMapWitMapperSuccess(): void

tests/LazyTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public function testMap(): void
4747
{
4848
$lazy = Lazy::of(function () {return 4; });
4949

50-
self::assertInstanceOf(Lazy::class, $lazy->map('range'));
51-
self::assertEquals(2, $lazy->map('sqrt')->get());
50+
self::assertSame(5, $lazy->map(fn (int $x) => $x + 1)->get());
51+
self::assertEquals(2, $lazy->map('sqrt')->get()); // sqrt returns float
5252
}
5353

5454
public function testCollect(): void

0 commit comments

Comments
 (0)