Skip to content

Commit

Permalink
removing reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph committed Jul 8, 2021
1 parent 82f936a commit 581eef5
Showing 1 changed file with 31 additions and 42 deletions.
73 changes: 31 additions & 42 deletions src/Linter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand All @@ -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']);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 581eef5

Please sign in to comment.