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.
@@ 4891-4915 (lines=25) @@
4888
     * @phpstan-return static<TKey,T>
4889
     * @psalm-mutation-free
4890
     */
4891
    public function prependImmutable($value, $key = null)
4892
    {
4893
        $generator = function () use ($key, $value): \Generator {
4894
            if ($this->properties !== []) {
4895
                $this->checkType($key, $value);
4896
            }
4897
4898
            if ($key !== null) {
4899
                yield $key => $value;
4900
            } else {
4901
                yield $value;
4902
            }
4903
4904
            /** @noinspection YieldFromCanBeUsedInspection - FP */
4905
            foreach ($this->getGenerator() as $keyOld => $itemOld) {
4906
                yield $keyOld => $itemOld;
4907
            }
4908
        };
4909
4910
        return static::create(
4911
            $generator,
4912
            $this->iteratorClass,
4913
            false
4914
        );
4915
    }
4916
4917
    /**
4918
     * Add a suffix to each key.