Skip to content

Introduce Phpstan #456

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

Merged
merged 19 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
24 changes: 24 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: "Static analysis"

on:
push:
branches:
- '[0-9]+.x'
- '[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.x'
pull_request:

jobs:
phpstan:
name: "PHPStan"
runs-on: "ubuntu-latest"

steps:
- name: "Checkout"
uses: "actions/checkout@v3"
- name: PHPStan
uses: "docker://oskarstark/phpstan-ga"
env:
REQUIRE_DEV: true
with:
args: analyze --no-progress
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Static analysis"
name: "PHP-CS-Fixer"

on:
push:
Expand All @@ -9,8 +9,8 @@ on:
pull_request:

jobs:
coding-standards:
name: "Coding Standards"
php-cs-fixer:
name: "PHP-CS-Fixer"
runs-on: "ubuntu-latest"

steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
/build/
/composer.lock
/phpspec.yml
/phpstan.neon
/phpunit.xml
/vendor/
11 changes: 4 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@
},
"conflict": {
"php-http/guzzle6-adapter": "<1.1",
"php-http/cache-plugin": "<1.7.0",
"php-http/cache-plugin": "<1.7",
"php-http/curl-client": "<2.0",
"php-http/socket-client": "<2.0",
"kriswallsmith/buzz": "<0.17",
"php-http/react-adapter": "<3.0",
"php-http/cache-plugin": "<1.7"
"php-http/react-adapter": "<3.0"
},
"require-dev": {
"guzzlehttp/psr7": "^1.7 || ^2.0",
Expand All @@ -58,6 +57,7 @@
"php-http/cache-plugin": "^1.7",
"php-http/mock-client": "^1.2",
"php-http/promise": "^1.0",
"phpstan/phpstan-symfony": "^1.2",
"symfony/browser-kit": "^5.4 || ^6.0 || ^7.0",
"symfony/cache": "^5.4 || ^6.0 || ^7.0",
"symfony/dom-crawler": "^5.4 || ^6.0 || ^7.0",
Expand All @@ -84,10 +84,7 @@
"autoload": {
"psr-4": {
"Http\\HttplugBundle\\": "src/"
},
"exclude-from-classmap": [
"/Tests/Resources/MyPsr18TestClient.php"
]
}
},
"autoload-dev": {
"psr-4": {
Expand Down
31 changes: 31 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
parameters:
ignoreErrors:
-
message: "#^Call to static method create\\(\\) on an unknown class Symfony\\\\Component\\\\HttpClient\\\\HttpClient\\.$#"
count: 1
path: src/ClientFactory/SymfonyFactory.php
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess this means we don't test the factory, otherwise we would depend on the symfony http client.

we should probably add that, but in a separate merge request. and its no blocker for releasing 2.0


-
message: "#^Class Http\\\\Client\\\\Plugin\\\\Vcr\\\\NamingStrategy\\\\NamingStrategyInterface not found\\.$#"
count: 1
path: src/DependencyInjection/Configuration.php
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the code properly handle a missing vcr plugin? if it does its okay i guess.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could composer require the vcr plugin in a first step of the phpstan job, to have it validate correctly. the php tests would discover if we messed up with validation.

some nice to haves would be to have the configuration class error when configuring without vcr without having the plugin installed, and https://github.com/php-http/HttplugBundle/blob/b7ad2c1951edec36ef0bd9897e309b0038c59a54/src/DependencyInjection/HttplugExtension.php should throw an exception at the beginning of the method if vcr is not available.

but probably this still not enough to make phpstan happy, so composer require step for this could be added. that means that phpstan locally would complain about those though 🤔

we can also merge the current state and continue in separate pull requests.


-
message: "#^Class Http\\\\Client\\\\Plugin\\\\Vcr\\\\Recorder\\\\PlayerInterface not found\\.$#"
count: 1
path: src/DependencyInjection/Configuration.php

-
message: "#^Class Http\\\\Client\\\\Plugin\\\\Vcr\\\\Recorder\\\\RecorderInterface not found\\.$#"
count: 1
path: src/DependencyInjection/Configuration.php

-
message: "#^Class Http\\\\Client\\\\Plugin\\\\Vcr\\\\RecordPlugin not found\\.$#"
count: 1
path: src/DependencyInjection/HttplugExtension.php

-
message: "#^Class Http\\\\Client\\\\Plugin\\\\Vcr\\\\ReplayPlugin not found\\.$#"
count: 1
path: src/DependencyInjection/HttplugExtension.php
12 changes: 12 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
includes:
- phpstan-baseline.neon
- vendor/phpstan/phpstan-symfony/extension.neon
- vendor/phpstan/phpstan-symfony/rules.neon

parameters:
scanFiles:
- vendor/symfony/dependency-injection/Loader/Configurator/ContainerConfigurator.php

level: 1
paths:
- src
Loading