Code Duplication    Length = 25-25 lines in 2 locations

src/Arrayy.php 2 locations

@@ 315-339 (lines=25) @@
312
     * @phpstan-return static<TKey,T>
313
     * @psalm-mutation-free
314
     */
315
    public function appendImmutable($value, $key = null): self
316
    {
317
        $generator = function () use ($key, $value): \Generator {
318
            if ($this->properties !== []) {
319
                $this->checkType($key, $value);
320
            }
321
322
            /** @noinspection YieldFromCanBeUsedInspection - FP */
323
            foreach ($this->getGenerator() as $keyOld => $itemOld) {
324
                yield $keyOld => $itemOld;
325
            }
326
327
            if ($key !== null) {
328
                yield $key => $value;
329
            } else {
330
                yield $value;
331
            }
332
        };
333
334
        return static::create(
335
            $generator,
336
            $this->iteratorClass,
337
            false
338
        );
339
    }
340
341
    /**
342
     * Sort the entries by value.
@@ 4899-4923 (lines=25) @@
4896
     * @phpstan-return static<TKey,T>
4897
     * @psalm-mutation-free
4898
     */
4899
    public function prependImmutable($value, $key = null)
4900
    {
4901
        $generator = function () use ($key, $value): \Generator {
4902
            if ($this->properties !== []) {
4903
                $this->checkType($key, $value);
4904
            }
4905
4906
            if ($key !== null) {
4907
                yield $key => $value;
4908
            } else {
4909
                yield $value;
4910
            }
4911
4912
            /** @noinspection YieldFromCanBeUsedInspection - FP */
4913
            foreach ($this->getGenerator() as $keyOld => $itemOld) {
4914
                yield $keyOld => $itemOld;
4915
            }
4916
        };
4917
4918
        return static::create(
4919
            $generator,
4920
            $this->iteratorClass,
4921
            false
4922
        );
4923
    }
4924
4925
    /**
4926
     * Add a suffix to each key.