Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Use baseline feature to run phpstan with and without extension #149

Merged
merged 1 commit into from
Mar 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions phpstan-with-extension-baseline.neon
Original file line number Diff line number Diff line change
@@ -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

11 changes: 11 additions & 0 deletions phpstan-with-extension.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
includes:
- extension.neon
- phpstan-with-extension-baseline.neon

parameters:
inferPrivatePropertyTypeFromConstructor: true
level: max
paths:
- src/
- test/
tmpDir: .build/phpstan
97 changes: 97 additions & 0 deletions phpstan-without-extension-baseline.neon
Original file line number Diff line number Diff line change
@@ -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

10 changes: 10 additions & 0 deletions phpstan-without-extension.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
includes:
- phpstan-without-extension-baseline.neon

parameters:
inferPrivatePropertyTypeFromConstructor: true
level: max
paths:
- src/
- test/
tmpDir: .build/phpstan
13 changes: 0 additions & 13 deletions phpstan.neon

This file was deleted.