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()"
@@ 4792-4809 (lines=18) @@
4789
     * @phpstan-return static<TKey,T>
4790
     * @psalm-mutation-free
4791
     */
4792
    public function only(array $keys): self
4793
    {
4794
        $keys = \array_flip($keys);
4795
4796
        $generator = function () use ($keys): \Generator {
4797
            foreach ($this->getGenerator() as $key => $value) {
4798
                if (isset($keys[$key])) {
4799
                    yield $key => $value;
4800
                }
4801
            }
4802
        };
4803
4804
        return static::create(
4805
            $generator,
4806
            $this->iteratorClass,
4807
            false
4808
        );
4809
    }
4810
4811
    /**
4812
     * Pad array to the specified size with a given value.