Skip to content

Commit

Permalink
chore: add phpstan strict type checking
Browse files Browse the repository at this point in the history
chore: update lando tooling to better reflect usage

chore: only run phpcs and phpstan on latest php version

chore: update step name

feat: update phpstan to mirro upgrade_status results

feat: update phpstan to ignore errors from phpunit dynamic call
  • Loading branch information
millnut committed Jul 13, 2024
1 parent f40fda1 commit c4c352f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
15 changes: 3 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ on:
branches:
- '3.x'
schedule:
- cron: "0 7 * * *"
- cron: '0 7 * * *'
workflow_dispatch:

env:
LOCALGOV_DRUPAL_PROJECT: localgovdrupal/localgov-project
LOCALGOV_DRUPAL_PROJECT_PATH:

jobs:

build:
name: Install LocalGov Drupal
runs-on: ubuntu-latest
Expand All @@ -39,7 +38,6 @@ jobs:
- '8.3'

steps:

- name: Save git branch and git repo names to env if this is not a pull request
if: github.event_name != 'pull_request'
run: |
Expand Down Expand Up @@ -98,12 +96,9 @@ jobs:
drupal-version:
- '~10.0'
php-version:
- '8.1'
- '8.2'
- '8.3'

steps:

- name: Cached workspace
uses: actions/cache@v2
with:
Expand All @@ -123,7 +118,7 @@ jobs:
./bin/phpcs -p ${LOCALGOV_DRUPAL_PROJECT_PATH}
phpstan:
name: Deprecated code checks
name: Static analysis checks
needs: build
runs-on: ubuntu-latest

Expand All @@ -135,12 +130,9 @@ jobs:
drupal-version:
- '~10.0'
php-version:
- '8.1'
- '8.2'
- '8.3'

steps:

- name: Cached workspace
uses: actions/cache@v2
with:
Expand All @@ -154,7 +146,7 @@ jobs:
with:
php-version: ${{ matrix.php-version }}

- name: Run deprecated code checks
- name: Run PHPStan code checks
run: |
cd html
./bin/phpstan analyse -c ./phpstan.neon ./web/modules/contrib/localgov* ./web/profiles/contrib/localgov* ./web/themes/contrib/localgov*
Expand All @@ -176,7 +168,6 @@ jobs:
- '8.3'

steps:

- name: Clone Drupal container
uses: actions/checkout@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .lando.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ tooling:
composer:
service: appserver
cmd: /usr/local/bin/composer
deprecated:
sca:
service: appserver
cmd: 'bash -c "/app/vendor/bin/phpstan analyse -c /app/phpstan.neon /app/web/profiles/contrib/localgov* /app/web/modules/contrib/localgov* /app/web/themes/contrib/localgov*"'
drush:
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"phpspec/prophecy-phpunit": "^2",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-strict-rules": "^1.5",
"squizlabs/php_codesniffer": "^3.6"
},
"conflict": {
Expand Down
23 changes: 21 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
includes:
- vendor/phpstan/phpstan/conf/bleedingEdge.neon

parameters:
# we don't set a level so that we check deprecations only, and
# not to highlight unknown classes which are from composer suggestions
level: 1
customRulesetUsed: true
reportUnmatchedIgnoredErrors: false
checkFunctionArgumentTypes: true

drupal:
rules:
classExtendsInternalClassRule: false

strictRules:
allRules: false
booleansInConditions: true
strictCalls: true

# Exclude microsite project submodules from phpstan checks on the main project.
excludePaths:
- web/modules/contrib/localgov_alert_banner/modules/group_alert_banner/*

# Ignore phpstan-drupal extension's rules.
ignoreErrors:
- '#\Drupal calls should be avoided in classes, use dependency injection instead#'
Expand All @@ -11,3 +28,5 @@ parameters:
- '#Plugin manager has cache backend specified but does not declare cache tags.#'
# new static() is a best practice in Drupal, so we cannot fix that.
- '#^Unsafe usage of new static#'
# Disable PHPUnit dynamic call until core decision - https://www.drupal.org/project/drupal/issues/3029358
- '#Dynamic call to static method PHPUnit\\Framework\\.*#'

0 comments on commit c4c352f

Please sign in to comment.