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.
@@ 4388-4412 (lines=25) @@
4385
     * @psalm-return static<TKey,T>
4386
     * @psalm-mutation-free
4387
     */
4388
    public function prependImmutable($value, $key = null)
4389
    {
4390
        $generator = function () use ($key, $value): \Generator {
4391
            if ($this->properties !== []) {
4392
                $this->checkType($key, $value);
4393
            }
4394
4395
            if ($key !== null) {
4396
                yield $key => $value;
4397
            } else {
4398
                yield $value;
4399
            }
4400
4401
            /** @noinspection YieldFromCanBeUsedInspection - FP */
4402
            foreach ($this->getGenerator() as $keyOld => $itemOld) {
4403
                yield $keyOld => $itemOld;
4404
            }
4405
        };
4406
4407
        return static::create(
4408
            $generator,
4409
            $this->iteratorClass,
4410
            false
4411
        );
4412
    }
4413
4414
    /**
4415
     * Add a suffix to each key.