Issues (85)

src/Operation/Distinct.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace loophp\collection\Operation;
6
7
use ArrayIterator;
8
use Closure;
9
use Generator;
10
11
/**
12
 * @immutable
13
 *
14
 * @template TKey
15
 * @template T
16
 */
17
final class Distinct extends AbstractOperation
18
{
19
    /**
20
     * @template U
21
     *
22
     * @return Closure(callable(U): Closure(U): bool): Closure(callable(T, TKey): U): Closure(iterable<TKey, T>): Generator<TKey, T>
23
     */
24 12
    public function __invoke(): Closure
25
    {
26 12
        return
27
            /**
28
             * @param callable(U): (Closure(U): bool) $comparatorCallback
29
             *
30
             * @return Closure(callable(T, TKey): U): Closure(iterable<TKey, T>): Generator<TKey, T>
31
             */
32 12
            static fn (callable $comparatorCallback): Closure =>
33
                /**
34
                 * @param callable(T, TKey): U $accessorCallback
35
                 *
36
                 * @return Closure(iterable<TKey, T>): Generator<TKey, T>
37
                 */
38 12
                static function (callable $accessorCallback) use ($comparatorCallback): Closure {
39
                    /** @var ArrayIterator<int, array{0: TKey, 1: T}> $stack */
40 12
                    $stack = new ArrayIterator();
41
42 12
                    return (new Filter())()(
43
                        /**
44
                         * @param T $value
45
                         * @param TKey $key
0 ignored issues
show
The type loophp\collection\Operation\TKey was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
46
                         */
47 12
                        static function (mixed $value, mixed $key) use ($comparatorCallback, $accessorCallback, $stack): bool {
48 12
                            $every = (new Every())()(
49
                                /**
50
                                 * @param array{0: TKey, 1: T} $keyValuePair
51
                                 */
52 12
                                static fn (int $index, array $keyValuePair): bool => !$comparatorCallback($accessorCallback($value, $key))($accessorCallback($keyValuePair[1], $keyValuePair[0]))
53 12
                            )($stack);
54
55 12
                            if (false === $every->current()) {
56 12
                                return false;
57
                            }
58
59 12
                            $stack->append([$key, $value]);
60
61 12
                            return true;
62 12
                        }
63 12
                    );
64 12
                };
65
    }
66
}
67