Skip to content

Commit

Permalink
Merge pull request #14 from Katalam/memory-limit
Browse files Browse the repository at this point in the history
[2.X] feat: add the support of the memory limit cli command of phpstan
  • Loading branch information
nunomaduro committed Jan 10, 2024
2 parents 751f0c1 + fbf36fb commit 1b5ae0d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ public function handleArguments(array $arguments): array
$this->coverageMin = (float) explode('=', $argument)[1];
}

if (str_starts_with($argument, '--memory-limit')) {
$memoryLimit = explode('=', $argument)[1] ?? '';

if (preg_match('/^-?\d+[kMG]?$/', $memoryLimit) !== 1) {
View::render('components.badge', [
'type' => 'ERROR',
'content' => 'Invalid memory limit: '.$memoryLimit,
]);

$this->exit(1);
}

if (ini_set('memory_limit', $memoryLimit) === false) {
View::render('components.badge', [
'type' => 'ERROR',
'content' => 'Failed to set memory limit: '.$memoryLimit,
]);

$this->exit(1);
}
}

if (str_starts_with($argument, '--type-coverage-json')) {
$outputPath = explode('=', $argument)[1] ?? null;

Expand Down

0 comments on commit 1b5ae0d

Please sign in to comment.