mglaman / drupal-check
CLI tool for running checks on a Drupal code base
Fund package maintenance!
mglaman
Open Collective
Tidelift
Installs: 5 100 509
Dependents: 53
Suggesters: 0
Security: 0
Stars: 333
Watchers: 11
Forks: 67
Open Issues: 29
Type:project
Requires
- php: ^7.2.5|^8.0
- composer/xdebug-handler: ^1.1 || ^2.0.1 || ^3.0
- jangregor/phpstan-prophecy: ^1.0
- jean85/pretty-package-versions: ^1.5.0 || ^2.0.1
- mglaman/phpstan-drupal: ^1.0.0
- nette/neon: ^3.1
- phpstan/phpstan-deprecation-rules: ^1.0.0
- symfony/console: ~3.4.5 || ^4.2|| ^5.0 || ^6.0 || ^7.0
- symfony/process: ~3.4.5 || ^4.2|| ^5.0 || ^6.0 || ^7.0
- webflo/drupal-finder: ^1.1
Requires (Dev)
- phpstan/phpstan: ^1.0.0
- phpstan/phpstan-strict-rules: ^1.0.0
- squizlabs/php_codesniffer: ^3.4
- dev-main
- 1.5.0
- 1.4.0
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.1
- 1.2.0
- 1.1.10
- 1.1.9
- 1.1.8
- 1.1.7
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-mglaman-patch-4
- dev-dependabot/composer/squizlabs/php_codesniffer-3.10.3
- dev-dependabot/composer/phpstan/phpstan-deprecation-rules-1.2.1
- dev-dependabot/composer/jean85/pretty-package-versions-2.0.6
- dev-dependabot/composer/jangregor/phpstan-prophecy-1.0.2
- dev-dependabot/composer/composer/xdebug-handler-3.0.5
- dev-mglaman-patch-3
- dev-terminal-width
- dev-remove-lock
- dev-mglaman-patch-2
- dev-mglaman-patch-1
- dev-gh204-failing-config_update_check
- dev-lightning-test
- dev-gh-164-phar-phpstan-path
- dev-gh-163-package-version-conflicts
- dev-gh-119-followups
- dev-increase-travis-testing
- dev-fix-global-require-in-testing
- dev-phar-self-update
- dev-gh55
- dev-examples-module
- dev-feature/phpcs-poc
This package is auto-updated.
Last update: 2024-11-18 16:52:56 UTC
README
Built on PHPStan, this static analysis tool will check for correctness (e.g. using a class that doesn't exist), deprecation errors, and more.
Why? While there are many static analysis tools out there, none of them run with the Drupal context in mind. This allows checking contrib modules for deprecation errors thrown by core.
Are you ready for Drupal 9? Check out our Drupal 9 Readiness instructions for details on how this tool can help.
Sponsors
Requirements
- PHP >=7.2
Installation
You can install this in your project using Composer as a development dependency like so:
composer require mglaman/drupal-check --dev
You can also install this globally using Composer like so:
composer global require mglaman/drupal-check
Refer to Composer's documentation on how to ensure global binaries are in your PATH: https://getcomposer.org/doc/00-intro.md#manual-installation.
Usage
php vendor/bin/drupal-check [options] [--] <path>...
Arguments:
path
- The Drupal code path(s) to inspect
Options:
--drupal-root[=DRUPAL-ROOT]
- Path to Drupal root.--format[=FORMAT]
- Formatter to use: raw, table, checkstyle, json, or junit [default: "table"]-d, --deprecations
- Check for deprecations-a, --analysis
- Check code analysis-s, --style
- Check code style--php8
- Set PHPStan phpVersion for 8.1 (Drupal 10 requirement)--memory-limit[=MEMORY-LIMIT]
- Memory limit for analysis-e, --exclude-dir[=EXCLUDE-DIR]
- Directories to exclude. Separate multiple directories with a comma, no spaces.--no-progress
- Do not show progress bar, only results-h, --help
- Display this help message-q, --quiet
- Do not output any message-V, --version
- Display this application version--ansi
- Force ANSI output--no-ansi
- Disable ANSI output-n, --no-interaction
- Do not ask any interactive question-v|vv|vvv, --verbose
- Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Examples:
- Check the address contrib module:
php vendor/bin/drupal-check web/modules/contrib/address
- Check the address contrib module for deprecations:
php vendor/bin/drupal-check -d web/modules/contrib/address
- Check the address contrib module for analysis:
php vendor/bin/drupal-check -a web/modules/contrib/address
Rollback update to PHPStan level 2 for deprecation analysis
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
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:
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
You can run Drupal Check from VSCode using this extension: https://marketplace.visualstudio.com/items?itemName=bbeversdorf.drupal-check
The code can be found at: https://github.com/bbeversdorf/vscode-drupal-check
License
Issues
Submit issues and feature requests here: https://github.com/mglaman/drupal-check/issues.
Known Issues
There are conflicts with dependencies shared with other libraries that might be installed on a Drupal project:
- This tool does not work with BLT 9: #9
- If you run into issues with other libraries, please submit an issue to this project.
Contributing
See the CONTRIBUTING.md.