Skip to content

Commit

Permalink
Refactoring/upgrading code to work with phpstan.
Browse files Browse the repository at this point in the history
  • Loading branch information
elb98rm committed Apr 19, 2021
1 parent 1c215a4 commit 9a7f983
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 94 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ before_script:
script:
- XDEBUG_MODE=coverage ./vendor/phpunit/phpunit/phpunit --coverage-html docs/tests/
- XDEBUG_MODE=coverage ./vendor/phpunit/phpunit/phpunit --coverage-text --coverage-clover=coverage.clover
- ./vendor/bin/phpstan

after_success:
- bash <(curl -s https://codecov.io/bash)
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ Tests can be run as follows:

* `./vendor/phpunit/phpunit/phpunit`

Static analysis/code review can be performed by using [phpstan](https://phpstan.org/):

* `./vendor/bin/phpstan`

The following tests and also creates code coverage (usually maintained at 100%)

* `./vendor/phpunit/phpunit/phpunit --coverage-html docs/tests/`
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"require-dev": {
"floor9design/testing-tools": "*",
"mockery/mockery": "dev-master",
"phpstan/phpstan": "^0.12.83",
"phpunit/phpunit": "^9.0"
},
"autoload": {
Expand Down
62 changes: 61 additions & 1 deletion composer.lock

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

4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: max
paths:
- src
5 changes: 5 additions & 0 deletions src/Models/DataResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class DataResource
var ?string $type = null;

/**
* @phpstan-var array[]
* @var array|null
*/
var ?array $attributes = null;
Expand Down Expand Up @@ -99,6 +100,7 @@ public function setType(?string $type): DataResource
}

/**
* @phpstan-return array[]|null
* @return array|null
* @see $attributes
*/
Expand All @@ -108,6 +110,7 @@ public function getAttributes(): ?array
}

/**
* @phpstan-param array[]|null $attributes
* @param array|null $attributes
* @return DataResource
* @see $attributes
Expand All @@ -124,6 +127,7 @@ public function setAttributes(?array $attributes): DataResource
* DataResource constructor.
* @param string|null $id
* @param string|null $type
* @phpstan-param array[]|null $attributes
* @param array|null $attributes
*/
public function __construct(
Expand All @@ -138,6 +142,7 @@ public function __construct(
}

/**
* @phpstan-return array{id:string|null,type:string|null,attributes:array[]|null}
* @return array
*/
public function toArray(): array
Expand Down
4 changes: 2 additions & 2 deletions src/Models/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public function setSource(?object $source): Error
* @param string|null $code
* @param string|null $title
* @param string|null $detail
* @param string|null $source
* @param object|null $source
*/
public function __construct(
?string $id = null,
Expand All @@ -250,7 +250,7 @@ public function __construct(
}

/**
* @return array
* @return array<string, object|string|null>
*/
public function toArray(): array
{
Expand Down
Loading

0 comments on commit 9a7f983

Please sign in to comment.