Skip to content

Commit

Permalink
Update workspace utility:
Browse files Browse the repository at this point in the history
- add PHPStan command
  • Loading branch information
webeweb committed Mar 16, 2024
1 parent 3a6b95b commit 1b4bbb7
Showing 1 changed file with 52 additions and 4 deletions.
56 changes: 52 additions & 4 deletions util/workspace.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ public static function getAvailableMethods(): array {
"--git-push-origin" => "runGitPushOrigin",
"--git-push-upstream" => "runGitPushUpstream",
"--git-status" => "runGitStatus",
"--phpunit" => "runPhpunit",
"--phpstan" => "runPhpStan",
"--phpunit" => "runPhpUnit",
"--license-update" => "runLicenseUpdate",
"--phpcoveralls-update" => "runPhpCoverallsUpdate",
"--phpmetrics-update" => "runPhpMetricsUpdate",
Expand All @@ -166,6 +167,7 @@ public static function getAvailableOptions(): array {
"--git-push-origin" => "Execute 'git push origin'",
"--git-push-upstream" => "Execute 'git push upstream --all --tag'",
"--git-status" => "Execute 'git status'",
"--phpstan" => "Execute 'vendor/bin/phpstan",
"--phpunit" => "Execute 'vendor/bin/phpunit",
"--license-update" => "Update LICENSE",
"--phpcoveralls-update" => "Update PhpCoveralls <version>",
Expand Down Expand Up @@ -254,6 +256,29 @@ private function hasLicense(): bool {
]));
}

/**
* Determines if this directory has a PHPStan configuration.
*
* @return bool Returns true in case of success, false otherwise.
* @throws Throwable Throws an exception if an error occurs.
*/
private function hasPhpStanConfiguration(): bool {

$cfg = file_exists(implode(DIRECTORY_SEPARATOR, [
$this->getDirectory(),
"phpstan.neon.dist",
]));

$php = file_exists(implode(DIRECTORY_SEPARATOR, [
$this->getDirectory(),
"vendor",
"bin",
"phpstan",
]));

return $cfg && $php;
}

/**
* Determines if this directory has a PHPUnit configuration.
*
Expand All @@ -262,7 +287,7 @@ private function hasLicense(): bool {
*/
private function hasPhpUnitConfiguration(): bool {

$xml = file_exists(implode(DIRECTORY_SEPARATOR, [
$cfg = file_exists(implode(DIRECTORY_SEPARATOR, [
$this->getDirectory(),
"phpunit.xml.dist",
]));
Expand All @@ -274,7 +299,7 @@ private function hasPhpUnitConfiguration(): bool {
"phpunit",
]));

return $xml && $php;
return $cfg && $php;
}

/**
Expand Down Expand Up @@ -559,6 +584,29 @@ public function runPhpMetricsUpdate(string $version): void {
$this->runPharUpdate("phpmetrics", $version, "metrics");
}

/**
* Executes a command "phpstan".
*
* @return void
* @throws Throwable Throws an exception if an error occurs.
*/
public function runPhpStan(): void {

if (false === $this->hasPhpStanConfiguration()) {
return;
}

$php = $this->getPhpBinary();
$cmd = implode(DIRECTORY_SEPARATOR, [
"$php vendor",
"bin",
"phpstan",
]);

$this->logCommand($cmd);
$this->executeCommand($this->chainCommand($cmd), true);
}

/**
* Updates the PhpStan version.
*
Expand All @@ -575,7 +623,7 @@ public function runPhpStanUpdate(string $version): void {
* @return void
* @throws Throwable Throws an exception if an error occurs.
*/
public function runPhpunit(): void {
public function runPhpUnit(): void {

if (false === $this->hasPhpUnitConfiguration()) {
return;
Expand Down

0 comments on commit 1b4bbb7

Please sign in to comment.