Skip to content

Commit f189d95

Browse files
committed
Upgrade docs
1 parent c5cd314 commit f189d95

Some content is hidden

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

58 files changed

+268
-129
lines changed

README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ You can specify a custom config filename and location in `composer.json` or in t
7272

7373
```yaml
7474
# grumphp.yml
75-
parameters:
75+
grumphp:
7676
hooks_dir: ~
7777
hooks_preset: local
7878
git_hook_variables:
@@ -86,6 +86,12 @@ parameters:
8686
ascii:
8787
failed: grumphp-grumpy.txt
8888
succeeded: grumphp-happy.txt
89+
parallel:
90+
enabled: true
91+
max_size: 32
92+
fixer:
93+
enabled: true
94+
fix_by_default: false
8995
tasks: {}
9096
testsuites: []
9197
extensions: []
@@ -97,7 +103,7 @@ Details of the configuration are broken down into the following sections.
97103
- [Tasks](doc/tasks.md) – External tasks performing code validation and their respective configurations.
98104
- [TestSuites](doc/testsuites.md)
99105
- [Extensions](doc/extensions.md)
100-
- [Events](doc/events.md)
106+
- [Extending the TaskRunner](doc/runner.md)
101107
- [Conventions checker](doc/conventions.md)
102108
103109
## Commands

doc/conventions.md

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Sample conventions grumphp file:
4545
# Convention grumphp.yml
4646
parameters:
4747
convention.git_commit_message_matchers: ['/.*/']
48+
grumphp:
4849
tasks:
4950
phpunit: ~
5051
git_commit_message:

doc/events.md

-34
This file was deleted.

doc/extensions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The configuration looks like this:
88

99
```yaml
1010
# grumphp.yml
11-
parameters:
11+
grumphp:
1212
extensions:
1313
- My\Project\GrumPHPExtension
1414
```

doc/faq.md

-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
## Table of content
44
- [How can I bypass GrumPHP](#how-can-i-bypass-grumphp)
55
- [Which parts of the code does GrumPHP scan?](#which-parts-of-the-code-does-grumphp-scan)
6-
- [Does GrumPHP support automatic fixing](#does-grumphp-support-automatic-fixing)
76
- [Does GrumPHP support Windows](#does-grumphp-support-windows)
87
- [How can I fix Composer require conflicts?](#how-can-i-fix-composer-require-conflicts)
98
- [Why is the unstaged file state being used?](#why-is-the-unstaged-file-state-being-used)
@@ -34,14 +33,6 @@ that are able to check only the committed lines.
3433
[up](#table-of-content)
3534

3635

37-
## Does GrumPHP support automatic fixing
38-
39-
No, he doesn't fix things for you. He wants you to have full
40-
control of the code you commit and not manipulate it in any way.
41-
42-
[up](#table-of-content)
43-
44-
4536
## Does GrumPHP support Windows
4637

4738
Yes, he does. But there are some limitations.

doc/parameters.md

+67-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
```yaml
44
# grumphp.yml
5-
parameters:
5+
grumphp:
66
hooks_dir: ~
77
hooks_preset: local
88
git_hook_variables:
@@ -17,6 +17,12 @@ parameters:
1717
ascii:
1818
failed: resource/grumphp-grumpy.txt
1919
succeeded: resource/grumphp-happy.txt
20+
parallel:
21+
enabled: true
22+
max_size: 32
23+
fixer:
24+
enabled: true
25+
fix_by_default: false
2026
```
2127
2228
**hooks_dir**
@@ -49,7 +55,7 @@ This parameter will allow you to customize git hooks templates. For now, those p
4955
Examples:
5056

5157
```yaml
52-
parameters:
58+
grumphp:
5359
git_hook_variables:
5460
EXEC_GRUMPHP_COMMAND: '/usr/local/bin/php72'
5561
EXEC_GRUMPHP_COMMAND: 'lando php'
@@ -99,7 +105,7 @@ This parameter will display additional information at the end of a `success` *or
99105

100106
```yaml
101107
# grumphp.yml
102-
parameters:
108+
grumphp:
103109
additional_info: "\nTo get full documentation for the project!\nVisit https://docs.example.com\n"
104110
```
105111

@@ -126,7 +132,7 @@ from the list.
126132
127133
```yaml
128134
# grumphp.yml
129-
parameters:
135+
grumphp:
130136
ascii:
131137
failed:
132138
- resource/grumphp-grumpy.txt
@@ -142,15 +148,70 @@ To disable all banners set ascii to `~`:
142148

143149
```yaml
144150
# grumphp.yml
145-
parameters:
151+
grumphp:
146152
ascii: ~
147153
```
148154
149155
To disable a specific banner set ascii image path to `~`:
150156

151157
```yaml
152158
# grumphp.yml
153-
parameters:
159+
grumphp:
154160
ascii:
155161
succeeded: ~
156162
```
163+
164+
165+
**parallel**
166+
167+
The parallel section can be used to configure how parallel execution works inside GrumPHP.
168+
You can specify following options:
169+
170+
```
171+
grumphp:
172+
parallel:
173+
enabled: true
174+
max_size: 32
175+
```
176+
177+
**parallel.enabled**
178+
179+
*Default: true*
180+
181+
You can choose to enable or disable the parallel execution.
182+
If for some reason parallel tasks don't work for you, you can choose to run them in sequence.
183+
184+
185+
**parallel.max_size**
186+
187+
*Default: 32*
188+
189+
The maximum size of parallel threads.
190+
191+
192+
**fixer**
193+
194+
GrumPHP provides a way of fixing your code.
195+
However, we won't automatically commit the changes, so that you have the chance to review what has been fixed!
196+
You can configure how fixers work with following config:
197+
198+
```
199+
grumphp:
200+
fixer:
201+
enabled: true
202+
fix_by_default: false
203+
```
204+
205+
**fixer.enabled**
206+
207+
*Default: true*
208+
209+
You can choose to enable or disable built-in fixers.
210+
211+
212+
**fixer.fix_by_default**
213+
214+
*Default: false*
215+
216+
In some contexts, like git commits, it is currently not possible to ask dynamic questions.
217+
Therefor, you can choose what the default answer will be.

doc/runner.md

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Extending the TaskRunner
2+
3+
## Events
4+
5+
It is possible to hook in to GrumPHP with events.
6+
Internally the Symfony event dispatcher is being used.
7+
8+
The following events are triggered during execution:
9+
10+
| Event name | Event class | Triggered
11+
| ----------------------- | --------------------- | ----------
12+
| grumphp.task.run | TaskEvent | before a task is executed
13+
| grumphp.task.failed | TaskFailedEvent | when a task fails
14+
| grumphp.task.complete | TaskEvent | when a task succeeds
15+
| grumphp.runner.run | RunnerEvent | before the tasks are executed
16+
| grumphp.runner.failed | RunnerFailedEvent | when one task failed
17+
| grumphp.runner.complete | RunnerEvent | when all tasks succeed
18+
| console.command | ConsoleCommandEvent | before a CLI command is ran
19+
| console.terminate | ConsoleTerminateEvent | before a CLI command terminates
20+
| console.exception | ConsoleExceptionEvent | when a CLI command throws an unhandled exception.
21+
22+
Configure events just like you would in Symfony:
23+
24+
```yml
25+
# grumphp.yml
26+
services:
27+
listener.some_listener:
28+
class: MyNamespace\EventListener\MyListener
29+
tags:
30+
- { name: grumphp.event_listener, event: grumphp.runner.run }
31+
- { name: grumphp.event_listener, event: grumphp.runner.run, method: customMethod, priority: 10 }
32+
listener.some_subscriber:
33+
class: MyNamespace\EventSubscriber\MySubscriber
34+
tags:
35+
- { name: grumphp.event_subscriber }
36+
```
37+
38+
## Register a RunnerMiddleware
39+
40+
A runner middleware can be used to adjust how a set of tasks is being executed.
41+
Examples are: resorting tasks, filtering tasks, logging, ....
42+
A runner middleware can be written by implementing the `RunnerMiddlewareInterface`.
43+
44+
**Example:**
45+
46+
```php
47+
use GrumPHP\Runner\Middleware\RunnerMiddlewareInterface;
48+
use GrumPHP\Collection\TaskResultCollection;
49+
use GrumPHP\Runner\TaskRunnerContext;
50+
51+
class PassThroughMiddleware implements RunnerMiddlewareInterface
52+
{
53+
/**
54+
* @param callable(TaskRunnerContext $info): TaskResultCollection $next
55+
*/
56+
public function handle(TaskRunnerContext $context, callable $next): TaskResultCollection
57+
{
58+
return $next($context);
59+
}
60+
}
61+
```
62+
63+
Configuration:
64+
65+
```yaml
66+
# grumphp.yaml
67+
68+
services:
69+
PassThroughMiddleware:
70+
tags:
71+
- { name: 'grumphp.runner_middleware', priority: 500 }
72+
```
73+
74+
75+
## Register a TaskHandlerMiddlewareInterface
76+
77+
A task handler middleware can be used to adjust how to run one single task.
78+
Examples are: event dispatching, caching, logging, ...
79+
A runner middleware works Asynchronous in order to allow parallel execution and can be written by implementing the `TaskHandlerMiddlewareInterface`.
80+
You need to return an [amp](https://github.com/amphp/amp) promise object.
81+
82+
**Example:**
83+
84+
```php
85+
use GrumPHP\Runner\TaskHandler\Middleware\TaskHandlerMiddlewareInterface;
86+
use GrumPHP\Runner\TaskResultInterface;
87+
use GrumPHP\Runner\TaskRunnerContext;
88+
use GrumPHP\Task\TaskInterface;
89+
90+
class PassThroughTaskHandlerMiddleware implements TaskHandlerMiddlewareInterface
91+
{
92+
/**
93+
* @param callable(TaskInterface, TaskRunnerContext): Promise<TaskResultInterface> $next
94+
* @return Promise<TaskResultInterface>
95+
*/
96+
public function handle(TaskInterface $task, TaskRunnerContext $runnercontext,callable $next): Promise
97+
{
98+
return $next($task, $runnercontext);
99+
}
100+
}
101+
```
102+
103+
Configuration:
104+
105+
```yaml
106+
# grumphp.yaml
107+
108+
services:
109+
PassThroughTaskHandlerMiddleware:
110+
tags:
111+
- { name: 'grumphp.task_handler', priority: 500 }
112+
```

doc/tasks.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ To activate a task, it is sufficient to add an empty task configuration:
55

66
```yaml
77
# grumphp.yml
8-
parameters:
8+
grumphp:
99
tasks:
1010
ant: ~
1111
atoum: ~
@@ -119,7 +119,7 @@ For example:
119119

120120
```yaml
121121
# grumphp.yml
122-
parameters:
122+
grumphp:
123123
tasks:
124124
anytask:
125125
metadata:
@@ -185,7 +185,7 @@ interface TaskInterface
185185

186186
```yaml
187187
# grumphp.yml
188-
parameters:
188+
grumphp:
189189
tasks:
190190
myConfigKey:
191191
config1: config-value
@@ -219,7 +219,7 @@ Configuration of the additional task will look like this:
219219

220220
```yaml
221221
# grumphp.yml
222-
parameters:
222+
grumphp:
223223
tasks:
224224
phpcsfixer2:
225225
allow_risky: true

doc/tasks/ant.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ It lives under the `ant` namespace and has following configurable parameters:
55

66
```yaml
77
# grumphp.yml
8-
parameters:
8+
grumphp:
99
tasks:
1010
ant:
1111
build_file: ~

doc/tasks/atoum.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ It lives under the `atoum` namespace and has the following configurable paramete
55

66
```yaml
77
# grumphp.yml
8-
parameters:
8+
grumphp:
99
tasks:
1010
atoum:
1111
config_file: .atoum.php

0 commit comments

Comments
 (0)