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.
@@ 4737-4761 (lines=25) @@
4734
     * @psalm-return static<TKey,T>
4735
     * @psalm-mutation-free
4736
     */
4737
    public function prependImmutable($value, $key = null)
4738
    {
4739
        $generator = function () use ($key, $value): \Generator {
4740
            if ($this->properties !== []) {
4741
                $this->checkType($key, $value);
4742
            }
4743
4744
            if ($key !== null) {
4745
                yield $key => $value;
4746
            } else {
4747
                yield $value;
4748
            }
4749
4750
            /** @noinspection YieldFromCanBeUsedInspection - FP */
4751
            foreach ($this->getGenerator() as $keyOld => $itemOld) {
4752
                yield $keyOld => $itemOld;
4753
            }
4754
        };
4755
4756
        return static::create(
4757
            $generator,
4758
            $this->iteratorClass,
4759
            false
4760
        );
4761
    }
4762
4763
    /**
4764
     * Add a suffix to each key.