protected function discoverClasses(array $namespaces) : array {
    $classes = [];

    foreach ($namespaces as $namespace => $namespace_directories) {
      $namespace_directories = array_filter($namespace_directories, function ($dir) {
        return is_dir($dir);
      });
      foreach ($namespace_directories as $namespace_directory) {
        $finder = $this->createFinder()
          ->files()
          ->name('*.php')
          ->in($namespace_directory)
          ->path($this->subdir);
        foreach ($finder as $file) {
          // Remove the namespace directory from the full file path.
          $sub_path = substr($file->getPath(), strlen($namespace_directory));
          if (!empty($sub_path)) {
            $sub_path = substr($sub_path, 1);
            $sub_path = str_replace('/', '\\', $sub_path);
            $sub_path .= '\\';
            $classes[] = $namespace . $sub_path . $file->getBasename('.php');
          }
        }
      }
    }

    return $classes;
  }