function clear(string $dir): bool
{
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir,
FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST);
$iterator = iterator_count($iterator) ? $iterator : [];
foreach ($iterator as $item) {
$item->isDir() && !$item->isLink() ? rmdir($item->getPathname()) : unlink($item->getPathname());
}
return rmdir($dir);
}