From 581eef5eaa0463a9ccab0910798738f3bf7b7aef Mon Sep 17 00:00:00 2001 From: joseph Date: Thu, 8 Jul 2021 10:05:11 +0000 Subject: [PATCH] removing reformat --- src/Linter.php | 73 +++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 42 deletions(-) diff --git a/src/Linter.php b/src/Linter.php index a3543fe6..b1b0fbad 100644 --- a/src/Linter.php +++ b/src/Linter.php @@ -10,27 +10,22 @@ class Linter { private ?\Closure $processCallback = null; - private array $files = []; - private array $cache = []; - private array $paths; - private array $excludes; - private array $extensions; - private int $processLimit = 5; - private bool $warning; - - public function __construct( - array|string $paths, - array $excludes = [], - array $extensions = ['php'], - $warning = false - ) { - $this->paths = (array)$paths; - $this->excludes = $excludes; - $this->warning = $warning; + private array $files = []; + private array $cache = []; + private array $paths; + private array $excludes; + private array $extensions; + private int $processLimit = 5; + private bool $warning; + + public function __construct(array|string $paths, array $excludes = [], array $extensions = ['php'], $warning = false) + { + $this->paths = (array)$paths; + $this->excludes = $excludes; + $this->warning = $warning; $this->extensions = \array_map(function ($extension) { return \sprintf('*.%s', \ltrim($extension, '.')); - }, - $extensions); + }, $extensions); } public function lint(array $files = [], bool $cache = true): array @@ -41,21 +36,20 @@ public function lint(array $files = [], bool $cache = true): array $processCallback = $this->processCallback ?? fn() => null; - $errors = []; - $running = []; + $errors = []; + $running = []; $newCache = []; while (!empty($files) || !empty($running)) { for ($i = count($running); !empty($files) && $i < $this->processLimit; ++$i) { - $file = array_shift($files); - $filename = $file->getRealPath(); + $file = array_shift($files); + $filename = $file->getRealPath(); $relativePathname = $file->getRelativePathname(); - if (!isset($this->cache[$relativePathname]) || - $this->cache[$relativePathname] !== md5_file($filename)) { - $lint = $this->createLintProcess($filename); + if (!isset($this->cache[$relativePathname]) || $this->cache[$relativePathname] !== md5_file($filename)) { + $lint = $this->createLintProcess($filename); $running[$filename] = [ - 'process' => $lint, - 'file' => $file, + 'process' => $lint, + 'file' => $file, 'relativePath' => $relativePathname, ]; $lint->start(); @@ -76,14 +70,10 @@ public function lint(array $files = [], bool $cache = true): array if ($lint->hasSyntaxError()) { $processCallback('error', $item['file']); - $errors[$filename] = - array_merge(['file' => $filename, 'file_name' => $item['relativePath']], - $lint->getSyntaxError()); + $errors[$filename] = array_merge(['file' => $filename, 'file_name' => $item['relativePath']], $lint->getSyntaxError()); } elseif ($this->warning && $lint->hasSyntaxIssue()) { $processCallback('warning', $item['file']); - $errors[$filename] = - array_merge(['file' => $filename, 'file_name' => $item['relativePath']], - $lint->getSyntaxIssue()); + $errors[$filename] = array_merge(['file' => $filename, 'file_name' => $item['relativePath']], $lint->getSyntaxIssue()); } else { $newCache[$item['relativePath']] = md5_file($filename); $processCallback('ok', $item['file']); @@ -124,12 +114,12 @@ protected function getFilesFromDir(string $dir): array { $finder = new Finder(); $finder->files() - ->ignoreUnreadableDirs() - ->ignoreVCS(true) - ->filter(function (SplFileInfo $file) { - return $file->isReadable(); - }) - ->in(realpath($dir)); + ->ignoreUnreadableDirs() + ->ignoreVCS(true) + ->filter(function (SplFileInfo $file) { + return $file->isReadable(); + }) + ->in(realpath($dir)); array_map([$finder, 'name'], $this->extensions); array_map([$finder, 'notPath'], $this->excludes); @@ -174,8 +164,7 @@ protected function createLintProcess(string $filename): Lint PHP_SAPI == 'cli' ? PHP_BINARY : PHP_BINDIR . '/php', '-d error_reporting=E_ALL', '-d display_errors=On', - '-l', - $filename, + '-l', $filename, ]; return new Lint($command);