Code Duplication    Length = 25-25 lines in 2 locations

src/Arrayy.php 2 locations

@@ 308-332 (lines=25) @@
305
     * @psalm-return static<TKey,T>
306
     * @psalm-mutation-free
307
     */
308
    public function appendImmutable($value, $key = null): self
309
    {
310
        $generator = function () use ($key, $value): \Generator {
311
            if ($this->properties !== []) {
312
                $this->checkType($key, $value);
313
            }
314
315
            /** @noinspection YieldFromCanBeUsedInspection - FP */
316
            foreach ($this->getGenerator() as $keyOld => $itemOld) {
317
                yield $keyOld => $itemOld;
318
            }
319
320
            if ($key !== null) {
321
                yield $key => $value;
322
            } else {
323
                yield $value;
324
            }
325
        };
326
327
        return static::create(
328
            $generator,
329
            $this->iteratorClass,
330
            false
331
        );
332
    }
333
334
    /**
335
     * Sort the entries by value.
@@ 4764-4788 (lines=25) @@
4761
     * @psalm-return static<TKey,T>
4762
     * @psalm-mutation-free
4763
     */
4764
    public function prependImmutable($value, $key = null)
4765
    {
4766
        $generator = function () use ($key, $value): \Generator {
4767
            if ($this->properties !== []) {
4768
                $this->checkType($key, $value);
4769
            }
4770
4771
            if ($key !== null) {
4772
                yield $key => $value;
4773
            } else {
4774
                yield $value;
4775
            }
4776
4777
            /** @noinspection YieldFromCanBeUsedInspection - FP */
4778
            foreach ($this->getGenerator() as $keyOld => $itemOld) {
4779
                yield $keyOld => $itemOld;
4780
            }
4781
        };
4782
4783
        return static::create(
4784
            $generator,
4785
            $this->iteratorClass,
4786
            false
4787
        );
4788
    }
4789
4790
    /**
4791
     * Add a suffix to each key.