Issue #3178534 by mondrake, klausi, alexpott, longwave, mallezie, Taran2L, mglaman, Spokje, kim.pepper, daffie, andypost, neclimdul, xjm, Gábor Hojtsy, cmlara: Start running PHPStan on Drupal core (level 0)

merge-requests/1696/head
catch 2022-01-18 09:34:31 +00:00
parent 30523436ce
commit fe307a0fee
10 changed files with 1505 additions and 4 deletions

View File

@ -21,9 +21,12 @@
"composer/composer": "^2.0.2",
"drupal/coder": "^8.3.10",
"instaclick/php-webdriver": "^1.4.1",
"mglaman/phpstan-drupal": "^1.1.9",
"mikey179/vfsstream": "^1.6.8",
"phpunit/phpunit": "^9.5",
"phpspec/prophecy-phpunit": "^2",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.4.0",
"symfony/css-selector": "^5.4",
"symfony/phpunit-bridge": "^5.4",
"symfony/var-dumper": "^5.4",
@ -51,7 +54,8 @@
"allow-plugins": {
"composer/installers": true,
"drupal/core-project-message": true,
"drupal/core-vendor-hardening": true
"drupal/core-vendor-hardening": true,
"phpstan/extension-installer": true
}
},
"extra": {

259
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "6209de25fead07a04a71b6af893db664",
"content-hash": "210789b4f85a82f083006db5aeafc33d",
"packages": [
{
"name": "asm89/stack-cors",
@ -5501,6 +5501,110 @@
},
"time": "2021-07-22T09:24:00+00:00"
},
{
"name": "mglaman/phpstan-drupal",
"version": "1.1.9",
"source": {
"type": "git",
"url": "https://github.com/mglaman/phpstan-drupal.git",
"reference": "74b356d990906fa0dd423544ef0d1b48cd52a246"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mglaman/phpstan-drupal/zipball/74b356d990906fa0dd423544ef0d1b48cd52a246",
"reference": "74b356d990906fa0dd423544ef0d1b48cd52a246",
"shasum": ""
},
"require": {
"php": "^7.4 || ^8.0",
"phpstan/phpstan": "^1.0",
"symfony/finder": "~3.4.5 ||^4.2 || ^5.0 || ^6.0",
"symfony/yaml": "~3.4.5 || ^4.2|| ^5.0 || ^6.0",
"webflo/drupal-finder": "^1.2"
},
"require-dev": {
"composer/installers": "^1.9",
"drupal/core-dev": "^8.8@alpha || ^9.0",
"drupal/core-recommended": "^8.8@alpha || ^9.0",
"drush/drush": "^9.6 || ^10.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^6.5 || ^7.5 || ^8.0 || ^9",
"squizlabs/php_codesniffer": "^3.3"
},
"suggest": {
"jangregor/phpstan-prophecy": "Provides a prophecy/prophecy extension for phpstan/phpstan.",
"phpstan/phpstan-deprecation-rules": "For catching deprecations, especially in Drupal core.",
"phpstan/phpstan-phpunit": "PHPUnit extensions and rules for PHPStan."
},
"type": "phpstan-extension",
"extra": {
"branch-alias": {
"dev-main": "1.0-dev"
},
"installer-paths": {
"tests/fixtures/drupal/core": [
"type:drupal-core"
],
"tests/fixtures/drupal/libraries/{$name}": [
"type:drupal-library"
],
"tests/fixtures/drupal/modules/contrib/{$name}": [
"type:drupal-module"
],
"tests/fixtures/drupal/profiles/contrib/{$name}": [
"type:drupal-profile"
],
"tests/fixtures/drupal/themes/contrib/{$name}": [
"type:drupal-theme"
]
},
"phpstan": {
"includes": [
"extension.neon"
]
}
},
"autoload": {
"files": [
"drupal-phpunit-hack.php"
],
"psr-4": {
"mglaman\\PHPStanDrupal\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Matt Glaman",
"email": "nmd.matt@gmail.com"
}
],
"description": "Drupal extension and rules for PHPStan",
"support": {
"issues": "https://github.com/mglaman/phpstan-drupal/issues",
"source": "https://github.com/mglaman/phpstan-drupal/tree/1.1.9"
},
"funding": [
{
"url": "https://github.com/mglaman",
"type": "github"
},
{
"url": "https://opencollective.com/phpstan-drupal",
"type": "open_collective"
},
{
"url": "https://tidelift.com/funding/github/packagist/mglaman/phpstan-drupal",
"type": "tidelift"
}
],
"time": "2022-01-17T15:57:58+00:00"
},
{
"name": "mikey179/vfsstream",
"version": "v1.6.10",
@ -6053,6 +6157,115 @@
},
"time": "2020-07-09T08:33:42+00:00"
},
{
"name": "phpstan/extension-installer",
"version": "1.1.0",
"source": {
"type": "git",
"url": "https://github.com/phpstan/extension-installer.git",
"reference": "66c7adc9dfa38b6b5838a9fb728b68a7d8348051"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/extension-installer/zipball/66c7adc9dfa38b6b5838a9fb728b68a7d8348051",
"reference": "66c7adc9dfa38b6b5838a9fb728b68a7d8348051",
"shasum": ""
},
"require": {
"composer-plugin-api": "^1.1 || ^2.0",
"php": "^7.1 || ^8.0",
"phpstan/phpstan": ">=0.11.6"
},
"require-dev": {
"composer/composer": "^1.8",
"phing/phing": "^2.16.3",
"php-parallel-lint/php-parallel-lint": "^1.2.0",
"phpstan/phpstan-strict-rules": "^0.11 || ^0.12"
},
"type": "composer-plugin",
"extra": {
"class": "PHPStan\\ExtensionInstaller\\Plugin"
},
"autoload": {
"psr-4": {
"PHPStan\\ExtensionInstaller\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Composer plugin for automatic installation of PHPStan extensions",
"support": {
"issues": "https://github.com/phpstan/extension-installer/issues",
"source": "https://github.com/phpstan/extension-installer/tree/1.1.0"
},
"time": "2020-12-13T13:06:13+00:00"
},
{
"name": "phpstan/phpstan",
"version": "1.4.0",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "72b04d97b5e6e60a081f17c416fef35bd521120b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/72b04d97b5e6e60a081f17c416fef35bd521120b",
"reference": "72b04d97b5e6e60a081f17c416fef35bd521120b",
"shasum": ""
},
"require": {
"php": "^7.1|^8.0"
},
"conflict": {
"phpstan/phpstan-shim": "*"
},
"bin": [
"phpstan",
"phpstan.phar"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.4-dev"
}
},
"autoload": {
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPStan - PHP Static Analysis Tool",
"support": {
"issues": "https://github.com/phpstan/phpstan/issues",
"source": "https://github.com/phpstan/phpstan/tree/1.4.0"
},
"funding": [
{
"url": "https://github.com/ondrejmirtes",
"type": "github"
},
{
"url": "https://github.com/phpstan",
"type": "github"
},
{
"url": "https://www.patreon.com/phpstan",
"type": "patreon"
},
{
"url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan",
"type": "tidelift"
}
],
"time": "2022-01-14T15:58:47+00:00"
},
{
"name": "phpunit/php-code-coverage",
"version": "9.2.10",
@ -8260,6 +8473,50 @@
],
"time": "2021-07-28T10:34:58+00:00"
},
{
"name": "webflo/drupal-finder",
"version": "1.2.2",
"source": {
"type": "git",
"url": "https://github.com/webflo/drupal-finder.git",
"reference": "c8e5dbe65caef285fec8057a4c718a0d4138d1ee"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/webflo/drupal-finder/zipball/c8e5dbe65caef285fec8057a4c718a0d4138d1ee",
"reference": "c8e5dbe65caef285fec8057a4c718a0d4138d1ee",
"shasum": ""
},
"require": {
"ext-json": "*"
},
"require-dev": {
"mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "^4.8"
},
"type": "library",
"autoload": {
"classmap": [
"src/DrupalFinder.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-2.0-or-later"
],
"authors": [
{
"name": "Florian Weber",
"email": "florian@webflo.org"
}
],
"description": "Helper class to locate a Drupal installation from a given path.",
"support": {
"issues": "https://github.com/webflo/drupal-finder/issues",
"source": "https://github.com/webflo/drupal-finder/tree/1.2.2"
},
"time": "2020-10-27T09:42:17+00:00"
},
{
"name": "webmozart/assert",
"version": "1.10.0",

View File

@ -15,8 +15,11 @@
"friends-of-behat/mink-browserkit-driver": "^1.4",
"instaclick/php-webdriver": "^1.4.1",
"justinrainbow/json-schema": "^5.2",
"mglaman/phpstan-drupal": "^1.1.9",
"mikey179/vfsstream": "^1.6.8",
"phpspec/prophecy-phpunit": "^2",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.4.0",
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "^5.4",
"symfony/css-selector": "^5.4",

View File

@ -22,6 +22,7 @@
"friends-of-behat/mink-browserkit-driver": "v1.6.1",
"instaclick/php-webdriver": "1.4.10",
"justinrainbow/json-schema": "5.2.11",
"mglaman/phpstan-drupal": "1.1.9",
"mikey179/vfsstream": "v1.6.10",
"myclabs/deep-copy": "1.10.2",
"nikic/php-parser": "v4.13.2",
@ -32,6 +33,8 @@
"phpdocumentor/type-resolver": "1.6.0",
"phpspec/prophecy": "v1.15.0",
"phpspec/prophecy-phpunit": "v2.0.1",
"phpstan/extension-installer": "1.1.0",
"phpstan/phpstan": "1.4.0",
"phpunit/php-code-coverage": "9.2.10",
"phpunit/php-file-iterator": "3.0.6",
"phpunit/php-invoker": "3.1.1",
@ -67,6 +70,7 @@
"symfony/lock": "v5.4.2",
"symfony/phpunit-bridge": "v5.4.0",
"theseer/tokenizer": "1.2.1",
"webflo/drupal-finder": "1.2.2",
"webmozart/assert": "1.10.0"
}
}

View File

@ -298,14 +298,14 @@ class ExecutionContext implements ExecutionContextInterface {
* {@inheritdoc}
*/
public function markObjectAsInitialized($cache_key) {
// Not supported, so nothing todo.
throw new \LogicException('\Symfony\Component\Validator\Context\ExecutionContextInterface::markObjectAsInitialized is unsupported.');
}
/**
* {@inheritdoc}
*/
public function isObjectInitialized($cache_key): bool {
// Not supported, so nothing todo.
throw new \LogicException('\Symfony\Component\Validator\Context\ExecutionContextInterface::isObjectInitialized is unsupported.');
}
/**

View File

@ -788,6 +788,7 @@ metapackages
metatag
metatags
meΦΩ
mglaman
miaus
middlewares
midgardmvc
@ -994,6 +995,7 @@ phpdocumentor
phpfile
phpserialize
phpspec
phpstan
phpunit
phpunit's
pianura

1152
core/phpstan-baseline.neon Normal file

File diff suppressed because it is too large Load Diff

10
core/phpstan-partial.neon Normal file
View File

@ -0,0 +1,10 @@
# Configuration file for PHPStan static code checking, see https://phpstan.org .
# PHPStan is triggered on Drupal CI in commit-code-check.sh.
includes:
- phpstan.neon.dist
# Do not add additional configuration to this file. This configuration exists
# only to allow core/scripts/dev/commit-code-check.sh to run against a subset of
# the codebase.
parameters:
reportUnmatchedIgnoredErrors: false

38
core/phpstan.neon.dist Normal file
View File

@ -0,0 +1,38 @@
# Configuration file for PHPStan static code checking, see https://phpstan.org .
# PHPStan is triggered on Drupal CI in commit-code-check.sh.
includes:
- phpstan-baseline.neon
parameters:
level: 0
paths:
- .
- ../composer
excludePaths:
# Skip settings.
- ../*/settings*.php
# Skip test fixtures.
- */tests/fixtures/*.php
# Below extends on purpose a non existing class for testing.
- modules/system/tests/modules/plugin_test/src/Plugin/plugin_test/fruit/ExtendingNonInstalledClass.php
# @todo files below need to be excluded as they prevent baseline generation.
# Fixing them is a priority.
- modules/link/tests/src/Kernel/LinkItemTest.php
ignoreErrors:
# new static() is a best practice in Drupal, so we cannot fix that.
- "#^Unsafe usage of new static#"
# Ignore common errors for now.
- "#^Access to an undefined property#"
- "#^Call to an undefined method#"
- "#^Cannot unset offset#"
- "#should return .* but return statement is missing#"
- "#Drupal calls should be avoided in classes, use dependency injection instead#"
- "#^Plugin definitions cannot be altered.#"
- "#^Missing cache backend declaration for performance.#"
- "#cache tag might be unclear and does not contain the cache key in it.#"
- "#^Class .* extends @internal class#"

View File

@ -11,6 +11,7 @@
# - File modes.
# - No changes to core/node_modules directory.
# - PHPCS checks PHP and YAML files.
# - PHPStan checks PHP files.
# - ESLint checks JavaScript and YAML files.
# - Checks .es6.js and .js files are equivalent.
# - Stylelint checks CSS files.
@ -110,6 +111,10 @@ TOP_LEVEL=$(git rev-parse --show-toplevel)
# This variable will be set to one when the file core/phpcs.xml.dist is changed.
PHPCS_XML_DIST_FILE_CHANGED=0
# This variable will be set to one when the files core/phpstan-baseline.neon or
# core/phpstan.neon.dist are changed.
PHPSTAN_DIST_FILE_CHANGED=0
# This variable will be set to one when one of the eslint config file is
# changed:
# - core/.eslintrc.passing.json
@ -126,6 +131,10 @@ for FILE in $FILES; do
PHPCS_XML_DIST_FILE_CHANGED=1;
fi;
if [[ $FILE == "core/phpstan-baseline.neon" || $FILE == "core/phpstan.neon.dist" ]]; then
PHPSTAN_DIST_FILE_CHANGED=1;
fi;
if [[ $FILE == "core/.eslintrc.json" || $FILE == "core/.eslintrc.passing.json" || $FILE == "core/.eslintrc.jquery.json" ]]; then
ESLINT_CONFIG_PASSING_FILE_CHANGED=1;
fi;
@ -181,6 +190,28 @@ printf "\n"
printf -- '-%.0s' {1..100}
printf "\n"
# Run PHPStan on all files in one go for better performance. APCu is disabled to
# ensure that the composer classmap is not corrupted.
if [[ $PHPSTAN_DIST_FILE_CHANGED == "1" ]]; then
printf "\nRunning PHPStan on *all* files.\n"
php -d apc.enabled=0 -d apc.enable_cli=0 vendor/bin/phpstan analyze --no-progress --configuration="$TOP_LEVEL/core/phpstan.neon.dist"
else
printf "\nRunning PHPStan on changed files.\n"
php -d apc.enabled=0 -d apc.enable_cli=0 vendor/bin/phpstan analyze --no-progress --configuration="$TOP_LEVEL/core/phpstan-partial.neon" $ABS_FILES
fi
if [ "$?" -ne "0" ]; then
# If there are failures set the status to a number other than 0.
FINAL_STATUS=1
printf "\nPHPStan: ${red}failed${reset}\n"
else
printf "\nPHPStan: ${green}passed${reset}\n"
fi
# Add a separator line to make the output easier to read.
printf "\n"
printf -- '-%.0s' {1..100}
printf "\n"
# When the file core/phpcs.xml.dist has been changed, then PHPCS must check all files.
if [[ $PHPCS_XML_DIST_FILE_CHANGED == "1" ]]; then
# Test all files with phpcs rules.