<?php

$composer = require __DIR__ . '/vendor/autoload.php';

// Automatically find all classes in the src directory.
$namespace = '\Drupal\\helper';
$path = __DIR__ . '/src';

// Exclude certain classes that fail currently.
$excluded = [
  $path . '/Tests/RenderElementTestTrait.php',
  // @todo Figure out why plugin classes that extend a core class fail:
  $path . '/Plugin/Field/FieldWidget/TimestampDateWidget.php',
  $path . '/Plugin/views/cache/BundleTags.php',
];

// Use a RecursiveIterator to find all .php files in the path.
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
$classes = [];
foreach ($iterator as $file) {
    if ($file->getExtension() === 'php' && !in_array($file->getPathname(), $excluded, TRUE)) {
        // Logic to convert file path back to Full Qualified Class Name (FQCN)
        $prefix = str_replace($path, '', $file->getPath());
        if (!empty($prefix)) {
          $prefix = strtr(ltrim($prefix, '/'), '/', '\\');
          $prefix .= '\\';
        }
        $classes[] = $namespace . '\\' . $prefix . $file->getBasename('.php');
    }
}

return (object)[
    'rootNamespace' => 'Drupal\helper',
    'destDirectory' => 'docs/api',
    'format' => 'github',
    'classes' => $classes,
];
