Skip to content

Commit d15c095

Browse files
NGSTACK-938 fix phpstan issues
1 parent 5a28d30 commit d15c095

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/Action/CheckLinter.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ protected function doExecute(Config $config, IO $io, Repository $repository, Act
3333
}
3434

3535
/**
36+
* @param string[] $directories
37+
*
3638
* @return array<string, mixed>
3739
*/
3840
protected function checkLinter(array $directories, string $linterCommand): array

src/Action/CheckPrettier.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,37 @@ final class CheckPrettier extends Action
2222

2323
protected function doExecute(Config $config, IO $io, Repository $repository, ActionConfig $action): void
2424
{
25+
/** @var string|string[] $extensions */
2526
$extensions = $action->getOptions()->get('extensions', ['js', 'jsx', 'ts', 'tsx', 'css', 'scss']);
2627
$excludedFiles = $action->getOptions()->get('excluded_files') ?? [];
2728
$directories = $action->getOptions()->get('directories', ['assets']);
2829
$prettierCommand = $action->getOptions()->get('prettier_command', 'pnpm prettier');
2930
$formatOptions = $action->getOptions()->get('prettier_options', '--check');
3031

3132
$finder = new Finder();
32-
$finder->in($directories)->files()->name(preg_filter('/^/', '*.', $extensions));
33+
preg_filter('/^/', '*.', $extensions);
34+
$finder->in($directories)->files()->name($extensions);
3335

3436
if ($finder->hasResults()) {
35-
$io->write(sprintf('Running %s on files:', $prettierCommand), true, IO::VERBOSE);
37+
$io->write(sprintf('Running %s on files:', $prettierCommand));
3638

3739
foreach ($finder as $file) {
38-
if ($this->shouldSkipFileCheck($file, $excludedFiles)) {
40+
if ($this->shouldSkipFileCheck($file->getPath(), $excludedFiles)) {
3941
continue;
4042
}
4143

4244
$result = $this->checkPrettier($file->getPath(), $prettierCommand, $formatOptions);
43-
$io->write($result['output']);
45+
46+
$io->write(sprintf('<info>%s: </info>', $file->getPath()));
47+
48+
/** @var bool $isResultSuccess */
49+
$isResultSuccess = $result['success'];
50+
51+
if ($isResultSuccess) {
52+
$io->write($result['output']);
53+
} else {
54+
$io->writeError(sprintf('<error>%s</error>', $result['error']));
55+
}
4456

4557
if ($result['success'] !== true) {
4658
$this->throwError($action, $io);
@@ -82,6 +94,7 @@ protected function checkPrettier(string $file, string $prettierCommand, string $
8294
return [
8395
'success' => $result->isSuccessful(),
8496
'output' => $result->getStdOut(),
97+
'error' => $result->getStdErr(),
8598
];
8699
}
87100
}

0 commit comments

Comments
 (0)