diff --git a/src/Accessable.php b/src/Accessable.php index ec46ab1..069da12 100644 --- a/src/Accessable.php +++ b/src/Accessable.php @@ -8,6 +8,8 @@ namespace Art4\JsonApiClient; +use Art4\JsonApiClient\Helper\AccessKey; + /** * Accessable Interface */ @@ -16,7 +18,7 @@ interface Accessable /** * Get a value by a key * - * @param mixed $key The key + * @param int|string|AccessKey $key The key * * @return mixed */ @@ -27,7 +29,7 @@ public function get($key); * * @deprecated `\Art4\JsonApiClient\Accessable::has()` will add `bool` as a native return type declaration in v2.0. Do the same in your implementation now to avoid errors. * - * @param mixed $key The key + * @param int|string|AccessKey $key The key * * @return bool */ @@ -39,7 +41,7 @@ public function has($key); * * @deprecated `\Art4\JsonApiClient\Accessable::getKeys()` will add `array` as a native return type declaration in v2.0. Do the same in your implementation now to avoid errors. * - * @return array Keys of all setted values + * @return array Keys of all setted values */ public function getKeys(); // public function getKeys(): array; diff --git a/src/Helper/AccessableTrait.php b/src/Helper/AccessableTrait.php index 81eb8bf..d9d690a 100644 --- a/src/Helper/AccessableTrait.php +++ b/src/Helper/AccessableTrait.php @@ -41,7 +41,7 @@ final protected function set(string $key, $value): void /** * Returns the keys of all setted values * - * @return array Keys of all setted values + * @return array Keys of all setted values */ final public function getKeys(): array { @@ -51,7 +51,7 @@ final public function getKeys(): array /** * Check if a value exists * - * @param mixed $key The key + * @param int|string|AccessKey $key The key */ final public function has($key): bool { @@ -82,7 +82,7 @@ final public function has($key): bool /** * Get a value by a key * - * @param mixed $key The key + * @param int|string|AccessKey $key The key * * @return mixed */ @@ -126,7 +126,7 @@ private function getValue(string $key) /** * Parse a dot.notated.key to an object * - * @param string|AccessKey $key The key + * @param int|string|AccessKey $key The key * * @return AccessKey The parsed key */ diff --git a/src/Serializer/ArraySerializer.php b/src/Serializer/ArraySerializer.php index 42d1491..422037f 100644 --- a/src/Serializer/ArraySerializer.php +++ b/src/Serializer/ArraySerializer.php @@ -35,7 +35,7 @@ public function __construct(array $params = []) /** * Convert data in an array * - * @return array|null + * @return array|null */ public function serialize(Accessable $data): ?array { diff --git a/src/V1/Attributes.php b/src/V1/Attributes.php index 918dcf3..9306362 100644 --- a/src/V1/Attributes.php +++ b/src/V1/Attributes.php @@ -8,9 +8,11 @@ namespace Art4\JsonApiClient\V1; -use Art4\JsonApiClient\Helper\AbstractElement; use Art4\JsonApiClient\Exception\AccessException; use Art4\JsonApiClient\Exception\ValidationException; +use Art4\JsonApiClient\Helper\AbstractElement; +use Art4\JsonApiClient\Helper\AccessKey; + /** * Attributes Object @@ -50,7 +52,7 @@ protected function parse($object): void /** * Get a value by the key of this object * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value * * @return mixed The value */ diff --git a/src/V1/Document.php b/src/V1/Document.php index ff3194d..4e971cb 100644 --- a/src/V1/Document.php +++ b/src/V1/Document.php @@ -9,9 +9,10 @@ namespace Art4\JsonApiClient\V1; use Art4\JsonApiClient\Accessable; -use Art4\JsonApiClient\Helper\AbstractElement; use Art4\JsonApiClient\Exception\AccessException; use Art4\JsonApiClient\Exception\ValidationException; +use Art4\JsonApiClient\Helper\AbstractElement; +use Art4\JsonApiClient\Helper\AccessKey; /** * Document Top Level Object @@ -73,7 +74,7 @@ protected function parse($object): void /** * Get a value by the key of this object * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value * * @return mixed The value */ diff --git a/src/V1/DocumentLink.php b/src/V1/DocumentLink.php index 30ab3c3..4d0dc0b 100644 --- a/src/V1/DocumentLink.php +++ b/src/V1/DocumentLink.php @@ -8,9 +8,10 @@ namespace Art4\JsonApiClient\V1; -use Art4\JsonApiClient\Helper\AbstractElement; use Art4\JsonApiClient\Exception\AccessException; use Art4\JsonApiClient\Exception\ValidationException; +use Art4\JsonApiClient\Helper\AbstractElement; +use Art4\JsonApiClient\Helper\AccessKey; /** * Document Link Object @@ -103,7 +104,7 @@ protected function parse($object): void /** * Get a value by the key of this object * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value * * @return mixed The value */ diff --git a/src/V1/Error.php b/src/V1/Error.php index 69c2f7b..346cd55 100644 --- a/src/V1/Error.php +++ b/src/V1/Error.php @@ -8,9 +8,10 @@ namespace Art4\JsonApiClient\V1; -use Art4\JsonApiClient\Helper\AbstractElement; use Art4\JsonApiClient\Exception\AccessException; use Art4\JsonApiClient\Exception\ValidationException; +use Art4\JsonApiClient\Helper\AbstractElement; +use Art4\JsonApiClient\Helper\AccessKey; /** * Error Object @@ -105,7 +106,7 @@ protected function parse($object): void /** * Get a value by the key of this object * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value * * @return mixed The value */ diff --git a/src/V1/ErrorCollection.php b/src/V1/ErrorCollection.php index 42def2f..b61e0f2 100644 --- a/src/V1/ErrorCollection.php +++ b/src/V1/ErrorCollection.php @@ -8,9 +8,10 @@ namespace Art4\JsonApiClient\V1; -use Art4\JsonApiClient\Helper\AbstractElement; use Art4\JsonApiClient\Exception\AccessException; use Art4\JsonApiClient\Exception\ValidationException; +use Art4\JsonApiClient\Helper\AbstractElement; +use Art4\JsonApiClient\Helper\AccessKey; /** * Error Collection Object @@ -44,7 +45,7 @@ protected function parse($object): void /** * Get a value by the key of this document * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value * * @return mixed The value */ diff --git a/src/V1/ErrorLink.php b/src/V1/ErrorLink.php index 112d09b..6c08772 100644 --- a/src/V1/ErrorLink.php +++ b/src/V1/ErrorLink.php @@ -8,9 +8,10 @@ namespace Art4\JsonApiClient\V1; -use Art4\JsonApiClient\Helper\AbstractElement; use Art4\JsonApiClient\Exception\AccessException; use Art4\JsonApiClient\Exception\ValidationException; +use Art4\JsonApiClient\Helper\AbstractElement; +use Art4\JsonApiClient\Helper\AccessKey; /** * Error Link Object @@ -63,7 +64,7 @@ protected function parse($object): void /** * Get a value by the key of this object * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value * * @return mixed The value */ diff --git a/src/V1/ErrorSource.php b/src/V1/ErrorSource.php index 3c70b99..e8136e2 100644 --- a/src/V1/ErrorSource.php +++ b/src/V1/ErrorSource.php @@ -8,9 +8,10 @@ namespace Art4\JsonApiClient\V1; -use Art4\JsonApiClient\Helper\AbstractElement; use Art4\JsonApiClient\Exception\AccessException; use Art4\JsonApiClient\Exception\ValidationException; +use Art4\JsonApiClient\Helper\AbstractElement; +use Art4\JsonApiClient\Helper\AccessKey; /** * Error Source Object @@ -52,7 +53,7 @@ protected function parse($object): void /** * Get a value by the key of this document * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value * * @return mixed The value */ diff --git a/src/V1/Jsonapi.php b/src/V1/Jsonapi.php index db56bef..6a5acbb 100644 --- a/src/V1/Jsonapi.php +++ b/src/V1/Jsonapi.php @@ -8,9 +8,10 @@ namespace Art4\JsonApiClient\V1; -use Art4\JsonApiClient\Helper\AbstractElement; use Art4\JsonApiClient\Exception\AccessException; use Art4\JsonApiClient\Exception\ValidationException; +use Art4\JsonApiClient\Helper\AbstractElement; +use Art4\JsonApiClient\Helper\AccessKey; /** * JSON API Object @@ -48,7 +49,7 @@ protected function parse($object): void /** * Get a value by the key of this object * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value * * @return mixed The value */ diff --git a/src/V1/Link.php b/src/V1/Link.php index 1c07bae..6489924 100644 --- a/src/V1/Link.php +++ b/src/V1/Link.php @@ -8,9 +8,10 @@ namespace Art4\JsonApiClient\V1; -use Art4\JsonApiClient\Helper\AbstractElement; use Art4\JsonApiClient\Exception\AccessException; use Art4\JsonApiClient\Exception\ValidationException; +use Art4\JsonApiClient\Helper\AbstractElement; +use Art4\JsonApiClient\Helper\AccessKey; /** * Link Object @@ -44,7 +45,7 @@ protected function parse($object): void /** * Get a value by the key of this object * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value * * @return mixed The value */ diff --git a/src/V1/Meta.php b/src/V1/Meta.php index 5836bab..db1dcc1 100644 --- a/src/V1/Meta.php +++ b/src/V1/Meta.php @@ -8,9 +8,10 @@ namespace Art4\JsonApiClient\V1; -use Art4\JsonApiClient\Helper\AbstractElement; use Art4\JsonApiClient\Exception\AccessException; use Art4\JsonApiClient\Exception\ValidationException; +use Art4\JsonApiClient\Helper\AbstractElement; +use Art4\JsonApiClient\Helper\AccessKey; /** * Meta Object @@ -46,7 +47,7 @@ protected function parse($object): void /** * Get a value by the key of this object * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value * * @return mixed The value */ diff --git a/src/V1/Relationship.php b/src/V1/Relationship.php index 5a842cf..ec6b0a4 100644 --- a/src/V1/Relationship.php +++ b/src/V1/Relationship.php @@ -8,9 +8,10 @@ namespace Art4\JsonApiClient\V1; -use Art4\JsonApiClient\Helper\AbstractElement; use Art4\JsonApiClient\Exception\AccessException; use Art4\JsonApiClient\Exception\ValidationException; +use Art4\JsonApiClient\Helper\AbstractElement; +use Art4\JsonApiClient\Helper\AccessKey; /** * Resource Identifier Object @@ -59,7 +60,7 @@ protected function parse($object): void /** * Get a value by the key of this object * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value * * @return mixed The value */ diff --git a/src/V1/RelationshipCollection.php b/src/V1/RelationshipCollection.php index 49680f0..fd9c9dc 100644 --- a/src/V1/RelationshipCollection.php +++ b/src/V1/RelationshipCollection.php @@ -8,9 +8,10 @@ namespace Art4\JsonApiClient\V1; -use Art4\JsonApiClient\Helper\AbstractElement; use Art4\JsonApiClient\Exception\AccessException; use Art4\JsonApiClient\Exception\ValidationException; +use Art4\JsonApiClient\Helper\AbstractElement; +use Art4\JsonApiClient\Helper\AccessKey; /** * Relationship Collection Object @@ -54,7 +55,7 @@ protected function parse($object): void /** * Get a value by the key of this object * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value * * @return mixed The value */ diff --git a/src/V1/RelationshipLink.php b/src/V1/RelationshipLink.php index 84b1c59..3cb303f 100644 --- a/src/V1/RelationshipLink.php +++ b/src/V1/RelationshipLink.php @@ -11,6 +11,7 @@ use Art4\JsonApiClient\Exception\AccessException; use Art4\JsonApiClient\Exception\ValidationException; use Art4\JsonApiClient\Helper\AbstractElement; +use Art4\JsonApiClient\Helper\AccessKey; /** * Relationship Link Object @@ -105,7 +106,7 @@ protected function parse($object): void /** * Get a value by the key of this object * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value * * @return mixed The value */ diff --git a/src/V1/ResourceCollection.php b/src/V1/ResourceCollection.php index 4577e2b..2b515e0 100644 --- a/src/V1/ResourceCollection.php +++ b/src/V1/ResourceCollection.php @@ -9,9 +9,10 @@ namespace Art4\JsonApiClient\V1; use Art4\JsonApiClient\Accessable; -use Art4\JsonApiClient\Helper\AbstractElement; use Art4\JsonApiClient\Exception\AccessException; use Art4\JsonApiClient\Exception\ValidationException; +use Art4\JsonApiClient\Helper\AbstractElement; +use Art4\JsonApiClient\Helper\AccessKey; /** * Resource Object @@ -47,7 +48,7 @@ protected function parse($object): void /** * Get a value by the key of this object * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value * * @return mixed The value */ diff --git a/src/V1/ResourceIdentifier.php b/src/V1/ResourceIdentifier.php index 26e6b2c..df39116 100644 --- a/src/V1/ResourceIdentifier.php +++ b/src/V1/ResourceIdentifier.php @@ -8,9 +8,10 @@ namespace Art4\JsonApiClient\V1; -use Art4\JsonApiClient\Helper\AbstractElement; use Art4\JsonApiClient\Exception\AccessException; use Art4\JsonApiClient\Exception\ValidationException; +use Art4\JsonApiClient\Helper\AbstractElement; +use Art4\JsonApiClient\Helper\AccessKey; /** * Resource Identifier Object @@ -59,7 +60,7 @@ protected function parse($object): void /** * Get a value by the key of this object * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value * * @return mixed The value */ diff --git a/src/V1/ResourceIdentifierCollection.php b/src/V1/ResourceIdentifierCollection.php index a887070..e820d37 100644 --- a/src/V1/ResourceIdentifierCollection.php +++ b/src/V1/ResourceIdentifierCollection.php @@ -8,9 +8,10 @@ namespace Art4\JsonApiClient\V1; -use Art4\JsonApiClient\Helper\AbstractElement; use Art4\JsonApiClient\Exception\AccessException; use Art4\JsonApiClient\Exception\ValidationException; +use Art4\JsonApiClient\Helper\AbstractElement; +use Art4\JsonApiClient\Helper\AccessKey; /** * Resource Object @@ -42,7 +43,7 @@ protected function parse($object): void /** * Get a value by the key of this object * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value * * @return mixed The value */ diff --git a/src/V1/ResourceItem.php b/src/V1/ResourceItem.php index caae85a..35c43b0 100644 --- a/src/V1/ResourceItem.php +++ b/src/V1/ResourceItem.php @@ -8,9 +8,10 @@ namespace Art4\JsonApiClient\V1; -use Art4\JsonApiClient\Helper\AbstractElement; use Art4\JsonApiClient\Exception\AccessException; use Art4\JsonApiClient\Exception\ValidationException; +use Art4\JsonApiClient\Helper\AbstractElement; +use Art4\JsonApiClient\Helper\AccessKey; /** * Resource Identifier Object @@ -77,7 +78,7 @@ protected function parse($object): void /** * Get a value by the key of this object * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value * * @return mixed The value */ diff --git a/src/V1/ResourceItemLink.php b/src/V1/ResourceItemLink.php index 69ce850..5315593 100644 --- a/src/V1/ResourceItemLink.php +++ b/src/V1/ResourceItemLink.php @@ -8,9 +8,10 @@ namespace Art4\JsonApiClient\V1; -use Art4\JsonApiClient\Helper\AbstractElement; use Art4\JsonApiClient\Exception\AccessException; use Art4\JsonApiClient\Exception\ValidationException; +use Art4\JsonApiClient\Helper\AbstractElement; +use Art4\JsonApiClient\Helper\AccessKey; /** * ItemLink Object @@ -40,7 +41,7 @@ protected function parse($object): void /** * Get a value by the key of this object * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value * * @return mixed The value */ diff --git a/src/V1/ResourceNull.php b/src/V1/ResourceNull.php index c7df660..7876367 100644 --- a/src/V1/ResourceNull.php +++ b/src/V1/ResourceNull.php @@ -12,6 +12,7 @@ use Art4\JsonApiClient\Element; use Art4\JsonApiClient\Manager; use Art4\JsonApiClient\Exception\AccessException; +use Art4\JsonApiClient\Helper\AccessKey; /** * Null Resource @@ -40,7 +41,7 @@ public function __construct($data, Manager $manager, Accessable $parent) /** * Check if a value exists in this resource * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value * * @return bool false */ @@ -62,7 +63,7 @@ public function getKeys() /** * Get a value by the key of this identifier * - * @param string $key The key of the value + * @param int|string|AccessKey $key The key of the value */ public function get($key): void { diff --git a/tests/Fixtures/HelperTrait.php b/tests/Fixtures/HelperTrait.php index 2949bad..aa0b604 100644 --- a/tests/Fixtures/HelperTrait.php +++ b/tests/Fixtures/HelperTrait.php @@ -164,8 +164,8 @@ public function setUpManagerMock(): void * * @param mixed $filename */ - protected function getJsonString($filename) + protected function getJsonString($filename): string { - return file_get_contents(__DIR__ . '/../files/' . $filename); + return strval(file_get_contents(__DIR__ . '/../files/' . $filename)); } } diff --git a/tests/Fixtures/V1Factory.php b/tests/Fixtures/V1Factory.php index 282ea05..835c047 100644 --- a/tests/Fixtures/V1Factory.php +++ b/tests/Fixtures/V1Factory.php @@ -8,31 +8,26 @@ namespace Art4\JsonApiClient\Tests\Fixtures; -use Art4\JsonApiClient\Element; use Art4\JsonApiClient\Factory as FactoryInterface; +use PHPUnit\Framework\TestCase; final class V1Factory implements FactoryInterface { - public $testcase; + public TestCase $testcase; /** * Create a factory - * - * @param object $testcase - * @param array $args - * - * @return object */ - public function __construct($testcase) + public function __construct(TestCase $testcase) { - return $this->testcase = $testcase; + $this->testcase = $testcase; } /** * Create a new instance of a class * * @param string $name - * @param array $args + * @param array $args * * @return object */ diff --git a/tests/Functional/ParsingTest.php b/tests/Functional/ParsingTest.php index 40565e1..18a67f1 100644 --- a/tests/Functional/ParsingTest.php +++ b/tests/Functional/ParsingTest.php @@ -22,6 +22,8 @@ class ParsingTest extends TestCase /** * Provide Parser + * + * @return array> */ public static function createParserProvider(): array { diff --git a/tests/Functional/SerializerTest.php b/tests/Functional/SerializerTest.php index f96c043..c835969 100644 --- a/tests/Functional/SerializerTest.php +++ b/tests/Functional/SerializerTest.php @@ -14,6 +14,7 @@ use Art4\JsonApiClient\Serializer\ArraySerializer; use Art4\JsonApiClient\Tests\Fixtures\HelperTrait; use Art4\JsonApiClient\V1\Factory; +use Exception; use PHPUnit\Framework\TestCase; class SerializerTest extends TestCase @@ -22,6 +23,8 @@ class SerializerTest extends TestCase /** * Provide JSON API data + * + * @return array> */ public static function jsonapiDataProvider(): array { @@ -33,7 +36,13 @@ public static function jsonapiDataProvider(): array '15_create_resource_without_id.json', ]; - foreach (glob($path . '*.json') as $file) { + $filenames = glob($path . '*.json'); + + if ($filenames === false) { + throw new Exception('Error while getting all json files.'); + } + + foreach ($filenames as $file) { $filename = str_replace($path, '', $file); // Ignore files with errors @@ -45,9 +54,7 @@ public static function jsonapiDataProvider(): array $files[] = [ $filename, - [ - 'is_request' => in_array($filename, $requestFiles), - ], + in_array($filename, $requestFiles), ]; } @@ -55,18 +62,15 @@ public static function jsonapiDataProvider(): array } /** - * @test * @dataProvider jsonapiDataProvider - * - * @param mixed $filename */ - public function parseJsonapiDataWithErrorAbortManager($filename, array $meta): void + public function testParseJsonapiDataWithErrorAbortManager(string $filename, bool $isRequest): void { $manager = new ErrorAbortManager(new Factory()); $string = $this->getJsonString($filename); - if ($meta['is_request']) { + if ($isRequest) { $input = new RequestStringInput($string); } else { $input = new ResponseStringInput($string);