Skip to content

Commit

Permalink
PHPStan level 1 - fix warnings and add to CI (#5932)
Browse files Browse the repository at this point in the history
* PHPStan level 0 fixes

* Handle ExecTrait a bit better

* Add phpstan to CI

* Report path

* mkdir

* fixes

* Fixes2

* Move method down to satisfy phpstan

* Remove composer.json/files. Was causing failure in testMultisiteContainer
  • Loading branch information
weitzman committed Mar 25, 2024
1 parent 902b304 commit 604d021
Show file tree
Hide file tree
Showing 41 changed files with 344 additions and 141 deletions.
7 changes: 5 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ jobs:
- run: cp .docker/zz-php.ini /usr/local/etc/php/conf.d/
- run: composer -n validate --no-check-all
- run: composer -n install
- run: composer -n cs
- run: mkdir -p /tmp/results
- run: composer -n cs -- --report=junit --report-file=/tmp/results/junit.phpcs.xml
- run: vendor/bin/phpstan --error-format=junit > /tmp/results/phpstan.junit.xml

# Mergeable test:
# FAIL if merging test branch with 12.x produces conflicts
Expand Down Expand Up @@ -138,7 +140,8 @@ jobs:
workflows:
drush:
jobs:
- code_style
- code_style:
<<: *poststeps
- check_mergable
# - test_80_drupal92_security:
# <<: *requires
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
"cweagans/composer-patches": "~1.0",
"drupal/core-recommended": "^10.2.4",
"drupal/semver_example": "2.3.0",
"jetbrains/phpstorm-attributes": "^1.0",
"mglaman/phpstan-drupal": "^1.2",
"phpunit/phpunit": "^9",
"rector/rector": "^0.12",
"squizlabs/php_codesniffer": "^3.7"
Expand Down
241 changes: 222 additions & 19 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions phpstan-bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

use Composer\Autoload\ClassLoader;

// Deal with dynamic autoloader that we use for symfony cross version compat.
$loader = new ClassLoader();
$loader->addPsr4('Drush\\', 'src-symfony-compatibility/v6');
$loader->register();
25 changes: 25 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
parameters:
level: 1
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
bootstrapFiles:
- phpstan-bootstrap.php
paths:
- src
drupal:
drupal_root: sut
excludePaths:
# Deliberately calls optional external code.
- src/Psysh/Caster.php
# Remove once https://github.com/mglaman/phpstan-drupal/issues/741 is resolved
- src/Commands/core/LocaleCommands.php
- src/Commands/core/LanguageCommands.php
ignoreErrors:
# XHprof
- '#tideways_xhprof_enable#'
- '#tideways_xhprof_disable#'
- '#Constant DRUSH_DRUPAL_CORE not found.#'
- '#Constant TIDEWAYS_XHPROF_FLAGS_NO_BUILTINS not found.#'
- '#Constant TIDEWAYS_XHPROF_FLAGS_CPU not found.#'
- '#Constant TIDEWAYS_XHPROF_FLAGS_MEMORY not found.#'
includes:
- vendor/mglaman/phpstan-drupal/extension.neon

0 comments on commit 604d021

Please sign in to comment.