Code Duplication    Length = 25-28 lines in 2 locations

src/Arrayy.php 2 locations

@@ 672-696 (lines=25) @@
669
         * @psalm-suppress PossiblyInvalidArgument
670
         * @psalm-suppress InvalidScalarArgument
671
         */
672
        if (
673
            $this->pathSeparator
674
            &&
675
            (string) $offset === $offset
676
            &&
677
            \strpos($offset, $this->pathSeparator) !== false
678
        ) {
679
            $explodedPath = \explode($this->pathSeparator, (string) $offset);
680
            if ($explodedPath !== false) {
681
                /** @var string $lastOffset - helper for phpstan */
682
                $lastOffset = \array_pop($explodedPath);
683
                $containerPath = \implode($this->pathSeparator, $explodedPath);
684
685
                /**
686
                 * @psalm-suppress MissingClosureReturnType
687
                 * @psalm-suppress MissingClosureParamType
688
                 */
689
                $this->callAtPath(
690
                    $containerPath,
691
                    static function ($container) use ($lastOffset, &$offsetExists) {
692
                        $offsetExists = \array_key_exists($lastOffset, $container);
693
                    }
694
                );
695
            }
696
        }
697
698
        return $offsetExists;
699
    }
@@ 776-803 (lines=28) @@
773
         * @psalm-suppress PossiblyInvalidArgument
774
         * @psalm-suppress InvalidScalarArgument
775
         */
776
        if (
777
            $this->pathSeparator
778
            &&
779
            (string) $offset === $offset
780
            &&
781
            \strpos($offset, $this->pathSeparator) !== false
782
        ) {
783
            $path = \explode($this->pathSeparator, (string) $offset);
784
785
            if ($path !== false) {
786
                $pathToUnset = \array_pop($path);
787
788
                /**
789
                 * @psalm-suppress MissingClosureReturnType
790
                 * @psalm-suppress MissingClosureParamType
791
                 */
792
                $this->callAtPath(
793
                    \implode($this->pathSeparator, $path),
794
                    static function (&$offset) use ($pathToUnset) {
795
                        if (\is_array($offset)) {
796
                            unset($offset[$pathToUnset]);
797
                        } else {
798
                            $offset = null;
799
                        }
800
                    }
801
                );
802
            }
803
        }
804
805
        unset($this->array[$offset]);
806
    }