From d9404cce414fd41e867760afce01108ceca22e0b Mon Sep 17 00:00:00 2001 From: BafS Date: Mon, 30 Oct 2023 11:16:10 +0100 Subject: [PATCH] Add PHPStan, fix some issues --- .github/workflows/static.yml | 31 ++++++++++++ .github/workflows/{php.yml => tests.yml} | 2 +- composer.json | 3 +- composer.lock | 64 +++++++++++++++++++++++- src/Builder/AttributeBuilder.php | 4 +- src/Model/Resource.php | 4 +- src/Model/Schema/Attribute.php | 12 ++--- src/Validator/ValidationResult.php | 2 +- 8 files changed, 107 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/static.yml rename .github/workflows/{php.yml => tests.yml} (96%) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 0000000..ddec332 --- /dev/null +++ b/.github/workflows/static.yml @@ -0,0 +1,31 @@ +name: PHP static analysis + +on: + push: + branches: [ master, main ] + pull_request: + branches: [ master, main ] + +jobs: + ci: + runs-on: ubuntu-latest + strategy: + matrix: + php: ['8.2'] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v2 + coverage: none + + - name: Install Dependencies + run: composer update --no-interaction --no-progress --ansi + + - name: PhpStan + run: ./vendor/bin/phpstan analyse diff --git a/.github/workflows/php.yml b/.github/workflows/tests.yml similarity index 96% rename from .github/workflows/php.yml rename to .github/workflows/tests.yml index 6bf96fd..4c5b3bd 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/tests.yml @@ -1,4 +1,4 @@ -name: PHP Unit/Quality CI +name: PHP unit tests on: push: diff --git a/composer.json b/composer.json index 9dade69..bb045df 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ }, "require-dev": { "phpunit/phpunit": "^9.0|^10.0", - "php-coveralls/php-coveralls": "^2.0" + "php-coveralls/php-coveralls": "^2.0", + "phpstan/phpstan": "^1.10" }, "minimum-stability": "stable" } diff --git a/composer.lock b/composer.lock index 8df589b..f4cf8ab 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c78b87801a88bcc9853de710eb7e59c3", + "content-hash": "2554a0c445e95b80747429c009319ed9", "packages": [], "packages-dev": [ { @@ -641,6 +641,68 @@ }, "time": "2023-07-16T08:39:10+00:00" }, + { + "name": "phpstan/phpstan", + "version": "1.10.39", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "d9dedb0413f678b4d03cbc2279a48f91592c97c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d9dedb0413f678b4d03cbc2279a48f91592c97c4", + "reference": "d9dedb0413f678b4d03cbc2279a48f91592c97c4", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2023-10-17T15:46:26+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "10.1.7", diff --git a/src/Builder/AttributeBuilder.php b/src/Builder/AttributeBuilder.php index 619ef1c..49c047e 100644 --- a/src/Builder/AttributeBuilder.php +++ b/src/Builder/AttributeBuilder.php @@ -196,7 +196,7 @@ public function addSubAttributes(array $attributes) } /** - * @param \string[] $canonicalValues + * @param string[] $canonicalValues * * @return AttributeBuilder */ @@ -208,7 +208,7 @@ public function setCanonicalValues(array $canonicalValues) } /** - * @param \string[] $referenceTypes + * @param string[] $referenceTypes * * @return AttributeBuilder */ diff --git a/src/Model/Resource.php b/src/Model/Resource.php index 1843b1a..07a58ab 100644 --- a/src/Model/Resource.php +++ b/src/Model/Resource.php @@ -44,7 +44,7 @@ public function __construct($id) abstract public function getResourceType(); /** - * @return \string[] + * @return string[] */ public function getSchemas() { @@ -123,7 +123,7 @@ public function serializeObject() if (!$extension) { continue; } - if ($extension instanceof ResourceExtension) { + if ($extension instanceof SerializableInterface) { $result[$schemaId] = $extension->serializeObject(); } elseif (is_array($extension)) { $result[$schemaId] = $extension; diff --git a/src/Model/Schema/Attribute.php b/src/Model/Schema/Attribute.php index c73551f..619bce5 100644 --- a/src/Model/Schema/Attribute.php +++ b/src/Model/Schema/Attribute.php @@ -59,12 +59,12 @@ class Attribute implements SerializableInterface * @param bool $required * @param string $description * @param Attribute[] $subAttributes - * @param \string[] $canonicalValues + * @param string[] $canonicalValues * @param bool $caseExact * @param string $mutability * @param string $returned * @param string $uniqueness - * @param \string[] $referenceTypes + * @param string[] $referenceTypes */ public function __construct( $name, @@ -143,7 +143,7 @@ public function getSubAttributes() } /** - * @return \string[] + * @return string[] */ public function getCanonicalValues() { @@ -183,7 +183,7 @@ public function getUniqueness() } /** - * @return \string[] + * @return string[] */ public function getReferenceTypes() { @@ -274,7 +274,7 @@ public static function deserializeObject(array $data) $subAttributes[] = static::deserializeObject($subAttribute); } } - $result = new static( + return new static( $data['name'], $data['type'], $data['multiValued'], @@ -288,7 +288,5 @@ public static function deserializeObject(array $data) isset($data['uniqueness']) ? $data['uniqueness'] : null, isset($data['referenceTypes']) ? $data['referenceTypes'] : [] ); - - return $result; } } diff --git a/src/Validator/ValidationResult.php b/src/Validator/ValidationResult.php index 9829ad7..28210a2 100644 --- a/src/Validator/ValidationResult.php +++ b/src/Validator/ValidationResult.php @@ -54,7 +54,7 @@ public function getErrors() } /** - * @return \string[] + * @return string[] */ public function getErrorsAsStrings() {