loophp /
collection
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace loophp\collection\Operation; |
||
| 6 | |||
| 7 | use Closure; |
||
| 8 | use Generator; |
||
| 9 | use loophp\iterators\IterableIteratorAggregate; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * @immutable |
||
| 13 | * |
||
| 14 | * @template TKey |
||
| 15 | * @template T |
||
| 16 | */ |
||
| 17 | final class Permutate extends AbstractOperation |
||
| 18 | { |
||
| 19 | 2 | public function __invoke(): Closure |
|
| 20 | { |
||
| 21 | 2 | $getPermutations = |
|
| 22 | /** |
||
| 23 | * @param list<T> $dataset |
||
|
0 ignored issues
–
show
|
|||
| 24 | * |
||
| 25 | * @return Generator<int, list<T>> |
||
| 26 | */ |
||
| 27 | 2 | fn (array $dataset): Generator => $this->getPermutations($dataset); |
|
| 28 | |||
| 29 | 2 | return |
|
| 30 | /** |
||
| 31 | * @param iterable<TKey, T> $iterable |
||
| 32 | * |
||
| 33 | * @return Generator<int, list<T>> |
||
| 34 | * |
||
| 35 | * @psalm-suppress InvalidOperand |
||
| 36 | */ |
||
| 37 | 2 | static fn (iterable $iterable): Generator => $getPermutations([...(new IterableIteratorAggregate($iterable))]); |
|
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param array<array-key, T> $dataset |
||
|
0 ignored issues
–
show
|
|||
| 42 | * |
||
| 43 | * @return Generator<int, list<T>> |
||
| 44 | */ |
||
| 45 | 2 | private function getPermutations(array $dataset): Generator |
|
| 46 | { |
||
| 47 | 2 | foreach ($dataset as $key => $firstItem) { |
|
| 48 | 2 | $remaining = $dataset; |
|
| 49 | |||
| 50 | 2 | array_splice($remaining, $key, 1); |
|
| 51 | |||
| 52 | 2 | if ([] === $remaining) { |
|
| 53 | 2 | yield [$firstItem]; |
|
| 54 | |||
| 55 | 2 | continue; |
|
| 56 | } |
||
| 57 | |||
| 58 | 2 | foreach ($this->getPermutations($remaining) as $permutation) { |
|
| 59 | // TODO: Fix this. |
||
| 60 | 2 | array_unshift($permutation, $firstItem); |
|
| 61 | |||
| 62 | 2 | yield $permutation; |
|
| 63 | } |
||
| 64 | } |
||
| 65 | } |
||
| 66 | } |
||
| 67 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths