Code Duplication    Length = 25-28 lines in 2 locations

src/Arrayy.php 2 locations

@@ 626-650 (lines=25) @@
623
         * @psalm-suppress PossiblyInvalidArgument
624
         * @psalm-suppress InvalidScalarArgument
625
         */
626
        if (
627
            $this->pathSeparator
628
            &&
629
            (string) $offset === $offset
630
            &&
631
            \strpos($offset, $this->pathSeparator) !== false
632
        ) {
633
            $explodedPath = \explode($this->pathSeparator, (string) $offset);
634
            if ($explodedPath !== false) {
635
                /** @var string $lastOffset - helper for phpstan */
636
                $lastOffset = \array_pop($explodedPath);
637
                $containerPath = \implode($this->pathSeparator, $explodedPath);
638
639
                /**
640
                 * @psalm-suppress MissingClosureReturnType
641
                 * @psalm-suppress MissingClosureParamType
642
                 */
643
                $this->callAtPath(
644
                    $containerPath,
645
                    static function ($container) use ($lastOffset, &$offsetExists) {
646
                        $offsetExists = \array_key_exists($lastOffset, $container);
647
                    }
648
                );
649
            }
650
        }
651
652
        return $offsetExists;
653
    }
@@ 727-754 (lines=28) @@
724
         * @psalm-suppress PossiblyInvalidArgument
725
         * @psalm-suppress InvalidScalarArgument
726
         */
727
        if (
728
            $this->pathSeparator
729
            &&
730
            (string) $offset === $offset
731
            &&
732
            \strpos($offset, $this->pathSeparator) !== false
733
        ) {
734
            $path = \explode($this->pathSeparator, (string) $offset);
735
736
            if ($path !== false) {
737
                $pathToUnset = \array_pop($path);
738
739
                /**
740
                 * @psalm-suppress MissingClosureReturnType
741
                 * @psalm-suppress MissingClosureParamType
742
                 */
743
                $this->callAtPath(
744
                    \implode($this->pathSeparator, $path),
745
                    static function (&$offset) use ($pathToUnset) {
746
                        if (\is_array($offset)) {
747
                            unset($offset[$pathToUnset]);
748
                        } else {
749
                            $offset = null;
750
                        }
751
                    }
752
                );
753
            }
754
        }
755
756
        unset($this->array[$offset]);
757
    }