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

Add PHPStan, fix some issues #3

Merged
merged 1 commit into from
Oct 30, 2023
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
31 changes: 31 additions & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .github/workflows/php.yml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: PHP Unit/Quality CI
name: PHP unit tests

on:
push:
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
64 changes: 63 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
parameters:
level: 2
paths:
- src/
- tests/

ignoreErrors:
- '#Unsafe usage of new static.+#'
4 changes: 2 additions & 2 deletions src/Builder/AttributeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function addSubAttributes(array $attributes)
}

/**
* @param \string[] $canonicalValues
* @param string[] $canonicalValues
*
* @return AttributeBuilder
*/
Expand All @@ -208,7 +208,7 @@ public function setCanonicalValues(array $canonicalValues)
}

/**
* @param \string[] $referenceTypes
* @param string[] $referenceTypes
*
* @return AttributeBuilder
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Model/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct($id)
abstract public function getResourceType();

/**
* @return \string[]
* @return string[]
*/
public function getSchemas()
{
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 5 additions & 7 deletions src/Model/Schema/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -143,7 +143,7 @@ public function getSubAttributes()
}

/**
* @return \string[]
* @return string[]
*/
public function getCanonicalValues()
{
Expand Down Expand Up @@ -183,7 +183,7 @@ public function getUniqueness()
}

/**
* @return \string[]
* @return string[]
*/
public function getReferenceTypes()
{
Expand Down Expand Up @@ -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'],
Expand All @@ -288,7 +288,5 @@ public static function deserializeObject(array $data)
isset($data['uniqueness']) ? $data['uniqueness'] : null,
isset($data['referenceTypes']) ? $data['referenceTypes'] : []
);

return $result;
}
}
2 changes: 1 addition & 1 deletion src/Validator/ValidationResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function getErrors()
}

/**
* @return \string[]
* @return string[]
*/
public function getErrorsAsStrings()
{
Expand Down