Skip to content

Commit 207bdba

Browse files
authored
EnforceIteratorToArrayPreserveKeysRule: fix test for latest PHPStan (#293)
1 parent 2f645b7 commit 207bdba

File tree

1 file changed

+15
-8
lines changed
  • tests/Rule/data/EnforceIteratorToArrayPreserveKeysRule

1 file changed

+15
-8
lines changed

tests/Rule/data/EnforceIteratorToArrayPreserveKeysRule/code.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
namespace EnforceIteratorToArrayPreserveKeysRule;
44

5+
/**
6+
* Isolate the generator, so that PHPStan is not aware of the keys.
7+
*/
8+
function passThru(\Generator $iterable): \Generator {
9+
yield from $iterable;
10+
}
11+
512
$objectAsKey = function () {
613
yield new \stdClass => 1;
714
};
@@ -17,15 +24,15 @@
1724
};
1825

1926

20-
iterator_to_array($objectAsKey()); // error: Calling iterator_to_array without 2nd parameter $preserve_keys. Default value true might cause failures or data loss.
21-
iterator_to_array($dataLoss()); // error: Calling iterator_to_array without 2nd parameter $preserve_keys. Default value true might cause failures or data loss.
22-
iterator_to_array($noKeys()); // error: Calling iterator_to_array without 2nd parameter $preserve_keys. Default value true might cause failures or data loss.
27+
iterator_to_array(passThru($objectAsKey())); // error: Calling iterator_to_array without 2nd parameter $preserve_keys. Default value true might cause failures or data loss.
28+
iterator_to_array(passThru($dataLoss())); // error: Calling iterator_to_array without 2nd parameter $preserve_keys. Default value true might cause failures or data loss.
29+
iterator_to_array(passThru($noKeys())); // error: Calling iterator_to_array without 2nd parameter $preserve_keys. Default value true might cause failures or data loss.
2330

24-
iterator_to_array($objectAsKey(), false);
25-
iterator_to_array($dataLoss(), false);
26-
iterator_to_array($noKeys(), true);
27-
iterator_to_array(... [$noKeys(), true]);
31+
iterator_to_array(passThru($objectAsKey()), false);
32+
iterator_to_array(passThru($dataLoss()), false);
33+
iterator_to_array(passThru($noKeys()), true);
34+
iterator_to_array(... [passThru($noKeys()), true]);
2835
iterator_to_array(
2936
preserve_keys: true,
30-
iterator: $noKeys()
37+
iterator: passThru($noKeys())
3138
);

0 commit comments

Comments
 (0)