Codesniffers - digitalutsc/islandora_lite_docs GitHub Wiki
Phan
For detailed installation and usage instructions, visit Getting Started and Phan Tutorial.
- Install Phan.
isle-dc/codebase$ composer require phan/phan
-
Install Phan dependency: php-ast. Installation instructions can be found here.
-
Create
isle-dc/codebase/.phan/config.php
Sample Configuration File
<?php
return [
// Supported values: `'5.6'`, `'7.0'`, `'7.1'`, `'7.2'`, `'7.3'`,
// `'7.4'`, `'8.0'`, `'8.1'`, `null`.
'target_php_version' => 8.1,
// directories to parse and analyze
'directory_list' => [
'web/modules/contrib',
'web/core/lib/Drupal',
'vendor'
],
'exclude_file_regex' => '@^vendor/.*/(tests?|Tests?)/@',
'exclude_analysis_directory_list' => [
'web/core/lib/Drupal',
'vendor/'
],
'analyzed_file_extensions' => [
'php',
]
];
For more configuration options, please see:
- Run Phan.
isle-dc/codebase$ ./vendor/bin/phan
Generating separate output files for different modules
#!/bin/bash
src=web/modules/contrib # directory containing modules
dest=phan_logs # output directory
mkdir -p $dest
# get phan output
output=$dest/phan_output.txt
./vendor/bin/phan -o $output
# generate separate files for each module
for module in $src/*; do
msgs=$dest/$(basename "$module").txt
grep "$module" $output > $msgs
# remove file if empty (no logs)
if [ -z $(grep '[^[:space:](/digitalutsc/islandora_lite_docs/wiki/--z-$(grep-'[^[:space:)' $msgs) ]]; then
rm $msgs
fi
done
To run: isle-dc/codebase$ ./generate_phan.sh
If permission denied, check if you have execute permissions by running ls -l generate_phan.sh
. If not, run chmod +x generate_phan.sh
.
PHPStan
- Install PHPStan
composer require --dev phpstan/phpstan
- Run PHPStan
vendor/bin/phpstan analyse path1 path2 path3 ...
For more options, see PHPStan Documentation
Drupal Deprecation Analysis
See mglaman/drupal-check: Rollback update to PHPStan level 2 for deprecation analysis
Useful Extensions
PHPStan Deprecation Rules
PHPStan Deprecation Rules helps detect deprecation errors.
To install:
composer require --dev phpstan/phpstan-deprecation-rules
composer require --dev phpstan/extension-installer
Generating output files for each module in a directory
This shell script runs PHPStan against each subdirectory within the specified dir
.
#!/bin/bash
dir="web/modules/contrib" # directory containing modules
target="phpstan_logs" # output directory
mkdir -p $target
for module in $dir/*; do
out=$target/$(basename "$module").txt
if ./vendor/bin/phpstan analyse $module > $out; then
# delete file if no errors
rm $out
fi
done
Run using the command: ./generate_phpstan.sh
If permission denied, check if you have execute permissions by running ls -l generate_phpstan.sh
. If not, run chmod +x generate_phpstan.sh
.
Drupal-Check
- Install drupal-check
composer require mglaman/drupal-check --dev
- Run
path/to/vendor/bin/drupal-check -d dir/to/analyze
See drupal-check for more configuration options.
Running drupal-check against multiple directories
This shell script runs drupal-check against each subdirectory within the specified dir
, generating individual output files for each.
#!/bin/bash
dir="web/modules/contrib" # directory containing modules to run drupal-check against
target="drupal_check_logs" # output directory
mkdir -p $target
for module in $dir/*; do
out=$target/$(basename "$module").txt
./vendor/bin/drupal-check -d $module > $out
done
To run: isle-dc/codebase$ ./drupalcheck.sh
If permission denied, check if you have execute permissions by running ls -l drupalcheck.sh
. If not, run chmod +x drupalcheck.sh
.