diff --git a/.phplint.yml b/.phplint.yml index f51c3c4c..6232fadc 100644 --- a/.phplint.yml +++ b/.phplint.yml @@ -5,3 +5,4 @@ extensions: exclude: - vendor warning: true +#memory_limit: -1 diff --git a/src/Command/LintCommand.php b/src/Command/LintCommand.php index c8314ac2..17031253 100644 --- a/src/Command/LintCommand.php +++ b/src/Command/LintCommand.php @@ -158,6 +158,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int $linter->setCache(Cache::get()); } + if (!empty($options['memory_limit'])) { + $linter->setMemoryLimit($options['memory_limit']); + } + $fileCount = count($linter->getFiles()); $code = 0; diff --git a/src/Console/Application.php b/src/Console/Application.php index ebe93a9f..8ce64950 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -10,7 +10,7 @@ class Application extends BaseApplication { public const NAME = 'phplint'; - public const VERSION = '5.2.1'; + public const VERSION = '5.2'; public function __construct() { diff --git a/src/Linter.php b/src/Linter.php index 6987aa0c..0d59f5f2 100644 --- a/src/Linter.php +++ b/src/Linter.php @@ -17,6 +17,7 @@ class Linter private array $extensions; private int $processLimit = 5; private bool $warning; + private string $memoryLimit; public function __construct(array|string $paths, array $excludes = [], array $extensions = ['php'], $warning = false) { @@ -91,6 +92,11 @@ public function setCache(array $cache = []) $this->cache = $cache; } + public function setMemoryLimit(string $limit) + { + $this->memoryLimit = $limit; + } + public function getFiles(): array { if (empty($this->files)) { @@ -160,9 +166,15 @@ 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, ]; + if (!empty($this->memoryLimit)) { + $command[] = '-d memory_limit=' . $this->memoryLimit; + } + + $command[] = '-l'; + $command[] = $filename; + return new Lint($command); } }