function LintCommand::execute
Overrides Command::execute
File
-
vendor/
symfony/ yaml/ Command/ LintCommand.php, line 89
Class
- LintCommand
- Validates YAML files syntax and outputs encountered errors.
Namespace
Symfony\Component\Yaml\CommandCode
protected function execute(InputInterface $input, OutputInterface $output) : int {
$io = new SymfonyStyle($input, $output);
$filenames = (array) $input->getArgument('filename');
$excludes = $input->getOption('exclude');
$this->format = $input->getOption('format');
$flags = $input->getOption('parse-tags');
if (null === $this->format) {
// Autodetect format according to CI environment
$this->format = class_exists(GithubActionReporter::class) && GithubActionReporter::isGithubActionEnvironment() ? 'github' : 'txt';
}
$flags = $flags ? Yaml::PARSE_CUSTOM_TAGS : 0;
$this->displayCorrectFiles = $output->isVerbose();
if ([
'-',
] === $filenames) {
return $this->display($io, [
$this->validate(file_get_contents('php://stdin'), $flags),
]);
}
if (!$filenames) {
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
}
$filesInfo = [];
foreach ($filenames as $filename) {
if (!$this->isReadable($filename)) {
throw new RuntimeException(\sprintf('File or directory "%s" is not readable.', $filename));
}
foreach ($this->getFiles($filename) as $file) {
if (!\in_array($file->getPathname(), $excludes, true)) {
$filesInfo[] = $this->validate(file_get_contents($file), $flags, $file);
}
}
}
return $this->display($io, $filesInfo);
}