-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trait to check if a given context is allowed in git_stage
- Loading branch information
1 parent
508ad78
commit 7c297e8
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GrumPHP\Task; | ||
|
||
use GrumPHP\Task\Context\ContextInterface; | ||
use GrumPHP\Task\Context\GitPreCommitContext; | ||
use GrumPHP\Task\Context\GitPrePushContext; | ||
|
||
trait GitContextTrait | ||
{ | ||
protected function isGitContextAllowed(ContextInterface $context): bool | ||
{ | ||
\assert($this instanceof TaskInterface); | ||
$gitStage = match (true) { | ||
$context instanceof GitPreCommitContext => 'pre-commit', | ||
$context instanceof GitPrePushContext => 'pre-push', | ||
default => null, | ||
}; | ||
return in_array($gitStage, $this->getConfig()->getMetadata()->gitStages(), true); | ||
} | ||
} |