Code Duplication    Length = 17-18 lines in 2 locations

src/Arrayy.php 2 locations

@@ 3538-3554 (lines=17) @@
3535
     * @phpstan-return static<TKey,T>
3536
     * @psalm-mutation-free
3537
     */
3538
    public function indexBy($key): self
3539
    {
3540
        // init
3541
        $results = [];
3542
3543
        foreach ($this->getGenerator() as $a) {
3544
            if (\array_key_exists($key, $a) === true) {
3545
                $results[$a[$key]] = $a;
3546
            }
3547
        }
3548
3549
        return static::create(
3550
            $results,
3551
            $this->iteratorClass,
3552
            false
3553
        );
3554
    }
3555
3556
    /**
3557
     * alias: for "Arrayy->searchIndex()"
@@ 4752-4769 (lines=18) @@
4749
     * @phpstan-return static<TKey,T>
4750
     * @psalm-mutation-free
4751
     */
4752
    public function only(array $keys): self
4753
    {
4754
        $keys = \array_flip($keys);
4755
4756
        $generator = function () use ($keys): \Generator {
4757
            foreach ($this->getGenerator() as $key => $value) {
4758
                if (isset($keys[$key])) {
4759
                    yield $key => $value;
4760
                }
4761
            }
4762
        };
4763
4764
        return static::create(
4765
            $generator,
4766
            $this->iteratorClass,
4767
            false
4768
        );
4769
    }
4770
4771
    /**
4772
     * Pad array to the specified size with a given value.