Skip to content

Commit

Permalink
Merge pull request #267 from mglaman/mglaman-patch-3
Browse files Browse the repository at this point in the history
Bump PHPStan to level 2 when doing deprecations
  • Loading branch information
mglaman authored Apr 29, 2022
2 parents e6b1aef + 57680ca commit e78eff7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 42 deletions.
8 changes: 4 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ jobs:
- run:
name: Global - Run against a module
command: |
drupal-check -vvv /tmp/drupal/core/modules/dynamic_page_cache
drupal-check -vvv /tmp/drupal/core/modules/dynamic_page_cache || if (($? == 255)); then false; else true; fi
test_drupal_project:
<<: *defaults
steps:
Expand All @@ -113,7 +113,7 @@ jobs:
- run:
name: Global - Run against a module
command: |
drupal-check -vvv /tmp/drupal/web/core/modules/dynamic_page_cache
drupal-check -vvv /tmp/drupal/web/core/modules/dynamic_page_cache || if (($? == 255)); then false; else true; fi
test_drupal_local_require:
<<: *defaults
steps:
Expand All @@ -138,7 +138,7 @@ jobs:
name: Local - Run against a module
command: |
cd /tmp/drupal
./vendor/bin/drupal-check -vvv web/core/modules/dynamic_page_cache
./vendor/bin/drupal-check -vvv web/core/modules/dynamic_page_cache || if (($? == 255)); then false; else true; fi
test_contrib:
<<: *defaults
steps:
Expand Down Expand Up @@ -168,7 +168,7 @@ jobs:
- run:
name: Run against a module
command: |
drupal-check -vvv /tmp/drupal/web/core/modules/dynamic_page_cache
drupal-check -vvv /tmp/drupal/web/core/modules/dynamic_page_cache || if (($? == 255)); then false; else true; fi
test_contained_not_initialized:
<<: *defaults
steps:
Expand Down
78 changes: 47 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,10 @@ Refer to Composer's documentation on how to ensure global binaries are in your P

## Usage

This tool works on all Drupal code, but must be executed within the root directory of a Drupal project..

### 1. cd into a Drupal Directory

You can run this tool within any Drupal project. But, for best results, create a fresh Drupal directory on the latest Drupal:

```
composer create-project drupal-composer/drupal-project:8.x-dev drupal --no-interaction --stability=dev
cd drupal
```

### 2. Run drupal-check

Usage:

```
drupal-check [OPTIONS] [DIRS]
php vendor/bin/drupal-check [OPTIONS] [DIRS]
```

Arguments:
Expand All @@ -69,27 +56,60 @@ Examples:

* Check the address contrib module:

```
drupal-check web/modules/contrib/address
```
```
php vendor/bin/drupal-check web/modules/contrib/address
```

* Check the address contrib module for deprecations:

```
drupal-check -d web/modules/contrib/address
```
```
php vendor/bin/drupal-check -d web/modules/contrib/address
```

* Check the address contrib module for analysis:

```
drupal-check -a web/modules/contrib/address
```
```
php vendor/bin/drupal-check -a web/modules/contrib/address
```

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

```
drupal-check -ad web/modules/contrib/address
```
drupal-check:1.4.0 set PHPStan's analysis level to 2 for deprecations and 6 for analysis. This ensures basic analysis
errors are fixed to provide the best deprecated code detection experience. You can read more about PHPStan's rule
levels here: https://phpstan.org/user-guide/rule-levels

If you do not want to run PHPStan at level 2 and only report deprecation messages, use the following instructions

```shell
composer remove mglaman/drupal-check
composer require --dev phpstan/phpstan \
phpstan/extension-installer \
mglaman/phpstan-drupal \
phpstan/phpstan-deprecation-rules
```

Create a `phpstan.neon` file with the following:

```neon
parameters:
customRulesetUsed: true
ignoreErrors:
- '#\Drupal calls should be avoided in classes, use dependency injection instead#'
- '#Plugin definitions cannot be altered.#'
- '#Missing cache backend declaration for performance.#'
- '#Plugin manager has cache backend specified but does not declare cache tags.#'
# FROM mglaman/drupal-check/phpstan/base_config.neon
reportUnmatchedIgnoredErrors: false
excludePaths:
- */tests/Drupal/Tests/Listeners/Legacy/*
- */tests/fixtures/*.php
- */settings*.php
- */bower_components/*
- */node_modules/*
```

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

## Drupal Check - VS Code Extension

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

[GPL v2](LICENSE.txt)

## Roadmap

See what feature requests are most popular in the Issue queue: https://github.com/mglaman/drupal-check/issues.

## Issues

Submit issues and feature requests here: https://github.com/mglaman/drupal-check/issues.
Expand Down
13 changes: 6 additions & 7 deletions src/Command/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'*/settings*.php',
'*/node_modules/*'
],
'ignoreErrors' => [],
'ignoreErrors' => [
'#Unsafe usage of new static\(\)#'
],
'drupal' => [
'drupal_root' => $this->drupalRoot,
]
Expand All @@ -156,14 +158,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

if ($this->isAnalysisCheck) {
$configuration_data['parameters']['level'] = 4;

$ignored_analysis_errors = [
'#Unsafe usage of new static\(\)#'
];
$configuration_data['parameters']['level'] = 6;
$ignored_analysis_errors = [];
$configuration_data['parameters']['ignoreErrors'] = array_merge($ignored_analysis_errors, $configuration_data['parameters']['ignoreErrors']);
} else {
$configuration_data['parameters']['customRulesetUsed'] = true;
$configuration_data['parameters']['level'] = 2;
}

if ($this->isDeprecationsCheck) {
Expand Down

0 comments on commit e78eff7

Please sign in to comment.