From d15c09555791fdae79f139fd8fac773f5a766afb Mon Sep 17 00:00:00 2001 From: Jakov Knezovic Date: Fri, 13 Dec 2024 15:17:05 +0100 Subject: [PATCH] NGSTACK-938 fix phpstan issues --- src/Action/CheckLinter.php | 2 ++ src/Action/CheckPrettier.php | 21 +++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Action/CheckLinter.php b/src/Action/CheckLinter.php index b3097c4..76bc681 100644 --- a/src/Action/CheckLinter.php +++ b/src/Action/CheckLinter.php @@ -33,6 +33,8 @@ protected function doExecute(Config $config, IO $io, Repository $repository, Act } /** + * @param string[] $directories + * * @return array */ protected function checkLinter(array $directories, string $linterCommand): array diff --git a/src/Action/CheckPrettier.php b/src/Action/CheckPrettier.php index ed0becf..5e10567 100644 --- a/src/Action/CheckPrettier.php +++ b/src/Action/CheckPrettier.php @@ -22,6 +22,7 @@ final class CheckPrettier extends Action protected function doExecute(Config $config, IO $io, Repository $repository, ActionConfig $action): void { + /** @var string|string[] $extensions */ $extensions = $action->getOptions()->get('extensions', ['js', 'jsx', 'ts', 'tsx', 'css', 'scss']); $excludedFiles = $action->getOptions()->get('excluded_files') ?? []; $directories = $action->getOptions()->get('directories', ['assets']); @@ -29,18 +30,29 @@ protected function doExecute(Config $config, IO $io, Repository $repository, Act $formatOptions = $action->getOptions()->get('prettier_options', '--check'); $finder = new Finder(); - $finder->in($directories)->files()->name(preg_filter('/^/', '*.', $extensions)); + preg_filter('/^/', '*.', $extensions); + $finder->in($directories)->files()->name($extensions); if ($finder->hasResults()) { - $io->write(sprintf('Running %s on files:', $prettierCommand), true, IO::VERBOSE); + $io->write(sprintf('Running %s on files:', $prettierCommand)); foreach ($finder as $file) { - if ($this->shouldSkipFileCheck($file, $excludedFiles)) { + if ($this->shouldSkipFileCheck($file->getPath(), $excludedFiles)) { continue; } $result = $this->checkPrettier($file->getPath(), $prettierCommand, $formatOptions); - $io->write($result['output']); + + $io->write(sprintf('%s: ', $file->getPath())); + + /** @var bool $isResultSuccess */ + $isResultSuccess = $result['success']; + + if ($isResultSuccess) { + $io->write($result['output']); + } else { + $io->writeError(sprintf('%s', $result['error'])); + } if ($result['success'] !== true) { $this->throwError($action, $io); @@ -82,6 +94,7 @@ protected function checkPrettier(string $file, string $prettierCommand, string $ return [ 'success' => $result->isSuccessful(), 'output' => $result->getStdOut(), + 'error' => $result->getStdErr(), ]; } }