Code Duplication    Length = 25-28 lines in 2 locations

src/Arrayy.php 2 locations

@@ 693-717 (lines=25) @@
690
         * @psalm-suppress PossiblyInvalidArgument
691
         * @psalm-suppress InvalidScalarArgument
692
         */
693
        if (
694
            $this->pathSeparator
695
            &&
696
            (string) $offset === $offset
697
            &&
698
            \strpos($offset, $this->pathSeparator) !== false
699
        ) {
700
            $explodedPath = \explode($this->pathSeparator, (string) $offset);
701
            if ($explodedPath !== false) {
702
                /** @var string $lastOffset - helper for phpstan */
703
                $lastOffset = \array_pop($explodedPath);
704
                $containerPath = \implode($this->pathSeparator, $explodedPath);
705
706
                /**
707
                 * @psalm-suppress MissingClosureReturnType
708
                 * @psalm-suppress MissingClosureParamType
709
                 */
710
                $this->callAtPath(
711
                    $containerPath,
712
                    static function ($container) use ($lastOffset, &$offsetExists) {
713
                        $offsetExists = \array_key_exists($lastOffset, $container);
714
                    }
715
                );
716
            }
717
        }
718
719
        return $offsetExists;
720
    }
@@ 797-824 (lines=28) @@
794
         * @psalm-suppress PossiblyInvalidArgument
795
         * @psalm-suppress InvalidScalarArgument
796
         */
797
        if (
798
            $this->pathSeparator
799
            &&
800
            (string) $offset === $offset
801
            &&
802
            \strpos($offset, $this->pathSeparator) !== false
803
        ) {
804
            $path = \explode($this->pathSeparator, (string) $offset);
805
806
            if ($path !== false) {
807
                $pathToUnset = \array_pop($path);
808
809
                /**
810
                 * @psalm-suppress MissingClosureReturnType
811
                 * @psalm-suppress MissingClosureParamType
812
                 */
813
                $this->callAtPath(
814
                    \implode($this->pathSeparator, $path),
815
                    static function (&$offset) use ($pathToUnset) {
816
                        if (\is_array($offset)) {
817
                            unset($offset[$pathToUnset]);
818
                        } else {
819
                            $offset = null;
820
                        }
821
                    }
822
                );
823
            }
824
        }
825
826
        unset($this->array[$offset]);
827
    }