protected function collectFiles(string $dir, string $basePath): array
    {
        $files = [];
        $dh = \opendir($dir);
        
        try {
            while (false !== ($entry = \readdir($dh))) {
                if ($entry == '.' || $entry == '..') {
                    continue;
                }
                
                $check = $dir . \DIRECTORY_SEPARATOR . $entry;
                
                if (\is_dir($check)) {
                    foreach ($this->collectFiles($check, $basePath . '/' . $entry) as $k => $v) {
                        $files[$k] = $v;
                    }
                } elseif (\is_file($check)) {
                    $files[$basePath . '/' . $entry] = $check;
                }
            }
            
            return $files;
        } finally {
            \closedir($dh);
        }
    }