Skip to content

Commit

Permalink
Merge pull request #4 from YieldStudio/grumphp-v2
Browse files Browse the repository at this point in the history
GrumPHP 2 support
  • Loading branch information
JamesHemery committed Jul 20, 2023
2 parents 873e70d + b9f4bc1 commit 51b3197
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ A [Laravel Pint](https://laravel.com/docs/9.x/pint) task for [GrumPHP](https://g

composer require yieldstudio/grumphp-laravel-pint

For GrumPHP v1 :

composer require yieldstudio/grumphp-laravel-pint:^0.0.2

## Usage

In your grumphp.yml :
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
],
"require": {
"php": "^8.0",
"phpro/grumphp": "^1.13"
"phpro/grumphp": "^2.0"
},
"autoload": {
"psr-4": {
Expand All @@ -35,7 +35,9 @@
},
"config": {
"sort-packages": true,
"allow-plugins": {}
"allow-plugins": {
"phpro/grumphp": true
}
},
"minimum-stability": "stable",
"prefer-stable": true,
Expand Down
8 changes: 8 additions & 0 deletions config/grumphp-laravel-pint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
YieldStudio\GrumPHPLaravelPint\LaravelPintTask:
class: YieldStudio\GrumPHPLaravelPint\LaravelPintTask
arguments:
- '@process_builder'
- '@formatter.raw_process'
tags:
- {name: grumphp.task, task: laravel_pint}
14 changes: 4 additions & 10 deletions src/ExtensionLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@
namespace YieldStudio\GrumPHPLaravelPint;

use GrumPHP\Extension\ExtensionInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;

class ExtensionLoader implements ExtensionInterface
{
/**
* @param ContainerBuilder $container
*/
public function load(ContainerBuilder $container): void
public function imports(): iterable
{
$container->register('task.laravel_pint', LaravelPintTask::class)
->addArgument(new Reference('process_builder'))
->addArgument(new Reference('formatter.raw_process'))
->addTag('grumphp.task', ['task' => 'laravel_pint']);
$configDir = dirname(__DIR__) . '/config';

yield $configDir . '/grumphp-laravel-pint.yaml';
}
}
7 changes: 5 additions & 2 deletions src/LaravelPintTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use GrumPHP\Runner\TaskResult;
use GrumPHP\Runner\TaskResultInterface;
use GrumPHP\Task\AbstractExternalTask;
use GrumPHP\Task\Config\ConfigOptionsResolver;
use GrumPHP\Task\Context\ContextInterface;
use GrumPHP\Task\Context\GitPreCommitContext;
use GrumPHP\Task\Context\RunContext;
Expand All @@ -28,7 +29,7 @@ public function getName(): string
return 'laravel_pint';
}

public static function getConfigurableOptions(): OptionsResolver
public static function getConfigurableOptions(): ConfigOptionsResolver
{
$resolver = new OptionsResolver();
$resolver->setDefaults([
Expand All @@ -47,7 +48,9 @@ public static function getConfigurableOptions(): OptionsResolver
$resolver->addAllowedTypes('triggered_by', ['array']);
$resolver->addAllowedTypes('ignore_patterns', ['array']);

return $resolver;
return ConfigOptionsResolver::fromClosure(
static fn (array $options): array => $resolver->resolve($options)
);
}

public function canRunInContext(ContextInterface $context): bool
Expand Down

0 comments on commit 51b3197

Please sign in to comment.