From 2e1ea000b87f6edaad8607b3846784836cbef1bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 1 Mar 2020 13:03:23 +0100 Subject: [PATCH] Enhancement: Use baseline feature to run phpstan with and without extension --- .gitattributes | 25 ++--- .github/CONTRIBUTING.md | 10 ++ .github/workflows/continuous-integration.yml | 7 +- Makefile | 10 +- phpstan-with-extension-baseline.neon | 32 +++++++ phpstan-with-extension.neon | 11 +++ phpstan-without-extension-baseline.neon | 97 ++++++++++++++++++++ phpstan-without-extension.neon | 10 ++ phpstan.neon | 13 --- 9 files changed, 188 insertions(+), 27 deletions(-) create mode 100644 phpstan-with-extension-baseline.neon create mode 100644 phpstan-with-extension.neon create mode 100644 phpstan-without-extension-baseline.neon create mode 100644 phpstan-without-extension.neon delete mode 100644 phpstan.neon diff --git a/.gitattributes b/.gitattributes index b185020..92be302 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,11 +1,14 @@ -.docker/ export-ignore -.github/ export-ignore -test/ export-ignore -.editorconfig export-ignore -.gitattributes export-ignore -.gitignore export-ignore -.php_cs export-ignore -composer.lock export-ignore -Makefile export-ignore -phpstan.neon export-ignore -phpunit.xml export-ignore +.docker/ export-ignore +.github/ export-ignore +test/ export-ignore +.editorconfig export-ignore +.gitattributes export-ignore +.gitignore export-ignore +.php_cs export-ignore +composer.lock export-ignore +Makefile export-ignore +phpstan-with-extension-baseline.neon export-ignore +phpstan-with-extension.neon export-ignore +phpstan-without-extension-baseline.neon export-ignore +phpstan-without-extension.neon export-ignore +phpunit.xml export-ignore diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 9483545..0c1818a 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -28,6 +28,16 @@ $ make static-code-analysis to run a static code analysis. +We are also using the baseline feature of [`phpstan/phpstan`](https://medium.com/@ondrejmirtes/phpstans-baseline-feature-lets-you-hold-new-code-to-a-higher-standard-e77d815a5dff). + +Run + +``` +$ make static-code-analysis-baseline +``` + +to regenerate the baselines in [`../phpstan-with-extension-baseline.neon`](../phpstan-with-extension-baseline.neon) and [`../phpstan-without-extension-baseline.neon`](../phpstan-without-extension-baseline.neon). + ## Tests We are using [`phpunit/phpunit`](https://github.com/sebastianbergmann/phpunit) to drive the development. diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index b10742a..be9cd7d 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -115,8 +115,11 @@ jobs: - name: "Create cache directory for phpstan/phpstan" run: "mkdir -p .build/phpstan" - - name: "Run phpstan/phpstan" - run: "vendor/bin/phpstan analyse --configuration=phpstan.neon" + - name: "Run phpstan/phpstan with extension" + run: "vendor/bin/phpstan analyse --configuration=phpstan-with-extension.neon" + + - name: "Run phpstan/phpstan without extension" + run: "vendor/bin/phpstan analyse --configuration=phpstan-without-extension.neon" tests: name: "Tests" diff --git a/Makefile b/Makefile index 02c7791..1b1ff65 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,15 @@ help: ## Displays this list of targets with descriptions .PHONY: static-code-analysis static-code-analysis: vendor ## Runs a static code analysis with phpstan/phpstan mkdir -p .build/phpstan - vendor/bin/phpstan analyse --configuration=phpstan.neon + vendor/bin/phpstan analyse --configuration=phpstan-with-extension.neon + vendor/bin/phpstan analyse --configuration=phpstan-without-extension.neon + +.PHONY: static-code-analysis-baseline +static-code-analysis-baseline: vendor ## Generates a baseline for static code analysis with phpstan/phpstan + echo '' > phpstan-with-extension-baseline.neon + vendor/bin/phpstan analyze --configuration=phpstan-with-extension.neon --error-format=baselineNeon > phpstan-with-extension-baseline.neon || true + echo '' > phpstan-without-extension-baseline.neon + vendor/bin/phpstan analyze --configuration=phpstan-without-extension.neon --error-format=baselineNeon > phpstan-without-extension-baseline.neon || true .PHONY: tests tests: vendor ## Runs tests with phpunit/phpunit diff --git a/phpstan-with-extension-baseline.neon b/phpstan-with-extension-baseline.neon new file mode 100644 index 0000000..7a4b9e2 --- /dev/null +++ b/phpstan-with-extension-baseline.neon @@ -0,0 +1,32 @@ +parameters: + ignoreErrors: + - + message: "#^Property JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Test\\\\ObjectProphecy\\\\ProphesizeTest\\:\\:\\$prophecy has no typehint specified\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php + + - + message: "#^Method JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Test\\\\ObjectProphecy\\\\ProphesizeTest\\:\\:createProphecy\\(\\) has no return typehint specified\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php + + - + message: "#^Property JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Test\\\\ObjectProphecy\\\\WillExtendTest\\:\\:\\$prophecy has no typehint specified\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/WillExtendTest.php + + - + message: "#^Method JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Test\\\\ObjectProphecy\\\\WillExtendTest\\:\\:createProphecy\\(\\) has no return typehint specified\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/WillExtendTest.php + + - + message: "#^Property JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Test\\\\ObjectProphecy\\\\WillImplementTest\\:\\:\\$prophecy has no typehint specified\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/WillImplementTest.php + + - + message: "#^Method JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Test\\\\ObjectProphecy\\\\WillImplementTest\\:\\:createProphecy\\(\\) has no return typehint specified\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/WillImplementTest.php + diff --git a/phpstan-with-extension.neon b/phpstan-with-extension.neon new file mode 100644 index 0000000..c9b0951 --- /dev/null +++ b/phpstan-with-extension.neon @@ -0,0 +1,11 @@ +includes: + - extension.neon + - phpstan-with-extension-baseline.neon + +parameters: + inferPrivatePropertyTypeFromConstructor: true + level: max + paths: + - src/ + - test/ + tmpDir: .build/phpstan diff --git a/phpstan-without-extension-baseline.neon b/phpstan-without-extension-baseline.neon new file mode 100644 index 0000000..9209189 --- /dev/null +++ b/phpstan-without-extension-baseline.neon @@ -0,0 +1,97 @@ +parameters: + ignoreErrors: + - + message: "#^Call to an undefined method Prophecy\\\\Prophecy\\\\ObjectProphecy\\:\\:bar\\(\\)\\.$#" + count: 1 + path: test/StaticAnalysis/Test/BaseModelTest.php + + - + message: "#^Parameter \\#1 \\$bar of method JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Src\\\\BaseModel\\:\\:bar\\(\\) expects JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Src\\\\Bar, object given\\.$#" + count: 1 + path: test/StaticAnalysis/Test/BaseModelTest.php + + - + message: "#^Call to an undefined method Prophecy\\\\Prophecy\\\\ObjectProphecy\\:\\:baz\\(\\)\\.$#" + count: 1 + path: test/StaticAnalysis/Test/BaseModelTest.php + + - + message: "#^Parameter \\#1 \\$baz of method JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Src\\\\BaseModel\\:\\:baz\\(\\) expects JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Src\\\\Baz, object given\\.$#" + count: 1 + path: test/StaticAnalysis/Test/BaseModelTest.php + + - + message: "#^Property JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Test\\\\ObjectProphecy\\\\ProphesizeTest\\:\\:\\$prophecy has no typehint specified\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php + + - + message: "#^Call to an undefined method Prophecy\\\\Prophecy\\\\ObjectProphecy\\:\\:getFoo\\(\\)\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php + + - + message: "#^Call to an undefined method Prophecy\\\\Prophecy\\\\ObjectProphecy\\:\\:doubleTheNumber\\(\\)\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php + + - + message: "#^Call to an undefined method object\\:\\:getFoo\\(\\)\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php + + - + message: "#^Call to an undefined method object\\:\\:doubleTheNumber\\(\\)\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php + + - + message: "#^Method JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Test\\\\ObjectProphecy\\\\ProphesizeTest\\:\\:createProphecy\\(\\) has no return typehint specified\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/ProphesizeTest.php + + - + message: "#^Property JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Test\\\\ObjectProphecy\\\\WillExtendTest\\:\\:\\$prophecy has no typehint specified\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/WillExtendTest.php + + - + message: "#^Call to an undefined method Prophecy\\\\Prophecy\\\\ObjectProphecy\\:\\:baz\\(\\)\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/WillExtendTest.php + + - + message: "#^Parameter \\#1 \\$baz of method JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Src\\\\BaseModel\\:\\:baz\\(\\) expects JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Src\\\\Baz, object given\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/WillExtendTest.php + + - + message: "#^Method JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Test\\\\ObjectProphecy\\\\WillExtendTest\\:\\:createProphecy\\(\\) has no return typehint specified\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/WillExtendTest.php + + - + message: "#^Property JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Test\\\\ObjectProphecy\\\\WillImplementTest\\:\\:\\$prophecy has no typehint specified\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/WillImplementTest.php + + - + message: "#^Call to an undefined method Prophecy\\\\Prophecy\\\\ObjectProphecy\\:\\:bar\\(\\)\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/WillImplementTest.php + + - + message: "#^Parameter \\#1 \\$bar of method JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Src\\\\BaseModel\\:\\:bar\\(\\) expects JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Src\\\\Bar, object given\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/WillImplementTest.php + + - + message: "#^Method JanGregor\\\\Prophecy\\\\Test\\\\StaticAnalysis\\\\Test\\\\ObjectProphecy\\\\WillImplementTest\\:\\:createProphecy\\(\\) has no return typehint specified\\.$#" + count: 1 + path: test/StaticAnalysis/Test/ObjectProphecy/WillImplementTest.php + + - + message: "#^Parameter \\#1 \\$declaringClass of class JanGregor\\\\Prophecy\\\\Reflection\\\\ObjectProphecyMethodReflection constructor expects PHPStan\\\\Reflection\\\\ClassReflection, object given\\.$#" + count: 2 + path: test/Unit/Reflection/ObjectProphecyMethodReflectionTest.php + diff --git a/phpstan-without-extension.neon b/phpstan-without-extension.neon new file mode 100644 index 0000000..3822b79 --- /dev/null +++ b/phpstan-without-extension.neon @@ -0,0 +1,10 @@ +includes: + - phpstan-without-extension-baseline.neon + +parameters: + inferPrivatePropertyTypeFromConstructor: true + level: max + paths: + - src/ + - test/ + tmpDir: .build/phpstan diff --git a/phpstan.neon b/phpstan.neon deleted file mode 100644 index aa4c807..0000000 --- a/phpstan.neon +++ /dev/null @@ -1,13 +0,0 @@ -includes: - - extension.neon - -parameters: - ignoreErrors: - - '#^Method .* has no return typehint specified\.$#' - - '#^Property .* has no typehint specified\.$#' - inferPrivatePropertyTypeFromConstructor: true - level: max - paths: - - src - - test - tmpDir: .build/phpstan