Skip to content

Commit d05ac8b

Browse files
MoiraeKondukterCRO
Moirae
authored andcommitted
refactor: update phpstan to max level
1 parent 6fdd67c commit d05ac8b

28 files changed

+105
-48
lines changed

phpstan.neon

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
parameters:
22
paths:
33
- src/
4-
level: 6
4+
level: max

src/Definition/Encoding/ErrorCollectionToPhpArrayEncoderInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88

99
interface ErrorCollectionToPhpArrayEncoderInterface
1010
{
11-
/** @return array<string,mixed> */
12-
public function encode(ErrorCollectionInterface $errorCollection);
11+
/** @return array<int,array<string,mixed>> */
12+
public function encode(ErrorCollectionInterface $errorCollection): array;
1313
}

src/Definition/Encoding/LinkCollectionToPhpArrayEncoderInterface.php

+3
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88

99
interface LinkCollectionToPhpArrayEncoderInterface
1010
{
11+
/**
12+
* @return array<string,mixed>
13+
*/
1114
public function encode(LinkCollectionInterface $linkCollection): array;
1215
}

src/Definition/Encoding/MetaToPhpArrayEncoderInterface.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88

99
interface MetaToPhpArrayEncoderInterface
1010
{
11-
public function encode(MetaInterface $meta);
11+
/** @return array<string,mixed> */
12+
public function encode(MetaInterface $meta): array;
1213
}

src/Definition/Encoding/PhpArrayToMetaEncoderInterface.php

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88

99
interface PhpArrayToMetaEncoderInterface
1010
{
11+
/** @param array<string,mixed> $meta */
1112
public function decode(array $meta): MetaInterface;
1213
}

src/Definition/Encoding/PhpArrayToRelationshipCollectionEncoderInterface.php

+6
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@
55
namespace Undabot\JsonApi\Definition\Encoding;
66

77
use Undabot\JsonApi\Definition\Model\Resource\Relationship\RelationshipCollectionInterface;
8+
use Undabot\JsonApi\Implementation\Encoding\Exception\JsonApiEncodingException;
89

910
interface PhpArrayToRelationshipCollectionEncoderInterface
1011
{
12+
/**
13+
* @param array<string,array<string,mixed>> $relationships
14+
*
15+
* @throws JsonApiEncodingException
16+
*/
1117
public function encode(array $relationships): RelationshipCollectionInterface;
1218
}

src/Definition/Encoding/PhpArrayToResourceEncoderInterface.php

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
interface PhpArrayToResourceEncoderInterface
1111
{
1212
/**
13+
* @param array<string,mixed> $resource
14+
*
1315
* @throws JsonApiEncodingException
1416
*/
1517
public function decode(array $resource): ResourceInterface;

src/Definition/Encoding/ResourceCollectionToPhpArrayEncoderInterface.php

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88

99
interface ResourceCollectionToPhpArrayEncoderInterface
1010
{
11+
/** @return array<int,array<string,mixed>> */
1112
public function encode(ResourceCollectionInterface $resource);
1213
}

src/Definition/Encoding/ResourceIdentifierToPhpArrayEncoderInterface.php

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88

99
interface ResourceIdentifierToPhpArrayEncoderInterface
1010
{
11+
/** @return array<string,mixed> */
1112
public function encode(ResourceIdentifierInterface $resourceIdentifier);
1213
}

src/Definition/Model/Meta/MetaInterface.php

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66

77
interface MetaInterface
88
{
9+
/** @return array<string,mixed> */
910
public function getData(): array;
1011
}

src/Definition/Model/Request/GetResourceCollectionRequestInterface.php

+6
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@
1414

1515
interface GetResourceCollectionRequestInterface
1616
{
17+
/**
18+
* @return null|array<int,mixed>
19+
*/
1720
public function getIncludes(): ?array;
1821

1922
public function isIncluded(string $name): bool;
2023

24+
/**
25+
* @return null|array<int,mixed>
26+
*/
2127
public function getSparseFieldset(): ?array;
2228

2329
public function getFilterSet(): ?FilterSet;

src/Definition/Model/Request/GetResourceRequestInterface.php

+10
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,20 @@ interface GetResourceRequestInterface
1111
{
1212
public function getId(): string;
1313

14+
/**
15+
* @todo change definition after interface implementation
16+
*
17+
* @return null|array<mixed>
18+
*/
1419
public function getIncludes(): ?array;
1520

1621
public function isIncluded(string $name): bool;
1722

23+
/**
24+
* @todo change definition after interface implementation
25+
*
26+
* @return null|array<mixed>
27+
*/
1828
public function getSparseFieldset(): ?array;
1929

2030
/**

src/Definition/Model/Resource/Attribute/AttributeInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ interface AttributeInterface
88
{
99
public function getName(): string;
1010

11-
public function getValue();
11+
public function getValue(): mixed;
1212
}

src/Implementation/Encoding/ErrorCollectionToPhpArrayEncoder.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct(ErrorToPhpArrayEncoderInterface $errorEncoder)
1919
$this->errorEncoder = $errorEncoder;
2020
}
2121

22-
/** @return array<string,mixed> */
22+
/** @return array<int,array<string,mixed>> */
2323
public function encode(ErrorCollectionInterface $errorCollection): array
2424
{
2525
$serializedErrors = [];

src/Implementation/Encoding/LinkCollectionToPhpArrayEncoder.php

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public function __construct(LinkToPhpArrayEncoderInterface $linkEncoder)
1919
$this->linkEncoder = $linkEncoder;
2020
}
2121

22+
/**
23+
* @return array<string,mixed>
24+
*/
2225
public function encode(LinkCollectionInterface $linkCollection): array
2326
{
2427
$links = [];

src/Implementation/Encoding/MetaToPhpArrayEncoder.php

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
class MetaToPhpArrayEncoder implements MetaToPhpArrayEncoderInterface
1111
{
12+
/** @return array<string,mixed> */
1213
public function encode(MetaInterface $meta): array
1314
{
1415
return $meta->getData();

src/Implementation/Encoding/PhpArrayToMetaEncoder.php

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
class PhpArrayToMetaEncoder implements PhpArrayToMetaEncoderInterface
1212
{
13+
/** @param array<string,mixed> $meta */
1314
public function decode(array $meta): MetaInterface
1415
{
1516
return new Meta($meta);

src/Implementation/Encoding/PhpArrayToRelationshipCollectionEncoder.php

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public function __construct(
3232
}
3333

3434
/**
35+
* @param array<string,array<string,mixed>> $relationships
36+
*
3537
* @throws JsonApiEncodingException
3638
*/
3739
public function encode(array $relationships): RelationshipCollectionInterface
@@ -48,6 +50,8 @@ public function encode(array $relationships): RelationshipCollectionInterface
4850
}
4951

5052
/**
53+
* @param array<string,mixed> $relationshipValue
54+
*
5155
* @throws JsonApiEncodingException
5256
*/
5357
private function decodeRelationship(string $relationshipName, array $relationshipValue): Relationship

src/Implementation/Encoding/PhpArrayToResourceEncoder.php

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public function __construct(
3737
}
3838

3939
/**
40+
* @param array<string,mixed> $resource
41+
*
4042
* @throws JsonApiEncodingException
4143
*/
4244
public function decode(array $resource): ResourceInterface
@@ -69,6 +71,9 @@ public function decode(array $resource): ResourceInterface
6971
);
7072
}
7173

74+
/**
75+
* @param null|array<string,mixed> $rawMeta
76+
*/
7277
private function parseMeta(?array $rawMeta): ?MetaInterface
7378
{
7479
if (null === $rawMeta) {

src/Implementation/Encoding/RelationshipToPhpArrayEncoder.php

+11-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ public function encode(RelationshipInterface $relationship): array
5757
return $serializedRelationship;
5858
}
5959

60+
/**
61+
* @return null|array<mixed,mixed>
62+
*/
6063
private function encodeRelationshipData(?RelationshipDataInterface $data): ?array
6164
{
6265
if ($data instanceof ToOneRelationshipDataInterface) {
@@ -71,7 +74,10 @@ private function encodeRelationshipData(?RelationshipDataInterface $data): ?arra
7174
throw new DomainException('Invalid relationship data');
7275
}
7376

74-
private function encodeToOneRelationshipData(ToOneRelationshipDataInterface $data)
77+
/**
78+
* @return null|array<string,mixed>
79+
*/
80+
private function encodeToOneRelationshipData(ToOneRelationshipDataInterface $data): ?array
7581
{
7682
if (null === $data->getData()) {
7783
return null;
@@ -80,7 +86,10 @@ private function encodeToOneRelationshipData(ToOneRelationshipDataInterface $dat
8086
return $this->resourceIdentifierToPhpArrayEncoder->encode($data->getData());
8187
}
8288

83-
private function encodeToManyRelationshipData(ToManyRelationshipDataInterface $data)
89+
/**
90+
* @return array<int,array<string,mixed>>
91+
*/
92+
private function encodeToManyRelationshipData(ToManyRelationshipDataInterface $data): array
8493
{
8594
if ($data->isEmpty()) {
8695
return [];

src/Implementation/Encoding/ResourceCollectionToPhpArrayEncoder.php

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function __construct(ResourceToPhpArrayEncoderInterface $resourceToPhpArr
1818
$this->resourceToPhpArrayEncoder = $resourceToPhpArrayEncoder;
1919
}
2020

21+
/** @return array<int,array<string,mixed>> */
2122
public function encode(ResourceCollectionInterface $resourceCollection): array
2223
{
2324
$resources = [];

src/Implementation/Encoding/ResourceIdentifierCollectionToPhpArrayEncoder.php

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public function __construct(ResourceIdentifierToPhpArrayEncoderInterface $resour
1818
$this->resourceIdentifierToPhpArrayEncoder = $resourceIdentifierToPhpArrayEncoder;
1919
}
2020

21+
/**
22+
* @return array<int,array<string,mixed>>
23+
*/
2124
public function encode(ResourceIdentifierCollectionInterface $resourceIdentifierCollection): array
2225
{
2326
$resourceIdentifiers = [];

src/Implementation/Encoding/ResourceIdentifierToPhpArrayEncoder.php

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function __construct(MetaToPhpArrayEncoderInterface $metaToPhpArrayEncode
1818
$this->metaToPhpArrayEncoder = $metaToPhpArrayEncoder;
1919
}
2020

21+
/** @return array<string,mixed> */
2122
public function encode(ResourceIdentifierInterface $resourceIdentifier)
2223
{
2324
$serializedResourceIdentifier = [

src/Implementation/Model/Error/ErrorCollection.php

+9-13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace Undabot\JsonApi\Implementation\Model\Error;
66

77
use ArrayIterator;
8+
use Assert\Assertion;
9+
use Assert\AssertionFailedException;
810
use InvalidArgumentException;
911
use Undabot\JsonApi\Definition\Model\Error\ErrorCollectionInterface;
1012
use Undabot\JsonApi\Definition\Model\Error\ErrorInterface;
@@ -17,7 +19,13 @@ final class ErrorCollection implements ErrorCollectionInterface
1719
/** @param ErrorInterface[] $errors */
1820
public function __construct(array $errors)
1921
{
20-
$this->makeSureAllErrorsAreValid($errors);
22+
try {
23+
Assertion::allIsInstanceOf($errors, ErrorInterface::class);
24+
} catch (AssertionFailedException $exception) {
25+
// $message = sprintf('ResourceIdentifierInterface expected, %s given', \get_class($resourceIdentifier));
26+
//
27+
// throw new InvalidArgumentException($message);
28+
}
2129
$this->errors = $errors;
2230
}
2331

@@ -36,16 +44,4 @@ public function getIterator(): ArrayIterator
3644
{
3745
return new ArrayIterator($this->getErrors());
3846
}
39-
40-
/** @param ErrorInterface[] $errors */
41-
private function makeSureAllErrorsAreValid(array $errors): void
42-
{
43-
foreach ($errors as $error) {
44-
if (false === ($error instanceof ErrorInterface)) {
45-
$message = sprintf('Error expected, %s given', \get_class($error));
46-
47-
throw new InvalidArgumentException($message);
48-
}
49-
}
50-
}
5147
}

src/Implementation/Model/Meta/Meta.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88

99
class Meta implements MetaInterface
1010
{
11-
/** @var array */
11+
/** @var array<string,mixed> */
1212
private $data = [];
1313

14+
/** @param array<string,mixed> $data */
1415
public function __construct(array $data)
1516
{
1617
$this->data = $data;
1718
}
1819

20+
/** @return array<string,mixed> */
1921
public function getData(): array
2022
{
2123
return $this->data;

src/Implementation/Model/Resource/ResourceCollection.php

+9-13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace Undabot\JsonApi\Implementation\Model\Resource;
66

77
use ArrayIterator;
8+
use Assert\Assertion;
9+
use Assert\AssertionFailedException;
810
use InvalidArgumentException;
911
use Undabot\JsonApi\Definition\Model\Resource\ResourceCollectionInterface;
1012
use Undabot\JsonApi\Definition\Model\Resource\ResourceInterface;
@@ -17,7 +19,13 @@ final class ResourceCollection implements ResourceCollectionInterface
1719
/** @param ResourceInterface[] $resources */
1820
public function __construct(array $resources)
1921
{
20-
$this->makeSureResourcesAreValid($resources);
22+
try {
23+
Assertion::allIsInstanceOf($resources, ResourceInterface::class);
24+
} catch (AssertionFailedException $exception) {
25+
// $message = sprintf('ResourceIdentifierInterface expected, %s given', \get_class($resourceIdentifier));
26+
//
27+
// throw new InvalidArgumentException($message);
28+
}
2129
$this->resources = $resources;
2230
}
2331

@@ -36,16 +44,4 @@ public function getIterator(): ArrayIterator
3644
{
3745
return new ArrayIterator($this->getResources());
3846
}
39-
40-
/** @param ResourceInterface[] $resources */
41-
private function makeSureResourcesAreValid(array $resources): void
42-
{
43-
foreach ($resources as $resource) {
44-
if (false === ($resource instanceof ResourceInterface)) {
45-
$message = sprintf('ResourceInterface expected, %s given', \get_class($resource));
46-
47-
throw new InvalidArgumentException($message);
48-
}
49-
}
50-
}
5147
}

0 commit comments

Comments
 (0)