Skip to content

Commit 3ce9d44

Browse files
committed
reach PHPStan level 9
1 parent 91d4ed9 commit 3ce9d44

File tree

6 files changed

+39
-28
lines changed

6 files changed

+39
-28
lines changed

.phpstan.neon

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ includes:
55
- vendor/phpstan/phpstan-phpunit/extension.neon
66

77
parameters:
8-
level: 8
8+
level: 9
99

1010
paths:
1111
- src/
@@ -53,6 +53,18 @@ parameters:
5353
path: tests/BC/ElementTest.php
5454
# parameter is required by Art4\JsonApiClient\Element
5555

56+
-
57+
message: "#^Parameter \\#1 \\$string of class Art4\\\\JsonApiClient\\\\Input\\\\RequestStringInput constructor expects string, mixed given\\.$#"
58+
count: 1
59+
path: tests/Unit/Input/RequestStringInputTest.php
60+
# We are providing an invalid parameter to test the exception message
61+
62+
-
63+
message: "#^Parameter \\#1 \\$string of class Art4\\\\JsonApiClient\\\\Input\\\\ResponseStringInput constructor expects string, mixed given\\.$#"
64+
count: 1
65+
path: tests/Unit/Input/ResponseStringInputTest.php
66+
# We are providing an invalid parameter to test the exception message
67+
5668
-
5769
message: "#^Parameter \\#1 \\$key of method Art4\\\\JsonApiClient\\\\V1\\\\ResourceNull\\:\\:has\\(\\) expects Art4\\\\JsonApiClient\\\\Helper\\\\AccessKey\\|int\\|string, array given\\.$#"
5870
count: 1

src/Helper/AccessKey.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class AccessKey extends SplStack
2222
/**
2323
* Transforms the Key to a string
2424
*
25-
* @param mixed $key
25+
* @param int|string $key
2626
*
2727
* @return AccessKey<string>
2828
*/

src/V1/Link.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ public function get($key)
6161
/**
6262
* Set a link
6363
*
64-
* @param string $name The Name
65-
* @param string|object $link The Link
64+
* @param mixed $link The Link
6665
*/
6766
private function setAsLink(string $name, $link): void
6867
{

tests/Functional/ParsingTest.php

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,9 @@ public static function createParserProvider(): array
3939
}
4040

4141
/**
42-
* @test
4342
* @dataProvider createParserProvider
44-
*
45-
* @param mixed $parser
4643
*/
47-
public function testParseSimpleResourceWithDifferentParser($parser): void
44+
public function testParseSimpleResourceWithDifferentParser(callable $parser): void
4845
{
4946
$string = $this->getJsonString('01_simple_resource.json');
5047
$document = $parser($string);
@@ -178,6 +175,7 @@ public function testParseCompleteResourceObjectWithMultipleRelationships(): void
178175
$this->assertTrue($document->has('included'));
179176
$this->assertTrue($document->has('data'));
180177

178+
/** @var Accessable */
181179
$resources = $document->get('data');
182180

183181
$this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceCollection', $resources);
@@ -186,6 +184,8 @@ public function testParseCompleteResourceObjectWithMultipleRelationships(): void
186184
$this->assertSame($resources->getKeys(), [0]);
187185

188186
$this->assertTrue($resources->has(0));
187+
188+
/** @var Accessable */
189189
$resource = $resources->get(0);
190190

191191
$this->assertFalse($resource->has('meta'));
@@ -195,24 +195,28 @@ public function testParseCompleteResourceObjectWithMultipleRelationships(): void
195195
$this->assertTrue($resource->has('relationships'));
196196
$this->assertTrue($resource->has('links'));
197197

198+
/** @var Accessable */
198199
$attributes = $resource->get('attributes');
199200

200201
$this->assertInstanceOf('Art4\JsonApiClient\V1\Attributes', $attributes);
201202
$this->assertTrue($attributes->has('title'));
202203
$this->assertSame($attributes->get('title'), 'JSON API paints my bikeshed!');
203204

205+
/** @var Accessable */
204206
$collection = $resource->get('relationships');
205207

206208
$this->assertInstanceOf('Art4\JsonApiClient\V1\RelationshipCollection', $collection);
207209
$this->assertTrue($collection->has('author'));
208210
$this->assertTrue($collection->has('comments'));
209211

212+
/** @var Accessable */
210213
$author = $collection->get('author');
211214

212215
$this->assertInstanceOf('Art4\JsonApiClient\V1\Relationship', $author);
213216
$this->assertTrue($author->has('links'));
214217
$this->assertTrue($author->has('data'));
215218

219+
/** @var Accessable */
216220
$links = $author->get('links');
217221

218222
$this->assertInstanceOf('Art4\JsonApiClient\V1\RelationshipLink', $links);
@@ -221,18 +225,21 @@ public function testParseCompleteResourceObjectWithMultipleRelationships(): void
221225
$this->assertTrue($links->has('related'));
222226
$this->assertSame($links->get('related'), 'http://example.com/articles/1/author');
223227

228+
/** @var Accessable */
224229
$data = $author->get('data');
225230

226231
$this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceIdentifier', $data);
227232
$this->assertSame($data->get('type'), 'people');
228233
$this->assertSame($data->get('id'), '9');
229234

235+
/** @var Accessable */
230236
$comments = $collection->get('comments');
231237

232238
$this->assertInstanceOf('Art4\JsonApiClient\V1\Relationship', $comments);
233239
$this->assertTrue($comments->has('links'));
234240
$this->assertTrue($comments->has('data'));
235241

242+
/** @var Accessable */
236243
$links = $comments->get('links');
237244

238245
$this->assertInstanceOf('Art4\JsonApiClient\V1\RelationshipLink', $links);
@@ -241,35 +248,42 @@ public function testParseCompleteResourceObjectWithMultipleRelationships(): void
241248
$this->assertTrue($links->has('related'));
242249
$this->assertSame($links->get('related'), 'http://example.com/articles/1/comments');
243250

251+
/** @var Accessable */
244252
$data_array = $comments->get('data');
245253

246254
$this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceIdentifierCollection', $data_array);
247255
$this->assertCount(2, $data_array->getKeys());
248256

257+
/** @var Accessable */
249258
$identifier = $data_array->get(0);
250259

251260
$this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceIdentifier', $identifier);
252261
$this->assertSame($identifier->get('type'), 'comments');
253262
$this->assertSame($identifier->get('id'), '5');
254263

264+
/** @var Accessable */
255265
$identifier = $data_array->get(1);
256266

257267
$this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceIdentifier', $identifier);
258268
$this->assertSame($identifier->get('type'), 'comments');
259269
$this->assertSame($identifier->get('id'), '12');
260270

271+
/** @var Accessable */
261272
$links = $resource->get('links');
262273

263274
$this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceItemLink', $links);
264275
$this->assertTrue($links->has('self'));
265276
$this->assertSame($links->get('self'), 'http://example.com/articles/1');
266277

278+
/** @var Accessable */
267279
$includes = $document->get('included');
268280

269281
$this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceCollection', $includes);
270282
$this->assertSame($includes->getKeys(), [0, 1, 2]);
271283

272284
$this->assertTrue($includes->has(0));
285+
286+
/** @var Accessable */
273287
$include = $includes->get(0);
274288

275289
$this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceItem', $include);
@@ -278,6 +292,7 @@ public function testParseCompleteResourceObjectWithMultipleRelationships(): void
278292
$this->assertTrue($include->has('attributes'));
279293
$this->assertTrue($include->has('links'));
280294

295+
/** @var Accessable */
281296
$attributes = $include->get('attributes');
282297

283298
$this->assertInstanceOf('Art4\JsonApiClient\V1\Attributes', $attributes);
@@ -288,13 +303,16 @@ public function testParseCompleteResourceObjectWithMultipleRelationships(): void
288303
$this->assertTrue($attributes->has('twitter'));
289304
$this->assertSame($attributes->get('twitter'), 'dgeb');
290305

306+
/** @var Accessable */
291307
$links = $include->get('links');
292308

293309
$this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceItemLink', $links);
294310
$this->assertTrue($links->has('self'));
295311
$this->assertSame($links->get('self'), 'http://example.com/people/9');
296312

297313
$this->assertTrue($includes->has(1));
314+
315+
/** @var Accessable */
298316
$include = $includes->get(1);
299317

300318
$this->assertInstanceOf('Art4\JsonApiClient\V1\ResourceItem', $include);

tests/Unit/Input/RequestStringInputTest.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ class RequestStringInputTest extends TestCase
1717
{
1818
use HelperTrait;
1919

20-
/**
21-
* @test
22-
*/
2320
public function testGetAsObjectFromStringReturnsObject(): void
2421
{
2522
$input = new RequestStringInput('{}');
@@ -29,11 +26,8 @@ public function testGetAsObjectFromStringReturnsObject(): void
2926

3027
/**
3128
* @dataProvider jsonValuesProviderWithoutString
32-
* @test
33-
*
34-
* @param mixed $input
3529
*/
36-
public function testCreateWithoutStringThrowsException($input): void
30+
public function testCreateWithoutStringThrowsException(mixed $input): void
3731
{
3832
$this->expectException(InputException::class);
3933
$this->expectExceptionMessage(
@@ -44,9 +38,6 @@ public function testCreateWithoutStringThrowsException($input): void
4438

4539
/**
4640
* @dataProvider jsonValuesAsStringProviderWithoutObject
47-
* @test
48-
*
49-
* @param string $input
5041
*/
5142
public function testGetAsObjectWithInvalidStringsThrowsException(string $input): void
5243
{

tests/Unit/Input/ResponseStringInputTest.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ class ResponseStringInputTest extends TestCase
1717
{
1818
use HelperTrait;
1919

20-
/**
21-
* @test
22-
*/
2320
public function testGetAsObjectFromStringReturnsObject(): void
2421
{
2522
$input = new ResponseStringInput('{}');
@@ -29,11 +26,8 @@ public function testGetAsObjectFromStringReturnsObject(): void
2926

3027
/**
3128
* @dataProvider jsonValuesProviderWithoutString
32-
* @test
33-
*
34-
* @param mixed $input
3529
*/
36-
public function testCreateWithoutStringThrowsException($input): void
30+
public function testCreateWithoutStringThrowsException(mixed $input): void
3731
{
3832
$this->expectException(InputException::class);
3933
$this->expectExceptionMessage(
@@ -44,9 +38,6 @@ public function testCreateWithoutStringThrowsException($input): void
4438

4539
/**
4640
* @dataProvider jsonValuesAsStringProviderWithoutObject
47-
* @test
48-
*
49-
* @param string $input
5041
*/
5142
public function testGetAsObjectWithInvalidStringsThrowsException(string $input): void
5243
{

0 commit comments

Comments
 (0)