Code Duplication    Length = 25-28 lines in 2 locations

src/Arrayy.php 2 locations

@@ 619-643 (lines=25) @@
616
         * @psalm-suppress PossiblyInvalidArgument
617
         * @psalm-suppress InvalidScalarArgument
618
         */
619
        if (
620
            $this->pathSeparator
621
            &&
622
            (string) $offset === $offset
623
            &&
624
            \strpos($offset, $this->pathSeparator) !== false
625
        ) {
626
            $explodedPath = \explode($this->pathSeparator, (string) $offset);
627
            if ($explodedPath !== false) {
628
                /** @var string $lastOffset - helper for phpstan */
629
                $lastOffset = \array_pop($explodedPath);
630
                $containerPath = \implode($this->pathSeparator, $explodedPath);
631
632
                /**
633
                 * @psalm-suppress MissingClosureReturnType
634
                 * @psalm-suppress MissingClosureParamType
635
                 */
636
                $this->callAtPath(
637
                    $containerPath,
638
                    static function ($container) use ($lastOffset, &$offsetExists) {
639
                        $offsetExists = \array_key_exists($lastOffset, $container);
640
                    }
641
                );
642
            }
643
        }
644
645
        return $offsetExists;
646
    }
@@ 716-743 (lines=28) @@
713
         * @psalm-suppress PossiblyInvalidArgument
714
         * @psalm-suppress InvalidScalarArgument
715
         */
716
        if (
717
            $this->pathSeparator
718
            &&
719
            (string) $offset === $offset
720
            &&
721
            \strpos($offset, $this->pathSeparator) !== false
722
        ) {
723
            $path = \explode($this->pathSeparator, (string) $offset);
724
725
            if ($path !== false) {
726
                $pathToUnset = \array_pop($path);
727
728
                /**
729
                 * @psalm-suppress MissingClosureReturnType
730
                 * @psalm-suppress MissingClosureParamType
731
                 */
732
                $this->callAtPath(
733
                    \implode($this->pathSeparator, $path),
734
                    static function (&$offset) use ($pathToUnset) {
735
                        if (\is_array($offset)) {
736
                            unset($offset[$pathToUnset]);
737
                        } else {
738
                            $offset = null;
739
                        }
740
                    }
741
                );
742
            }
743
        }
744
745
        unset($this->array[$offset]);
746
    }