Skip to content
Snippets Groups Projects
Commit f095afad authored by danielspeicher's avatar danielspeicher
Browse files

Document Drupal Development Env: composer/plugin/drupal-development-environment#1

parent 6920b079
No related branches found
No related tags found
1 merge request!6Develop
...@@ -15,7 +15,7 @@ It provides a massive amount of testing tools, which can be executed out of the ...@@ -15,7 +15,7 @@ It provides a massive amount of testing tools, which can be executed out of the
- [Dependency Analysis](../../../dev_tools/test.md#drupal-dependency-analysis) - [Dependency Analysis](../../../dev_tools/test.md#drupal-dependency-analysis)
- [PHP Unit](../../../dev_tools/test.md#unitkernelfunctional-testing) - [PHP Unit](../../../dev_tools/test.md#unitkernelfunctional-testing)
- [PHP Code Sniffer](../../../dev_tools/test.md#php-code-sniffer) - [PHP Code Sniffer](../../../dev_tools/test.md#php-code-sniffer)
- [PHP PHPStan](../../../dev_tools/test.md#php-code-sniffer) - [PHP PHPStan](../../../dev_tools/test.md#php-stan)
- [PHP Lint](../../../dev_tools/test.md#php-code-sniffer) - [PHP Lint](../../../dev_tools/test.md#php-code-sniffer)
- [PHP LOC](../../../dev_tools/test.md#php-loc) - [PHP LOC](../../../dev_tools/test.md#php-loc)
- [PHP Mess Detection](../../../dev_tools/test.md#php-mess-detection) - [PHP Mess Detection](../../../dev_tools/test.md#php-mess-detection)
......
...@@ -42,24 +42,95 @@ drupal/blazy 2.16.0 2.27.0 Provides.. ...@@ -42,24 +42,95 @@ drupal/blazy 2.16.0 2.27.0 Provides..
We have several tools to perform static code analysis. We have several tools to perform static code analysis.
* Code Sniffer - [PHP Code Sniffer](#php-code-sniffer)
* PHP LOC - [PHP PHPStan](#php-stan)
* Mess Detection - [PHP Lint](#php-code-sniffer)
- [PHP LOC](#php-loc)
- [PHP Mess Detection](../../../dev_tools/test.md#php-mess-detection)
- [PHP Copy and Paste Detector](../../../dev_tools/test.md#php-code-sniffer)
- [PHP Metrics](../../../dev_tools/test.md#php-code-sniffer)
- [PHP Stylelint](../../../dev_tools/test.md#php-code-sniffer)
- [Eslint](../../../dev_tools/test.md#php-code-sniffer)
### PHP Code Sniffer ### PHP Code Sniffer
PHP Code Sniffer performs a static code analysis with a specific Drupal profile. It detects PHP Code Sniffer performs a static code analysis with a specific Drupal profile. It detects
code smells like static calls. code smells like static calls.
To execute PHP Code Sniffer on the console: You can execute PHP CS for a specific Drupal contrib module:
```l3d ```phpcs
a test phpcsmodule <contrib_module>
```
Now the entire code in that module will be analysed.
If you want to analyse a custom module, just do the following:
```phpcs
a test phpcsmodule ../custom/<custom_module>
```
To execute PHP Code Sniffer for a file or directory:
```phpcs
a test phpcs <file_ordirectory> a test phpcs <file_ordirectory>
``` ```
Whether it is a directory, it runs the analysis for everything under this directory Whether it is a directory, it runs the analysis for everything under this directory
recursively. recursively.
Note: **There are many errors, which can be fixed automatically.** If you see something like this:
```phpcs
FILE: /var/www/html/web/modules/contrib/eca/src/Entity/Model.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
37 | ERROR | [x] Additional blank lines found at end of doc comment
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
```
You can just execute:
```phpcs
a test phpcs-fix <contrib_module>
```
Now th errors are gone, which saves a lot of time and effort.
### PHP Stan
We use level 6 as default, which is pretty good and strict and provides a very clean code. You can adjust this in the
`phpstan.neon` file. It looks like this:
```phpstan
parameters:
level: 6
```
It is recommended to have such a file in every module located in its root path.
You can execute PHP Stan for a specific Drupal contrib module:
```phpstan
a test phpstanmodule <contrib_module>
```
Now the entire code in that module will be analysed.
If you want to analyse a custom module, just do the following:
```phpstan
a test phpstanmodule ../custom/<custom_module>
```
To execute PHP Stan for a file or directory:
```phpstan
a test phpstan <file_ordirectory>
```
Whether it is a directory, it runs the analysis for everything under this directory Whether it is a directory, it runs the analysis for everything under this directory
recursively. recursively.
...@@ -69,7 +140,7 @@ PHP LOC prints several metrics about your code, like the average size of a class ...@@ -69,7 +140,7 @@ PHP LOC prints several metrics about your code, like the average size of a class
To execute PHP LOC on the console: To execute PHP LOC on the console:
```l3d ```phploc
a test phploc <file_ordirectory> a test phploc <file_ordirectory>
``` ```
...@@ -84,9 +155,9 @@ uses several profiles like: ...@@ -84,9 +155,9 @@ uses several profiles like:
This analysis detects also code smells like the complexity (e.g. number of This analysis detects also code smells like the complexity (e.g. number of
dependencies) of classes. dependencies) of classes.
To execute PHP Code Sniffer on the console: To execute PHP Mess Detection on the console:
```l3d ```phpmd
a test phpmd <file_ordirectory> json <profile> a test phpmd <file_ordirectory> json <profile>
``` ```
...@@ -97,7 +168,7 @@ recursively. ...@@ -97,7 +168,7 @@ recursively.
To execute the tests, you can use a single command: To execute the tests, you can use a single command:
```l3d ```phpunit
a test phpunit <file_ordirectory> a test phpunit <file_ordirectory>
``` ```
...@@ -144,7 +215,7 @@ You can also use the execution with the debugger. ...@@ -144,7 +215,7 @@ You can also use the execution with the debugger.
First, activate the coverage option: First, activate the coverage option:
```l3d ```debug
a debug coverage a debug coverage
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment