From 44b89c047b43b219165a892e814499baec7646c5 Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Sat, 14 Dec 2019 22:43:40 +0100 Subject: [PATCH 1/2] Upgrade to PHPStan 0.12 --- .travis.yml | 2 +- composer.json | 4 +-- phpstan-baseline.neon | 62 +++++++++++++++++++++++++++++++++++++++++++ phpstan.neon | 6 ++++- 4 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 phpstan-baseline.neon diff --git a/.travis.yml b/.travis.yml index 2c9dc4115..5eff2663b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,7 @@ before_script: script: - if [[ $(phpenv version-name) == '7.2' ]]; then vendor/bin/phpunit --coverage-clover clover.xml ; fi - if [[ $(phpenv version-name) != '7.2' ]]; then vendor/bin/phpunit ; fi - - if [[ $(phpenv version-name) == '7.2' ]]; then vendor/bin/phpstan analyse -l 6 -c phpstan.neon src ; fi + - if [[ $(phpenv version-name) == '7.2' ]]; then vendor/bin/phpstan analyse -l 5 -c phpstan.neon src ; fi after_script: - if [[ $(phpenv version-name) == '7.2' ]]; then php vendor/bin/coveralls -v ; fi diff --git a/composer.json b/composer.json index ad1f56f08..0a1fbfbe9 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "scripts": { "test": "phpunit", "format-code": "php-cs-fixer fix --allow-risky=yes", - "phpstan": "phpstan analyse -l 6 -c phpstan.neon src" + "phpstan": "phpstan analyse -l 5 -c phpstan.neon src" }, "require": { "php": ">=7.2.0", @@ -38,7 +38,7 @@ "doctrine/annotations": "~1.2", "ocramius/proxy-manager": "~2.0.2", "friendsofphp/php-cs-fixer": "^2.4", - "phpstan/phpstan": "^0.9.2" + "phpstan/phpstan": "^0.12" }, "provide": { "psr/container-implementation": "^1.0" diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 000000000..aca40e3c7 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,62 @@ +parameters: + ignoreErrors: + - + message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#" + count: 1 + path: src\CompiledContainer.php + + - + message: "#^Negated boolean expression is always false\\.$#" + count: 1 + path: src\CompiledContainer.php + + - + message: "#^Negated boolean expression is always false\\.$#" + count: 2 + path: src\Compiler\Compiler.php + + - + message: "#^If condition is always false\\.$#" + count: 1 + path: src\Compiler\Compiler.php + + - + message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#" + count: 2 + path: src\Container.php + + - + message: "#^Negated boolean expression is always false\\.$#" + count: 1 + path: src\Container.php + + - + message: "#^Result of && is always false\\.$#" + count: 1 + path: src\ContainerBuilder.php + + - + message: "#^Else branch is unreachable because ternary operator condition is always true\\.$#" + count: 1 + path: src\ContainerBuilder.php + + - + message: "#^Negated boolean expression is always false\\.$#" + count: 1 + path: src\Definition\ArrayDefinitionExtension.php + + - + message: "#^Parameter \\#1 \\$definition \\(DI\\\\Definition\\\\InstanceDefinition\\) of method DI\\\\Definition\\\\Resolver\\\\InstanceInjector\\:\\:resolve\\(\\) should be compatible with parameter \\$definition \\(DI\\\\Definition\\\\ObjectDefinition\\) of method DI\\\\Definition\\\\Resolver\\\\ObjectCreator\\:\\:resolve\\(\\)$#" + count: 1 + path: src\Definition\Resolver\InstanceInjector.php + + - + message: "#^Instanceof between DI\\\\Definition\\\\Definition and DI\\\\Definition\\\\AutowireDefinition will always evaluate to false\\.$#" + count: 1 + path: src\Definition\Source\SourceCache.php + + - + message: "#^Parameter \\#1 \\$autoload_function of function spl_autoload_register expects callable\\(string\\)\\: void, ProxyManager\\\\Autoloader\\\\AutoloaderInterface given\\.$#" + count: 1 + path: src\Proxy\ProxyFactory.php + diff --git a/phpstan.neon b/phpstan.neon index 09952ac27..31411ef0a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,11 @@ +includes: + - phpstan-baseline.neon + parameters: excludes_analyse: - - %rootDir%/../../../src/Compiler/Template.php + - src/Compiler/Template.php ignoreErrors: - '#Access to undefined constant DI\\CompiledContainer::METHOD_MAPPING.#' - '#Function apcu_.* not found.#' reportUnmatchedIgnoredErrors: false + inferPrivatePropertyTypeFromConstructor: true From 502f2e4981ea5cdea1ec8ce5d7278867d80b66ae Mon Sep 17 00:00:00 2001 From: Jacob Dreesen Date: Sat, 14 Dec 2019 23:12:22 +0100 Subject: [PATCH 2/2] Run PHPStan on travis only once When running it on PHP 7.2 it runs twice, because the lowest dependencies check is run on this version, too. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5eff2663b..065621c5f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -34,7 +34,7 @@ before_script: script: - if [[ $(phpenv version-name) == '7.2' ]]; then vendor/bin/phpunit --coverage-clover clover.xml ; fi - if [[ $(phpenv version-name) != '7.2' ]]; then vendor/bin/phpunit ; fi - - if [[ $(phpenv version-name) == '7.2' ]]; then vendor/bin/phpstan analyse -l 5 -c phpstan.neon src ; fi + - if [[ $(phpenv version-name) == '7.3' ]]; then vendor/bin/phpstan analyse -l 5 -c phpstan.neon src ; fi after_script: - if [[ $(phpenv version-name) == '7.2' ]]; then php vendor/bin/coveralls -v ; fi