-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from openeuropa/OEL-3328
OEL-3328: Add task PHPStan
- Loading branch information
Showing
7 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Editor configuration normalization | ||
# @see http://editorconfig.org/ | ||
|
||
# This is the top-most .editorconfig file; do not search in parent directories. | ||
root = true | ||
|
||
# All files. | ||
[*] | ||
end_of_line = LF | ||
indent_style = space | ||
indent_size = 4 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/vendor/ | ||
composer.lock | ||
grumphp.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Conventions | ||
|
||
Information about conventions for OpenEuropa projects and components. | ||
|
||
## Available conventions | ||
|
||
These conventions can be used in your projects: | ||
|
||
* [Drupal](dist/drupal-conventions.yml) for Drupal projects. | ||
* [OE Component](dist/oe-component-conventions.yml) for oe component projects. | ||
|
||
## PHP Code Sniffer | ||
|
||
- [Drupal coding standards](https://www.drupal.org/docs/develop/standards) | ||
except: | ||
- `Drupal.Commenting.Deprecated` because this rule only makes sense for core and projects in drupal.org. | ||
|
||
## PHP Stan | ||
|
||
- [mglaman/phpstan-drupal](https://github.com/mglaman/phpstan-drupal): allows to understand how to read code in a Drupal. | ||
- [phpstan/phpstan-deprecation-rules](https://github.com/phpstan/phpstan-deprecation-rules): this extension emits deprecation warnings on code. | ||
- [phpstan/extension-installer](https://github.com/phpstan/extension-installer): package autoconfigures PHPStan to load the previous packages. | ||
|
||
## Commit messages | ||
|
||
Valid default commit messages: `Issue #123: My commit.` or `OPENEUROPA-123: My commit.` | ||
|
||
- Must start with GitHub issue reference or a Jira-like ticket ID. | ||
- Must have a colon followed by a space after the issue reference. | ||
- Must start with capital letter and end with a period. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,116 @@ | ||
# code-review-drupal | ||
[![Packagist](https://img.shields.io/packagist/v/openeuropa/code-review-drupal.svg)](https://packagist.org/packages/openeuropa/code-review-drupal) | ||
|
||
Coding standard dependencies for Drupal components. | ||
|
||
### Installation | ||
Install the code review component via Composer: | ||
|
||
```bash | ||
composer require --dev openeuropa/code-review-drupal | ||
``` | ||
|
||
In your project root create the following `grumphp.yml.dist`: | ||
|
||
```yaml | ||
imports: | ||
- { resource: ./vendor/openeuropa/code-review-drupal/dist/drupal-conventions.yml } | ||
``` | ||
### Commands | ||
GrumPHP tasks will be run at every commit, if you wish to run them without performing a commit use the following command: | ||
```bash | ||
./vendor/bin/grumphp run | ||
``` | ||
|
||
If you want to simulate the tasks that will be run when creating a new commit: | ||
|
||
```bash | ||
./vendor/bin/grumphp git:pre-commit | ||
``` | ||
|
||
Check [GrumPHP documentation](https://github.com/phpro/grumphp/tree/master/doc) for more. | ||
|
||
### Customization | ||
|
||
This component offers a variety of ready conventions that all projects need to follow. | ||
This list of default conventions can be found in [CONVENTIONS.md](CONVENTIONS.md). | ||
|
||
Since GrumPHP uses the [Symfony Dependency Injection component](http://symfony.com/doc/current/components/dependency_injection.html) | ||
you can override specific parameters in your project's `grumphp.yml.dist` file as follows: | ||
|
||
```yaml | ||
imports: | ||
- { resource: ./vendor/openeuropa/code-review-drupal/dist/drupal-conventions.yml } | ||
|
||
parameters: | ||
tasks.git_commit_message.matchers: ['/^JIRA-\d+: [A-Z].+\./'] | ||
``` | ||
Below the list of task parameters can that be overridden on a per-project basis: | ||
- `tasks.phpcs.standard` | ||
- `tasks.phpcs.ignore_patterns` | ||
- `tasks.phpcs.triggered_by` | ||
- `tasks.phpcs.whitelist_patterns` | ||
- `tasks.phpcs.warning_severity` | ||
- `tasks.phpstan.autoload_file` | ||
- `tasks.phpstan.configuration` | ||
- `tasks.phpstan.level` | ||
- `tasks.phpstan.force_patterns` | ||
- `tasks.phpstan.triggered_by` | ||
- `tasks.git_commit_message.matchers` | ||
|
||
It is also possible to extend the list of tasks to be run by adding tasks under the `tasks:` tree as shown below: | ||
|
||
```yaml | ||
imports: | ||
- { resource: ./vendor/openeuropa/code-review-drupal/dist/drupal-conventions.yml } | ||
grumphp: | ||
tasks: | ||
phpparser: ~ | ||
``` | ||
|
||
GrumPHP already has a series of tasks that can be used out of the box, you can find the complete list in the | ||
[GrumPHP tasks page](https://github.com/phpro/grumphp/blob/v2.x/doc/tasks.md). | ||
|
||
If you wih you can create your own tasks as explained in the [GrumPHP extensions page](https://github.com/phpro/grumphp/blob/v2.x/doc/extensions.md). | ||
|
||
### Transition from code-review 2.x | ||
|
||
If you wish to transition to code-review-drupal from code-review version 2.x, please replace the package via Composer: | ||
|
||
```bash | ||
composer remove --dev openeuropa/code-review | ||
composer require --dev openeuropa/code-review-drupal | ||
``` | ||
|
||
Besides replacement of the package, some adjustments are needed in `grumphp.yml` file. | ||
|
||
This component removes ExtraTasks extension. Any aditional task previously declared in `extra_tasks` will need to be placed inside `tasks` under `grumphp` tree. | ||
|
||
```diff yaml | ||
- extra_tasks: | ||
- phpparser: | ||
- ignore_patterns: | ||
- - vendor/ | ||
- | ||
- grumphp: | ||
- extensions: | ||
- - OpenEuropa\CodeReview\ExtraTasksExtension | ||
+ grumphp: | ||
+ tasks: | ||
+ phpparser: | ||
+ ignore_patterns: | ||
+ - vendor/ | ||
``` | ||
|
||
In addition, PHP Mess Detector is no longer available as part of the configured tasks. The task and related parameters have been removed. If you wish to continue using PHP Mess Detector, you can add it as part of GrumPHP as previously described. | ||
|
||
All other conventions and parameters remain the same. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "openeuropa/code-review-drupal", | ||
"description": "OpenEuropa code review drupal component.", | ||
"license": "EUPL-1.2", | ||
"require": { | ||
"php": ">=8.1", | ||
"openeuropa/code-review": "OEL-3328-dev", | ||
"drupal/coder": "^8.3.16", | ||
"mglaman/phpstan-drupal": "^1.2", | ||
"phpstan/phpstan-deprecation-rules": "^1.2", | ||
"phpstan/extension-installer": "^1.4" | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"dealerdirect/phpcodesniffer-composer-installer": true, | ||
"phpro/grumphp-shim": true, | ||
"phpstan/extension-installer": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
imports: | ||
- { resource: ./vendor/openeuropa/code-review/dist/base-conventions.yml } | ||
|
||
grumphp: | ||
|
||
tasks: | ||
|
||
# PHP Code Sniffer. | ||
phpcs: | ||
standard: '%tasks.phpcs.standard%' | ||
ignore_patterns: '%tasks.phpcs.ignore_patterns%' | ||
triggered_by: '%tasks.phpcs.triggered_by%' | ||
whitelist_patterns: '%tasks.phpcs.whitelist_patterns%' | ||
warning_severity: '%tasks.phpcs.warning_severity%' | ||
exclude: | ||
- 'Drupal.Commenting.Deprecated' | ||
metadata: | ||
priority: 300 | ||
|
||
# PHP Stan. | ||
phpstan: | ||
autoload_file: '%tasks.phpstan.autoload_file%' | ||
configuration: '%tasks.phpstan.configuration%' | ||
level: '%tasks.phpstan.level%' | ||
force_patterns: '%tasks.phpstan.force_patterns%' | ||
ignore_patterns: '%tasks.phpstan.ignore_patterns%' | ||
triggered_by: '%tasks.phpstan.triggered_by%' | ||
memory_limit: "-1" | ||
use_grumphp_paths: true | ||
|
||
# Commit message format. | ||
git_commit_message: | ||
matchers: '%tasks.git_commit_message.matchers%' | ||
case_insensitive: false | ||
enforce_no_subject_trailing_period: false | ||
multiline: false | ||
max_body_width: 0 | ||
max_subject_width: 0 | ||
|
||
parameters: | ||
drupal-conventions.triggered_by: | ||
- php | ||
- module | ||
- inc | ||
- theme | ||
tasks.phpcs.standard: ./vendor/drupal/coder/coder_sniffer/Drupal | ||
tasks.phpcs.triggered_by: '%drupal-conventions.triggered_by%' | ||
tasks.phpstan.triggered_by: '%drupal-conventions.triggered_by%' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
imports: | ||
- { resource: drupal-conventions.yml } | ||
|
||
parameters: | ||
oe-component-conventions.triggerend_by: | ||
- inc | ||
- install | ||
- module | ||
- php | ||
- theme | ||
- yml | ||
oe-component-conventions.ignore_patterns: | ||
- build/ | ||
- vendor/ | ||
- node_modules/ | ||
tasks.phpcs.triggered_by: '%oe-component-conventions.triggerend_by%' | ||
tasks.phpcs.ignore_patterns: '%oe-component-conventions.ignore_patterns%' | ||
tasks.phpstan.triggered_by: '%oe-component-conventions.triggerend_by%' | ||
tasks.phpstan.ignore_patterns: '%oe-component-conventions.ignore_patterns%' |