diff options
Diffstat (limited to 'scripts/plugin-stub-generator/src/Report.php')
| -rw-r--r-- | scripts/plugin-stub-generator/src/Report.php | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/scripts/plugin-stub-generator/src/Report.php b/scripts/plugin-stub-generator/src/Report.php index 92e0565e..758a1768 100644 --- a/scripts/plugin-stub-generator/src/Report.php +++ b/scripts/plugin-stub-generator/src/Report.php @@ -7,8 +7,11 @@ namespace Shirabe\PluginStubGenerator; /** The classifier report (scripts/plugin-class-classifier/report.json). */ final class Report { - /** @param array<string, string> $categories fqcn => category */ - private function __construct(private readonly array $categories) + /** + * @param array<string, string> $categories fqcn => category + * @param array<string, string> $kinds fqcn => class / interface / trait / enum + */ + private function __construct(private readonly array $categories, private readonly array $kinds) { } @@ -24,14 +27,38 @@ final class Report throw new GenerationError(["$path records classification violations; fix the classifier lists first"]); } $categories = []; + $kinds = []; foreach ($data['classes'] as $class) { $categories[$class['fqcn']] = $class['category']; + $kinds[$class['fqcn']] = $class['kind']; } - return new self($categories); + return new self($categories, $kinds); } public function category(string $fqcn): ?string { return $this->categories[$fqcn] ?? null; } + + public function kind(string $fqcn): ?string + { + return $this->kinds[$fqcn] ?? null; + } + + /** + * The FQCNs of the given categories, in report order. + * + * @param list<string> $categories + * @return list<string> + */ + public function inCategories(array $categories): array + { + $out = []; + foreach ($this->categories as $fqcn => $category) { + if (in_array($category, $categories, true)) { + $out[] = $fqcn; + } + } + return $out; + } } |
