protected function remove($directory): void
    {
        $sourcePath = $this->packagePath . DS . $directory;

        if (!is_dir($sourcePath)) {
            return;
        }
        foreach ($iterator = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator(
                $sourcePath,
                \RecursiveDirectoryIterator::SKIP_DOTS
            ),
            \RecursiveIteratorIterator::CHILD_FIRST
        ) as $item) {
            // path to copied file
            $current = PATH_ROOT . DS . $directory . DS . $iterator->getSubPathName();

            // remove empty directories
            if (is_dir($current)) {
                if (\count(scandir($current, SCANDIR_SORT_ASCENDING)) === 2) {
                    rmdir($current);
                    $this->installer->getIo()->write(
                        "  - Removed directory `{$iterator->getSubPathName()}`",
                        true,
                        IOInterface::VERBOSE
                    );
                } else {
                    $this->installer->getIo()->write(
                        sprintf(
                            '  - <comment>Skipped directory `%s`</comment>',
                            $directory . DS . $iterator->getSubPathName()
                        ),
                        true,
                        IOInterface::VERBOSE
                    );
                }
                continue;
            }

            // skip already removed files
            if (!is_file($current)) {
                continue;
            }

            if (md5_file($item) === md5_file($current)) {
                // remove file
                unlink($current);
                $this->installer->getIo()->write(
                    "  - Removed file `{$iterator->getSubPathName()}`",
                    true,
                    IOInterface::VERBOSE
                );
            } else {
                // or skip changed files
                $this->installer->getIo()->write(
                    "  - <comment>File `{$iterator->getSubPathName()}` has changed</comment>",
                    true,
                    IOInterface::VERBOSE
                );
            }
        }
    }
protected function remove($directory): void
    {
        $sourcePath = $this->packagePath . DS . $directory;

        if (!is_dir($sourcePath)) {
            return;
        }
        foreach ($iterator = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator(
                $sourcePath,
                \RecursiveDirectoryIterator::SKIP_DOTS
            ),
            \RecursiveIteratorIterator::CHILD_FIRST
        ) as $item) {
            // path to copied file
            $current = PATH_ROOT . DS . $directory . DS . $iterator->getSubPathName();

            // remove empty directories
            if (is_dir($current)) {
                if (\count(scandir($current, SCANDIR_SORT_ASCENDING)) === 2) {
                    rmdir($current);
                    $this->installer->getIo()->write(
                        "  - Removed directory `{$iterator->getSubPathName()}`",
                        true,
                        IOInterface::VERBOSE
                    );
                } else {
                    $this->installer->getIo()->write(
                        sprintf(
                            '  - <comment>Skipped directory `%s`</comment>',
                            $directory . DS . $iterator->getSubPathName()
                        ),
                        true,
                        IOInterface::VERBOSE
                    );
                }
                continue;
            }

            // skip already removed files
            if (!is_file($current)) {
                continue;
            }

            if (md5_file($item) === md5_file($current)) {
                // remove file
                unlink($current);
                $this->installer->getIo()->write(
                    "  - Removed file `{$iterator->getSubPathName()}`",
                    true,
                    IOInterface::VERBOSE
                );
            } else {
                // or skip changed files
                $this->installer->getIo()->write(
                    "  - <comment>File `{$iterator->getSubPathName()}` has changed</comment>",
                    true,
                    IOInterface::VERBOSE
                );
            }
        }
    }
protected function remove ( $ directory ) : void { $ sourcePath = $ this -> packagePath . DS . $ directory ; if ( ! is_dir ( $ sourcePath ) ) { return ; } foreach ( $ iterator = new \ RecursiveIteratorIterator ( new \ RecursiveDirectoryIterator ( $ sourcePath , \ RecursiveDirectoryIterator :: SKIP_DOTS ) , \ RecursiveIteratorIterator :: CHILD_FIRST ) as $ item ) { // path to copied file $ current = PATH_ROOT . DS . $ directory . DS . $ iterator -> getSubPathName ( ) ; // remove empty directories if ( is_dir ( $ current ) ) { if ( \ count ( scandir ( $ current , SCANDIR_SORT_ASCENDING ) ) === 2 ) { rmdir ( $ current ) ; $ this -> installer -> getIo ( ) -> write ( "  - Removed directory `{$iterator->getSubPathName()}`" , true , IOInterface :: VERBOSE ) ; } else { $ this -> installer -> getIo ( ) -> write ( sprintf ( '  - <comment>Skipped directory `%s`</comment>' , $ directory . DS . $ iterator -> getSubPathName ( ) ) , true , IOInterface :: VERBOSE ) ; } continue ; } // skip already removed files if ( ! is_file ( $ current ) ) { continue ; } if ( md5_file ( $ item ) === md5_file ( $ current ) ) { // remove file unlink ( $ current ) ; $ this -> installer -> getIo ( ) -> write ( "  - Removed file `{$iterator->getSubPathName()}`" , true , IOInterface :: VERBOSE ) ; } else { // or skip changed files $ this -> installer -> getIo ( ) -> write ( "  - <comment>File `{$iterator->getSubPathName()}` has changed</comment>" , true , IOInterface :: VERBOSE ) ; } } }
It recursively removes the files and directories
@param $directory
@return void
It recursively removes the files and directories