Code Duplication    Length = 17-18 lines in 2 locations

src/Arrayy.php 2 locations

@@ 3570-3586 (lines=17) @@
3567
     * @phpstan-return static<TKey,T>
3568
     * @psalm-mutation-free
3569
     */
3570
    public function indexBy($key): self
3571
    {
3572
        // init
3573
        $results = [];
3574
3575
        foreach ($this->getGenerator() as $a) {
3576
            if (\array_key_exists($key, $a) === true) {
3577
                $results[$a[$key]] = $a;
3578
            }
3579
        }
3580
3581
        return static::create(
3582
            $results,
3583
            $this->iteratorClass,
3584
            false
3585
        );
3586
    }
3587
3588
    /**
3589
     * alias: for "Arrayy->searchIndex()"
@@ 4791-4808 (lines=18) @@
4788
     * @phpstan-return static<TKey,T>
4789
     * @psalm-mutation-free
4790
     */
4791
    public function only(array $keys): self
4792
    {
4793
        $keys = \array_flip($keys);
4794
4795
        $generator = function () use ($keys): \Generator {
4796
            foreach ($this->getGenerator() as $key => $value) {
4797
                if (isset($keys[$key])) {
4798
                    yield $key => $value;
4799
                }
4800
            }
4801
        };
4802
4803
        return static::create(
4804
            $generator,
4805
            $this->iteratorClass,
4806
            false
4807
        );
4808
    }
4809
4810
    /**
4811
     * Pad array to the specified size with a given value.