Skip to content

Commit e78eff7

Browse files
authored
Merge pull request #267 from mglaman/mglaman-patch-3
Bump PHPStan to level 2 when doing deprecations
2 parents e6b1aef + 57680ca commit e78eff7

File tree

3 files changed

+57
-42
lines changed

3 files changed

+57
-42
lines changed

Diff for: .circleci/config.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ jobs:
9999
- run:
100100
name: Global - Run against a module
101101
command: |
102-
drupal-check -vvv /tmp/drupal/core/modules/dynamic_page_cache
102+
drupal-check -vvv /tmp/drupal/core/modules/dynamic_page_cache || if (($? == 255)); then false; else true; fi
103103
test_drupal_project:
104104
<<: *defaults
105105
steps:
@@ -113,7 +113,7 @@ jobs:
113113
- run:
114114
name: Global - Run against a module
115115
command: |
116-
drupal-check -vvv /tmp/drupal/web/core/modules/dynamic_page_cache
116+
drupal-check -vvv /tmp/drupal/web/core/modules/dynamic_page_cache || if (($? == 255)); then false; else true; fi
117117
test_drupal_local_require:
118118
<<: *defaults
119119
steps:
@@ -138,7 +138,7 @@ jobs:
138138
name: Local - Run against a module
139139
command: |
140140
cd /tmp/drupal
141-
./vendor/bin/drupal-check -vvv web/core/modules/dynamic_page_cache
141+
./vendor/bin/drupal-check -vvv web/core/modules/dynamic_page_cache || if (($? == 255)); then false; else true; fi
142142
test_contrib:
143143
<<: *defaults
144144
steps:
@@ -168,7 +168,7 @@ jobs:
168168
- run:
169169
name: Run against a module
170170
command: |
171-
drupal-check -vvv /tmp/drupal/web/core/modules/dynamic_page_cache
171+
drupal-check -vvv /tmp/drupal/web/core/modules/dynamic_page_cache || if (($? == 255)); then false; else true; fi
172172
test_contained_not_initialized:
173173
<<: *defaults
174174
steps:

Diff for: README.md

+47-31
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,10 @@ Refer to Composer's documentation on how to ensure global binaries are in your P
3434

3535
## Usage
3636

37-
This tool works on all Drupal code, but must be executed within the root directory of a Drupal project..
38-
39-
### 1. cd into a Drupal Directory
40-
41-
You can run this tool within any Drupal project. But, for best results, create a fresh Drupal directory on the latest Drupal:
42-
43-
```
44-
composer create-project drupal-composer/drupal-project:8.x-dev drupal --no-interaction --stability=dev
45-
cd drupal
46-
```
47-
48-
### 2. Run drupal-check
49-
5037
Usage:
5138

5239
```
53-
drupal-check [OPTIONS] [DIRS]
40+
php vendor/bin/drupal-check [OPTIONS] [DIRS]
5441
```
5542

5643
Arguments:
@@ -69,27 +56,60 @@ Examples:
6956

7057
* Check the address contrib module:
7158

72-
```
73-
drupal-check web/modules/contrib/address
74-
```
59+
```
60+
php vendor/bin/drupal-check web/modules/contrib/address
61+
```
7562

7663
* Check the address contrib module for deprecations:
7764

78-
```
79-
drupal-check -d web/modules/contrib/address
80-
```
65+
```
66+
php vendor/bin/drupal-check -d web/modules/contrib/address
67+
```
8168

8269
* Check the address contrib module for analysis:
8370

84-
```
85-
drupal-check -a web/modules/contrib/address
86-
```
71+
```
72+
php vendor/bin/drupal-check -a web/modules/contrib/address
73+
```
8774

88-
* Check the address contrib module for both deprecations and analysis:
75+
## Rollback update to PHPStan level 2 for deprecation analysis
8976

90-
```
91-
drupal-check -ad web/modules/contrib/address
92-
```
77+
drupal-check:1.4.0 set PHPStan's analysis level to 2 for deprecations and 6 for analysis. This ensures basic analysis
78+
errors are fixed to provide the best deprecated code detection experience. You can read more about PHPStan's rule
79+
levels here: https://phpstan.org/user-guide/rule-levels
80+
81+
If you do not want to run PHPStan at level 2 and only report deprecation messages, use the following instructions
82+
83+
```shell
84+
composer remove mglaman/drupal-check
85+
composer require --dev phpstan/phpstan \
86+
phpstan/extension-installer \
87+
mglaman/phpstan-drupal \
88+
phpstan/phpstan-deprecation-rules
89+
```
90+
91+
Create a `phpstan.neon` file with the following:
92+
93+
```neon
94+
parameters:
95+
customRulesetUsed: true
96+
ignoreErrors:
97+
- '#\Drupal calls should be avoided in classes, use dependency injection instead#'
98+
- '#Plugin definitions cannot be altered.#'
99+
- '#Missing cache backend declaration for performance.#'
100+
- '#Plugin manager has cache backend specified but does not declare cache tags.#'
101+
102+
# FROM mglaman/drupal-check/phpstan/base_config.neon
103+
reportUnmatchedIgnoredErrors: false
104+
excludePaths:
105+
- */tests/Drupal/Tests/Listeners/Legacy/*
106+
- */tests/fixtures/*.php
107+
- */settings*.php
108+
- */bower_components/*
109+
- */node_modules/*
110+
```
111+
112+
You can copy this from the Upgrade Status module directly https://git.drupalcode.org/project/upgrade_status/-/blob/8.x-3.x/deprecation_testing_template.neon
93113

94114
## Drupal Check - VS Code Extension
95115

@@ -101,10 +121,6 @@ The code can be found at: https://github.com/bbeversdorf/vscode-drupal-check
101121

102122
[GPL v2](LICENSE.txt)
103123

104-
## Roadmap
105-
106-
See what feature requests are most popular in the Issue queue: https://github.com/mglaman/drupal-check/issues.
107-
108124
## Issues
109125

110126
Submit issues and feature requests here: https://github.com/mglaman/drupal-check/issues.

Diff for: src/Command/CheckCommand.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
138138
'*/settings*.php',
139139
'*/node_modules/*'
140140
],
141-
'ignoreErrors' => [],
141+
'ignoreErrors' => [
142+
'#Unsafe usage of new static\(\)#'
143+
],
142144
'drupal' => [
143145
'drupal_root' => $this->drupalRoot,
144146
]
@@ -156,14 +158,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
156158
}
157159

158160
if ($this->isAnalysisCheck) {
159-
$configuration_data['parameters']['level'] = 4;
160-
161-
$ignored_analysis_errors = [
162-
'#Unsafe usage of new static\(\)#'
163-
];
161+
$configuration_data['parameters']['level'] = 6;
162+
$ignored_analysis_errors = [];
164163
$configuration_data['parameters']['ignoreErrors'] = array_merge($ignored_analysis_errors, $configuration_data['parameters']['ignoreErrors']);
165164
} else {
166-
$configuration_data['parameters']['customRulesetUsed'] = true;
165+
$configuration_data['parameters']['level'] = 2;
167166
}
168167

169168
if ($this->isDeprecationsCheck) {

0 commit comments

Comments
 (0)