Skip to content

Commit

Permalink
Trait to check if a given context is allowed in git_stage
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiu-cristea committed May 26, 2024
1 parent 508ad78 commit 7c297e8
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Task/GitContextTrait.php
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);
}
}

0 comments on commit 7c297e8

Please sign in to comment.