Skip to content

Commit 0cb1122

Browse files
Use the new trait
1 parent c7cc1b5 commit 0cb1122

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+82
-127
lines changed

src/Task/AbstractExternalTask.php

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
*/
1515
abstract class AbstractExternalTask implements TaskInterface
1616
{
17+
use GitContextTrait;
18+
1719
/**
1820
* @var TaskConfigInterface
1921
*/

src/Task/AbstractLinterTask.php

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
abstract class AbstractLinterTask implements TaskInterface
1919
{
20+
use GitContextTrait;
21+
2022
/**
2123
* @var TaskConfigInterface
2224
*/

src/Task/AbstractParserTask.php

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
abstract class AbstractParserTask implements TaskInterface
1919
{
20+
use GitContextTrait;
21+
2022
/**
2123
* @var TaskConfigInterface
2224
*/

src/Task/Ant.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use GrumPHP\Runner\TaskResultInterface;
1010
use GrumPHP\Task\Config\ConfigOptionsResolver;
1111
use GrumPHP\Task\Context\ContextInterface;
12-
use GrumPHP\Task\Context\GitPreCommitContext;
1312
use GrumPHP\Task\Context\RunContext;
1413
use Symfony\Component\OptionsResolver\OptionsResolver;
1514

@@ -36,7 +35,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
3635

3736
public function canRunInContext(ContextInterface $context): bool
3837
{
39-
return $context instanceof GitPreCommitContext || $context instanceof RunContext;
38+
return $this->isGitContextAllowed($context) || $context instanceof RunContext;
4039
}
4140

4241
public function run(ContextInterface $context): TaskResultInterface

src/Task/Atoum.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use GrumPHP\Runner\TaskResultInterface;
1010
use GrumPHP\Task\Config\ConfigOptionsResolver;
1111
use GrumPHP\Task\Context\ContextInterface;
12-
use GrumPHP\Task\Context\GitPreCommitContext;
1312
use GrumPHP\Task\Context\RunContext;
1413
use Symfony\Component\OptionsResolver\OptionsResolver;
1514

@@ -47,7 +46,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
4746
*/
4847
public function canRunInContext(ContextInterface $context): bool
4948
{
50-
return $context instanceof GitPreCommitContext || $context instanceof RunContext;
49+
return $this->isGitContextAllowed($context) || $context instanceof RunContext;
5150
}
5251

5352
/**

src/Task/Behat.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use GrumPHP\Runner\TaskResultInterface;
1010
use GrumPHP\Task\Config\ConfigOptionsResolver;
1111
use GrumPHP\Task\Context\ContextInterface;
12-
use GrumPHP\Task\Context\GitPreCommitContext;
1312
use GrumPHP\Task\Context\RunContext;
1413
use Symfony\Component\OptionsResolver\OptionsResolver;
1514

@@ -43,7 +42,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
4342
*/
4443
public function canRunInContext(ContextInterface $context): bool
4544
{
46-
return $context instanceof GitPreCommitContext || $context instanceof RunContext;
45+
return $this->isGitContextAllowed($context) || $context instanceof RunContext;
4746
}
4847

4948
/**

src/Task/Brunch.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use GrumPHP\Runner\TaskResultInterface;
1010
use GrumPHP\Task\Config\ConfigOptionsResolver;
1111
use GrumPHP\Task\Context\ContextInterface;
12-
use GrumPHP\Task\Context\GitPreCommitContext;
1312
use GrumPHP\Task\Context\RunContext;
1413
use Symfony\Component\OptionsResolver\OptionsResolver;
1514

@@ -43,7 +42,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
4342
*/
4443
public function canRunInContext(ContextInterface $context): bool
4544
{
46-
return $context instanceof GitPreCommitContext || $context instanceof RunContext;
45+
return $this->isGitContextAllowed($context) || $context instanceof RunContext;
4746
}
4847

4948
/**

src/Task/CloverCoverage.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use GrumPHP\Task\Config\EmptyTaskConfig;
1111
use GrumPHP\Task\Config\TaskConfigInterface;
1212
use GrumPHP\Task\Context\ContextInterface;
13-
use GrumPHP\Task\Context\GitPreCommitContext;
1413
use GrumPHP\Task\Context\RunContext;
1514
use GrumPHP\Util\Filesystem;
1615
use SimpleXMLElement;
@@ -19,6 +18,8 @@
1918

2019
class CloverCoverage implements TaskInterface
2120
{
21+
use GitContextTrait;
22+
2223
/**
2324
* @var Filesystem
2425
*/
@@ -72,7 +73,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
7273
*/
7374
public function canRunInContext(ContextInterface $context): bool
7475
{
75-
return $context instanceof GitPreCommitContext || $context instanceof RunContext;
76+
return $this->isGitContextAllowed($context) || $context instanceof RunContext;
7677
}
7778

7879
/**

src/Task/Codeception.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use GrumPHP\Runner\TaskResultInterface;
1010
use GrumPHP\Task\Config\ConfigOptionsResolver;
1111
use GrumPHP\Task\Context\ContextInterface;
12-
use GrumPHP\Task\Context\GitPreCommitContext;
1312
use GrumPHP\Task\Context\RunContext;
1413
use Symfony\Component\OptionsResolver\OptionsResolver;
1514

@@ -45,7 +44,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
4544
*/
4645
public function canRunInContext(ContextInterface $context): bool
4746
{
48-
return $context instanceof GitPreCommitContext || $context instanceof RunContext;
47+
return $this->isGitContextAllowed($context) || $context instanceof RunContext;
4948
}
5049

5150
/**

src/Task/Composer.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use GrumPHP\Runner\TaskResultInterface;
1111
use GrumPHP\Task\Config\ConfigOptionsResolver;
1212
use GrumPHP\Task\Context\ContextInterface;
13-
use GrumPHP\Task\Context\GitPreCommitContext;
1413
use GrumPHP\Task\Context\RunContext;
1514
use GrumPHP\Util\Filesystem;
1615
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -61,7 +60,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
6160

6261
public function canRunInContext(ContextInterface $context): bool
6362
{
64-
return $context instanceof GitPreCommitContext || $context instanceof RunContext;
63+
return $this->isGitContextAllowed($context) || $context instanceof RunContext;
6564
}
6665

6766
public function run(ContextInterface $context): TaskResultInterface

src/Task/ComposerNormalize.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use GrumPHP\Runner\TaskResultInterface;
99
use GrumPHP\Task\Config\ConfigOptionsResolver;
1010
use GrumPHP\Task\Context\ContextInterface;
11-
use GrumPHP\Task\Context\GitPreCommitContext;
1211
use GrumPHP\Task\Context\RunContext;
1312
use Symfony\Component\OptionsResolver\OptionsResolver;
1413
use Symfony\Component\Process\Process;
@@ -20,7 +19,7 @@ class ComposerNormalize extends AbstractExternalTask
2019
{
2120
public function canRunInContext(ContextInterface $context): bool
2221
{
23-
return $context instanceof GitPreCommitContext || $context instanceof RunContext;
22+
return $this->isGitContextAllowed($context) || $context instanceof RunContext;
2423
}
2524

2625
public static function getConfigurableOptions(): ConfigOptionsResolver

src/Task/ComposerRequireChecker.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use GrumPHP\Runner\TaskResultInterface;
1010
use GrumPHP\Task\Config\ConfigOptionsResolver;
1111
use GrumPHP\Task\Context\ContextInterface;
12-
use GrumPHP\Task\Context\GitPreCommitContext;
1312
use GrumPHP\Task\Context\RunContext;
1413
use Symfony\Component\OptionsResolver\OptionsResolver;
1514

@@ -41,7 +40,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
4140
*/
4241
public function canRunInContext(ContextInterface $context): bool
4342
{
44-
return $context instanceof GitPreCommitContext || $context instanceof RunContext;
43+
return $this->isGitContextAllowed($context) || $context instanceof RunContext;
4544
}
4645

4746
/**

src/Task/ComposerScript.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use GrumPHP\Runner\TaskResultInterface;
1010
use GrumPHP\Task\Config\ConfigOptionsResolver;
1111
use GrumPHP\Task\Context\ContextInterface;
12-
use GrumPHP\Task\Context\GitPreCommitContext;
1312
use GrumPHP\Task\Context\RunContext;
1413
use Symfony\Component\OptionsResolver\OptionsResolver;
1514

@@ -39,7 +38,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
3938
*/
4039
public function canRunInContext(ContextInterface $context): bool
4140
{
42-
return $context instanceof GitPreCommitContext || $context instanceof RunContext;
41+
return $this->isGitContextAllowed($context) || $context instanceof RunContext;
4342
}
4443

4544
/**

src/Task/Deptrac.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use GrumPHP\Runner\TaskResultInterface;
1010
use GrumPHP\Task\Config\ConfigOptionsResolver;
1111
use GrumPHP\Task\Context\ContextInterface;
12-
use GrumPHP\Task\Context\GitPreCommitContext;
1312
use GrumPHP\Task\Context\RunContext;
1413
use Symfony\Component\OptionsResolver\OptionsResolver;
1514

@@ -38,7 +37,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
3837

3938
public function canRunInContext(ContextInterface $context): bool
4039
{
41-
return $context instanceof GitPreCommitContext || $context instanceof RunContext;
40+
return $this->isGitContextAllowed($context) || $context instanceof RunContext;
4241
}
4342

4443
public function run(ContextInterface $context): TaskResultInterface

src/Task/DoctrineOrm.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use GrumPHP\Runner\TaskResultInterface;
1010
use GrumPHP\Task\Config\ConfigOptionsResolver;
1111
use GrumPHP\Task\Context\ContextInterface;
12-
use GrumPHP\Task\Context\GitPreCommitContext;
1312
use GrumPHP\Task\Context\RunContext;
1413
use Symfony\Component\OptionsResolver\OptionsResolver;
1514

@@ -39,7 +38,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
3938
*/
4039
public function canRunInContext(ContextInterface $context): bool
4140
{
42-
return $context instanceof GitPreCommitContext || $context instanceof RunContext;
41+
return $this->isGitContextAllowed($context) || $context instanceof RunContext;
4342
}
4443

4544
/**

src/Task/ESLint.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use GrumPHP\Runner\TaskResultInterface;
1212
use GrumPHP\Task\Config\ConfigOptionsResolver;
1313
use GrumPHP\Task\Context\ContextInterface;
14-
use GrumPHP\Task\Context\GitPreCommitContext;
1514
use GrumPHP\Task\Context\RunContext;
1615
use Symfony\Component\OptionsResolver\Options;
1716
use Symfony\Component\OptionsResolver\OptionsResolver;
@@ -60,7 +59,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
6059

6160
public function canRunInContext(ContextInterface $context): bool
6261
{
63-
return ($context instanceof GitPreCommitContext || $context instanceof RunContext);
62+
return ($this->isGitContextAllowed($context) || $context instanceof RunContext);
6463
}
6564

6665
public function run(ContextInterface $context): TaskResultInterface

src/Task/Ecs.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use GrumPHP\Runner\TaskResultInterface;
1313
use GrumPHP\Task\Config\ConfigOptionsResolver;
1414
use GrumPHP\Task\Context\ContextInterface;
15-
use GrumPHP\Task\Context\GitPreCommitContext;
1615
use GrumPHP\Task\Context\RunContext;
1716
use Symfony\Component\OptionsResolver\OptionsResolver;
1817
use Symfony\Component\Process\Process;
@@ -48,7 +47,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
4847

4948
public function canRunInContext(ContextInterface $context): bool
5049
{
51-
return $context instanceof GitPreCommitContext || $context instanceof RunContext;
50+
return $this->isGitContextAllowed($context) || $context instanceof RunContext;
5251
}
5352

5453
public function run(ContextInterface $context): TaskResultInterface
@@ -102,7 +101,7 @@ private function addPaths(
102101
FilesCollection $files,
103102
array $config
104103
): void {
105-
if ($context instanceof GitPreCommitContext && $config['files_on_pre_commit']) {
104+
if ($this->isGitContextAllowed($context) && $config['files_on_pre_commit']) {
106105
$arguments->addFiles($files);
107106
return;
108107
}

src/Task/FileSize.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
use GrumPHP\Task\Config\EmptyTaskConfig;
1111
use GrumPHP\Task\Config\TaskConfigInterface;
1212
use GrumPHP\Task\Context\ContextInterface;
13-
use GrumPHP\Task\Context\GitPreCommitContext;
1413
use GrumPHP\Task\Context\RunContext;
1514
use Symfony\Component\OptionsResolver\OptionsResolver;
1615

1716
class FileSize implements TaskInterface
1817
{
18+
use GitContextTrait;
19+
1920
/**
2021
* @var TaskConfigInterface
2122
*/
@@ -55,7 +56,7 @@ public function withConfig(TaskConfigInterface $config): TaskInterface
5556

5657
public function canRunInContext(ContextInterface $context): bool
5758
{
58-
return $context instanceof RunContext || $context instanceof GitPreCommitContext;
59+
return $context instanceof RunContext || $this->isGitContextAllowed($context);
5960
}
6061

6162
public function run(ContextInterface $context): TaskResultInterface

src/Task/Gherkin.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use GrumPHP\Runner\TaskResultInterface;
1010
use GrumPHP\Task\Config\ConfigOptionsResolver;
1111
use GrumPHP\Task\Context\ContextInterface;
12-
use GrumPHP\Task\Context\GitPreCommitContext;
1312
use GrumPHP\Task\Context\RunContext;
1413
use Symfony\Component\OptionsResolver\OptionsResolver;
1514

@@ -38,7 +37,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
3837
*/
3938
public function canRunInContext(ContextInterface $context): bool
4039
{
41-
return $context instanceof GitPreCommitContext || $context instanceof RunContext;
40+
return $this->isGitContextAllowed($context) || $context instanceof RunContext;
4241
}
4342

4443
/**

src/Task/Git/Blacklist.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use GrumPHP\Task\AbstractExternalTask;
1313
use GrumPHP\Task\Config\ConfigOptionsResolver;
1414
use GrumPHP\Task\Context\ContextInterface;
15-
use GrumPHP\Task\Context\GitPreCommitContext;
1615
use Symfony\Component\OptionsResolver\OptionsResolver;
1716

1817
/**
@@ -63,7 +62,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
6362

6463
public function canRunInContext(ContextInterface $context): bool
6564
{
66-
return $context instanceof GitPreCommitContext;
65+
return $this->isGitContextAllowed($context);
6766
}
6867

6968
public function run(ContextInterface $context): TaskResultInterface

src/Task/Git/BranchName.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@
1212
use GrumPHP\Task\Config\EmptyTaskConfig;
1313
use GrumPHP\Task\Config\TaskConfigInterface;
1414
use GrumPHP\Task\Context\ContextInterface;
15-
use GrumPHP\Task\Context\GitPreCommitContext;
1615
use GrumPHP\Task\Context\RunContext;
16+
use GrumPHP\Task\GitContextTrait;
1717
use GrumPHP\Util\Regex;
1818
use GrumPHP\Task\TaskInterface;
1919
use Symfony\Component\OptionsResolver\OptionsResolver;
2020

2121
class BranchName implements TaskInterface
2222
{
23+
use GitContextTrait;
24+
2325
/**
2426
* @var TaskConfigInterface
2527
*/
@@ -69,7 +71,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
6971

7072
public function canRunInContext(ContextInterface $context): bool
7173
{
72-
return $context instanceof RunContext || $context instanceof GitPreCommitContext;
74+
return $context instanceof RunContext || $this->isGitContextAllowed($context);
7375
}
7476

7577
public function run(ContextInterface $context): TaskResultInterface

src/Task/Grunt.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use GrumPHP\Runner\TaskResultInterface;
1010
use GrumPHP\Task\Config\ConfigOptionsResolver;
1111
use GrumPHP\Task\Context\ContextInterface;
12-
use GrumPHP\Task\Context\GitPreCommitContext;
1312
use GrumPHP\Task\Context\RunContext;
1413
use Symfony\Component\OptionsResolver\OptionsResolver;
1514

@@ -39,7 +38,7 @@ public static function getConfigurableOptions(): ConfigOptionsResolver
3938
*/
4039
public function canRunInContext(ContextInterface $context): bool
4140
{
42-
return $context instanceof GitPreCommitContext || $context instanceof RunContext;
41+
return $this->isGitContextAllowed($context) || $context instanceof RunContext;
4342
}
4443

4544
/**

0 commit comments

Comments
 (0)