Skip to content

Commit 75d2c30

Browse files
authored
Merge pull request #13 from pluswerk/feature/grumphp-0.19
✨ make bom fixer task compatible with grumphp 0.19
2 parents 02bce40 + 8921601 commit 75d2c30

5 files changed

Lines changed: 39 additions & 29 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ git:
88
php:
99
- 7.2
1010
- 7.3
11+
- 7.4
1112
- nightly
1213

1314
env:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"require": {
2828
"php": ">=7.2",
29-
"phpro/grumphp": "0.16.* || 0.17.*"
29+
"phpro/grumphp": "0.19.*"
3030
},
3131
"require-dev": {
3232
"squizlabs/php_codesniffer": ">=3.5.0 <4.0.0"

grumphp.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
parameters:
2-
git_dir: .
3-
bin_dir: vendor/bin
4-
stop_on_failure: false
5-
ignore_unstaged_changes: false #brocken
1+
grumphp:
62
tasks:
73
composer:
84
with_dependencies: false
@@ -21,7 +17,7 @@ parameters:
2117
detect_key_conflicts: true
2218
phpcs:
2319
standard: "PSR12"
24-
warning_severity: 900000
20+
warning_severity: 0
2521
tab_width: 4
2622
yamllint: ~
2723
plus_bom_fixer:

src/BomFixerTask.php

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,25 @@
44

55
use GrumPHP\Runner\TaskResult;
66
use GrumPHP\Runner\TaskResultInterface;
7-
use GrumPHP\Task\AbstractExternalTask;
7+
use GrumPHP\Task\Config\EmptyTaskConfig;
8+
use GrumPHP\Task\Config\TaskConfigInterface;
89
use GrumPHP\Task\Context\ContextInterface;
910
use GrumPHP\Task\Context\GitPreCommitContext;
1011
use GrumPHP\Task\Context\RunContext;
12+
use GrumPHP\Task\TaskInterface;
1113
use Symfony\Component\OptionsResolver\OptionsResolver;
1214

13-
class BomFixerTask extends AbstractExternalTask
15+
final class BomFixerTask implements TaskInterface
1416
{
15-
public function getName(): string
17+
/** @var TaskConfigInterface */
18+
private $config;
19+
20+
public function __construct()
1621
{
17-
return 'plus_bom_fixer';
22+
$this->config = new EmptyTaskConfig();
1823
}
1924

20-
public function getConfigurableOptions(): OptionsResolver
25+
public static function getConfigurableOptions(): OptionsResolver
2126
{
2227
$resolver = new OptionsResolver();
2328
$resolver->setDefaults(
@@ -31,15 +36,27 @@ public function getConfigurableOptions(): OptionsResolver
3136
return $resolver;
3237
}
3338

39+
public function getConfig(): TaskConfigInterface
40+
{
41+
return $this->config;
42+
}
43+
44+
public function withConfig(TaskConfigInterface $config): TaskInterface
45+
{
46+
$new = clone $this;
47+
$new->config = $config;
48+
49+
return $new;
50+
}
51+
3452
public function canRunInContext(ContextInterface $context): bool
3553
{
36-
return ($context instanceof GitPreCommitContext || $context instanceof RunContext);
54+
return $context instanceof RunContext || $context instanceof GitPreCommitContext;
3755
}
3856

3957
public function run(ContextInterface $context): TaskResultInterface
4058
{
41-
$config = $this->getConfiguration();
42-
$files = $context->getFiles()->extensions($config['triggered_by']);
59+
$files = $context->getFiles()->extensions($this->config->getOptions()['triggered_by']);
4360
if (0 === count($files)) {
4461
return TaskResult::createSkipped($this, $context);
4562
}
@@ -64,18 +81,20 @@ public function run(ContextInterface $context): TaskResultInterface
6481
}
6582

6683
if (count($shouldGetFixedLog) > 0) {
67-
return TaskResult::createFailed(
68-
$this,
69-
$context,
70-
implode(PHP_EOL, $shouldGetFixedLog) . PHP_EOL
84+
$errorMessage = implode(PHP_EOL, $shouldGetFixedLog) . PHP_EOL
7185
. 'you can use this to fix them:' . PHP_EOL
72-
. $fixCommand
73-
);
86+
. $fixCommand;
87+
return TaskResult::createFailed($this, $context, $errorMessage);
7488
}
7589
return TaskResult::createPassed($this, $context);
7690
}
7791

78-
protected function fileInfoSearch(string $filename, string $search): bool
92+
private function isFileWithBOM(string $filename): bool
93+
{
94+
return $this->fileInfoSearch($filename, 'BOM');
95+
}
96+
97+
private function fileInfoSearch(string $filename, string $search): bool
7998
{
8099
$output = [];
81100
exec('file ' . '"' . $filename . '"', $output, $returnVar);
@@ -84,9 +103,4 @@ protected function fileInfoSearch(string $filename, string $search): bool
84103
}
85104
return false;
86105
}
87-
88-
public function isFileWithBOM(string $filename): bool
89-
{
90-
return $this->fileInfoSearch($filename, 'BOM');
91-
}
92106
}

src/ExtensionLoader.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ class ExtensionLoader implements ExtensionInterface
1111
public function load(ContainerBuilder $container)
1212
{
1313
return $container->register('task.plus_bom_fixer', BomFixerTask::class)
14-
->addArgument(new Reference('config'))
1514
->addArgument(new Reference('process_builder'))
1615
->addArgument(new Reference('formatter.raw_process'))
17-
->addTag('grumphp.task', ['config' => 'plus_bom_fixer']);
16+
->addTag('grumphp.task', ['task' => 'plus_bom_fixer']);
1817
}
1918
}

0 commit comments

Comments
 (0)