'/\/\*+(.*?)\*\//s', 'md' => '//s', ]; public const array SEARCH_DIRS = [ '/src', '/src-dev', '/tests', '/bin', '/docs', ]; public static function extractFileHeader(SplFileInfo $file): string { preg_match( self::EXTENSIONS[$file->getExtension()], file_get_contents($file->getRealPath()), $matches, ); return $matches[1] ?? ''; } protected function execute(InputInterface $input, OutputInterface $output): int { $pass = true; $root = dirname(__DIR__, 2); $finder = (new Finder())->in(array_map(static fn($dir) => $root . $dir, self::SEARCH_DIRS))->files(); $validator = ValidatorBuilder::call( static fn($input) => array_filter(explode("\n", trim($input))), ValidatorBuilder::templated( 'Each header line of {{subject}}', ValidatorBuilder::each(ValidatorBuilder::stringType()->contains('SPDX')), ), ); foreach (array_keys(self::EXTENSIONS) as $extension) { $finder = $finder->name('*.' . $extension); } foreach (self::HEADERS as $headerLine) { $validator = $validator->contains(sprintf('SPDX-%s', $headerLine)); } foreach ($finder as $file) { try { ValidatorBuilder::named( sprintf('File "%s" SPDX header', $file->getRelativePathname()), $validator, )->assert(static::extractFileHeader($file)); } catch (ValidationException $e) { $output->writeln($e->getFullMessage()); $pass = false; } } return $pass ? Command::SUCCESS : Command::FAILURE; } }