Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump PHPStan to level 2 when doing deprecations #267

Merged
merged 4 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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