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.
@@ 4612-4636 (lines=25) @@
4609
     * @psalm-return static<TKey,T>
4610
     * @psalm-mutation-free
4611
     */
4612
    public function prependImmutable($value, $key = null)
4613
    {
4614
        $generator = function () use ($key, $value): \Generator {
4615
            if ($this->properties !== []) {
4616
                $this->checkType($key, $value);
4617
            }
4618
4619
            if ($key !== null) {
4620
                yield $key => $value;
4621
            } else {
4622
                yield $value;
4623
            }
4624
4625
            /** @noinspection YieldFromCanBeUsedInspection - FP */
4626
            foreach ($this->getGenerator() as $keyOld => $itemOld) {
4627
                yield $keyOld => $itemOld;
4628
            }
4629
        };
4630
4631
        return static::create(
4632
            $generator,
4633
            $this->iteratorClass,
4634
            false
4635
        );
4636
    }
4637
4638
    /**
4639
     * Add a suffix to each key.