src/Utilities/Miscellaneous.php
public static function removeDirectory($directoryPath, $contentOnly = false)
    {
        /*
         * Directory does not exist?
         * Nothing to do
         */
        if (!file_exists($directoryPath)) {
            return null;
        }

        /*
         * It's not a directory?
         * Let's treat it like file
         */
        if (!is_dir($directoryPath)) {
            return unlink($directoryPath);
        }

        foreach (scandir($directoryPath, SCANDIR_SORT_ASCENDING) as $item) {
            if ('.' === $item || '..' === $item) {
                continue;
            }

            if (!self::removeDirectory($directoryPath . DIRECTORY_SEPARATOR . $item)) {
                return false;
            }
        }

        // Directory should be removed too?
        if (!$contentOnly) {
            return rmdir($directoryPath);
        }

        return true;
    }
public static function removeDirectory($directoryPath, $contentOnly = false)
    {
        /*
         * Directory does not exist?
         * Nothing to do
         */
        if (!file_exists($directoryPath)) {
            return null;
        }

        /*
         * It's not a directory?
         * Let's treat it like file
         */
        if (!is_dir($directoryPath)) {
            return unlink($directoryPath);
        }

        foreach (scandir($directoryPath, SCANDIR_SORT_ASCENDING) as $item) {
            if ('.' === $item || '..' === $item) {
                continue;
            }

            if (!self::removeDirectory($directoryPath . DIRECTORY_SEPARATOR . $item)) {
                return false;
            }
        }

        // Directory should be removed too?
        if (!$contentOnly) {
            return rmdir($directoryPath);
        }

        return true;
    }
public static function removeDirectory ( $ directoryPath , $ contentOnly = false ) { /*
         * Directory does not exist?
         * Nothing to do
         */ if ( ! file_exists ( $ directoryPath ) ) { return null ; } /*
         * It's not a directory?
         * Let's treat it like file
         */ if ( ! is_dir ( $ directoryPath ) ) { return unlink ( $ directoryPath ) ; } foreach ( scandir ( $ directoryPath , SCANDIR_SORT_ASCENDING ) as $ item ) { if ( '.' === $ item || '..' === $ item ) { continue ; } if ( ! self :: removeDirectory ( $ directoryPath . DIRECTORY_SEPARATOR . $ item ) ) { return false ; } } // Directory should be removed too? if ( ! $ contentOnly ) { return rmdir ( $ directoryPath ) ; } return true ; }
Removes the directory.
If not empty, removes also contents.

@param string $directoryPath Directory path
@param bool   $contentOnly   (optional) If is set to true, only content of the directory is removed, not
directory itself. Otherwise - directory is removed too (default behaviour).
@return null|bool
Removes the directory . If not empty removes also contents .