Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix array and iterable type action methods on
NeverType
- Loading branch information
1 parent
d91411b
commit 7a7b386
Showing
4 changed files
with
142 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Bug8277; | ||
|
||
use Generator; | ||
use function PHPStan\Testing\assertType; | ||
|
||
/** | ||
* {@see FunctionalStreamTest::testWindow()} | ||
* | ||
* @template K | ||
* @template T | ||
* | ||
* @param iterable<K, T> $stream | ||
* @param positive-int $width | ||
* | ||
* @return Generator<int, T[]> | ||
*/ | ||
function swindow(iterable $stream, int $width): Generator | ||
{ | ||
$window = []; | ||
foreach ($stream as $value) { | ||
$window[] = $value; | ||
$count = count($window); | ||
|
||
assertType('int<1, max>', $count); | ||
|
||
switch (true) { | ||
case $count > $width: | ||
array_shift($window); | ||
// no break | ||
case $count === $width: | ||
yield $window; | ||
} | ||
} | ||
} |