protected function iterateOverFiles(string $filter, array $files, array $list) : array
    {
        $result = [];
        foreach ($files as $filePath) {
            //Filter by filter.
            if ($filter !== '' && substr($filePath, -strlen($filter)) !== $filter) {
                continue;
            }
            //Filter by black/white List
            $directory = dirname($filePath);
            $lastDirectoryPath = $filePath;
            while (!in_array($directory, [$this->environment->getRootDirectory(), '', $lastDirectoryPath], true)
            ) {
                if (array_key_exists($directory, $list)) {
                    if ($list[$directory] === true) {
                        $result[] = $filePath;
                    }
                    continue 2;
                }
                $lastDirectoryPath = $directory;
                $directory = dirname($directory);
            }
            $result[] = $filePath;
        }
        return $result;
    }