Add PHPStan workflow and baseline (#1222)

This commit is contained in:
Martin Rademacher 2022-05-04 09:57:50 +12:00 committed by GitHub
parent e6d00f9903
commit f0b3b8d23d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 138 additions and 10 deletions

View File

@ -24,5 +24,5 @@ jobs:
with:
dependency-versions: 'highest'
- name: Static Code Analysis
- name: Check Code Style
run: composer lint

28
.github/workflows/phpstan.yml vendored Normal file
View File

@ -0,0 +1,28 @@
name: phpstan
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
phpstan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Checkout repository
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
- uses: ramsey/composer-install@v1
with:
dependency-versions: 'highest'
- name: Static Code Analysis
run: composer analyse

View File

@ -59,6 +59,7 @@
"require-dev": {
"composer/package-versions-deprecated": "^1.11",
"friendsofphp/php-cs-fixer": "^2.17 || ^3.0",
"phpstan/phpstan": "^1.6",
"phpunit/phpunit": ">=8"
},
"autoload-dev": {
@ -84,8 +85,7 @@
"@testlegacy"
],
"analyse": [
"phpstan analyse --memory-limit=2G",
"psalm --show-info=true"
"phpstan analyse --memory-limit=2G"
],
"spectral": "for ff in `find Examples -name '*.yaml'`; do spectral lint $ff; done",
"docs:dev": "cd docs && npm run dev",

102
phpstan-baseline.neon Normal file
View File

@ -0,0 +1,102 @@
parameters:
ignoreErrors:
-
message: "#^Access to an undefined property OpenApi\\\\Annotations\\\\AbstractAnnotation\\:\\:\\$description\\.$#"
count: 1
path: src/Annotations/AbstractAnnotation.php
-
message: "#^Access to an undefined property OpenApi\\\\Annotations\\\\AbstractAnnotation\\:\\:\\$summary\\.$#"
count: 1
path: src/Annotations/AbstractAnnotation.php
-
message: "#^Variable \\$name might not be defined\\.$#"
count: 2
path: src/Annotations/Components.php
-
message: "#^Variable \\$type might not be defined\\.$#"
count: 1
path: src/Annotations/Components.php
-
message: "#^Property OpenApi\\\\Annotations\\\\Flow\\:\\:\\$scopes \\(array\\) does not accept stdClass\\.$#"
count: 1
path: src/Annotations/Flow.php
-
message: "#^Access to an undefined property object\\:\\:\\$enum\\.$#"
count: 1
path: src/Annotations/Schema.php
-
message: "#^Else branch is unreachable because previous condition is always true\\.$#"
count: 1
path: src/Context.php
-
message: "#^Ternary operator condition is always true\\.$#"
count: 1
path: src/Context.php
-
message: "#^If condition is always true\\.$#"
count: 1
path: src/Generator.php
-
message: "#^Instanceof between callable and class\\-string\\|false results in an error\\.$#"
count: 1
path: src/Generator.php
-
message: "#^Variable \\$logLine in empty\\(\\) always exists and is not falsy\\.$#"
count: 1
path: src/Loggers/ConsoleLogger.php
-
message: "#^Call to function is_array\\(\\) with bool\\|OpenApi\\\\Annotations\\\\AdditionalProperties will always evaluate to false\\.$#"
count: 1
path: src/Processors/AugmentSchemas.php
-
message: "#^Property OpenApi\\\\Annotations\\\\Schema\\:\\:\\$properties \\(array\\<OpenApi\\\\Annotations\\\\Property\\>\\) does not accept string\\.$#"
count: 1
path: src/Processors/AugmentSchemas.php
-
message: "#^Result of && is always false\\.$#"
count: 1
path: src/Processors/AugmentSchemas.php
-
message: "#^Property OpenApi\\\\Annotations\\\\JsonContent\\:\\:\\$examples \\(array\\<string, OpenApi\\\\Annotations\\\\Examples\\>\\) does not accept string\\.$#"
count: 1
path: src/Processors/MergeJsonContent.php
-
message: "#^Property OpenApi\\\\Annotations\\\\XmlContent\\:\\:\\$examples \\(array\\<string, OpenApi\\\\Annotations\\\\Examples\\>\\) does not accept string\\.$#"
count: 1
path: src/Processors/MergeXmlContent.php
-
message: "#^Parameter \\#1 \\$callback of function spl_autoload_register expects \\(callable\\(string\\)\\: void\\)\\|null, array\\{Composer\\\\Autoload\\\\ClassLoader, 'findFile'\\} given\\.$#"
count: 1
path: tests/Analysers/ComposerAutoloaderScannerTest.php
-
message: "#^Access to an undefined property OpenApi\\\\Analysers\\\\AnnotationFactoryInterface\\:\\:\\$reflectors\\.$#"
count: 2
path: tests/Analysers/ReflectionAnalyserTest.php
-
message: "#^Access to an undefined property Reflector\\:\\:\\$name\\.$#"
count: 1
path: tests/Analysers/ReflectionAnalyserTest.php
-
message: "#^Call to an undefined method ReflectionType\\:\\:getName\\(\\)\\.$#"
count: 1
path: tests/Annotations/AttributesSyncTest.php

View File

@ -1,3 +1,6 @@
includes:
- phpstan-baseline.neon
parameters:
level: 5
paths:

View File

@ -18,7 +18,7 @@ use OpenApi\Generator;
class JsonContent extends Schema
{
/**
* @var array
* @var array<string,Examples>
*/
public $examples = Generator::UNDEFINED;

View File

@ -20,7 +20,6 @@ class AdditionalProperties extends \OpenApi\Annotations\AdditionalProperties
* @param Schema[] $allOf
* @param Schema[] $anyOf
* @param Schema[] $oneOf
* @param mixed $const
* @param array<string,string>|null $x
* @param Attachable[]|null $attachables
*/

View File

@ -20,7 +20,6 @@ class Items extends \OpenApi\Annotations\Items
* @param Schema[] $allOf
* @param Schema[] $anyOf
* @param Schema[] $oneOf
* @param mixed $const
* @param array<string,string>|null $x
* @param Attachable[]|null $attachables
*/

View File

@ -12,6 +12,7 @@ use OpenApi\Generator;
class JsonContent extends \OpenApi\Annotations\JsonContent
{
/**
* @param array<string,Examples> $examples
* @param string[] $required
* @param Property[] $properties
* @param int|float $maximum
@ -20,7 +21,6 @@ class JsonContent extends \OpenApi\Annotations\JsonContent
* @param Schema[] $allOf
* @param Schema[] $anyOf
* @param Schema[] $oneOf
* @param mixed $const
* @param array<string,string>|null $x
* @param Attachable[]|null $attachables
*/

View File

@ -12,7 +12,6 @@ trait ParameterTrait
{
/**
* @param array<string,Examples> $examples
* @param MediaType[] $content
* @param array<string,string>|null $x
* @param Attachable[]|null $attachables
*/

View File

@ -20,7 +20,6 @@ class Property extends \OpenApi\Annotations\Property
* @param Schema[] $allOf
* @param Schema[] $anyOf
* @param Schema[] $oneOf
* @param mixed $const
* @param array<string,string>|null $x
* @param Attachable[]|null $attachables
*/

View File

@ -21,7 +21,6 @@ class XmlContent extends \OpenApi\Annotations\XmlContent
* @param Schema[] $allOf
* @param Schema[] $anyOf
* @param Schema[] $oneOf
* @param mixed $const
* @param array<string,string>|null $x
* @param Attachable[]|null $attachables
*/