Skip to content

Commit 0a998dc

Browse files
committed
cleanup relaxed type checking by phpdoc
1 parent 7452fff commit 0a998dc

6 files changed

Lines changed: 14 additions & 21 deletions

File tree

examples/bootstrap_examples.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,11 @@ public function getOfficialLink(): string {
151151
* optionally helpers for the specific profile
152152
*/
153153

154-
/**
155-
* @param ResourceInterface&HasAttributesInterface $resource
156-
*/
157-
public function setTimestamps(ResourceInterface $resource, ?\DateTimeInterface $created=null, ?\DateTimeInterface $updated=null) {
158-
if ($resource instanceof HasAttributesInterface === false) {
159-
throw new \Exception('cannot add attributes to identifier objects');
160-
}
161-
154+
public function setTimestamps(
155+
ResourceInterface & HasAttributesInterface $resource,
156+
?\DateTimeInterface $created=null,
157+
?\DateTimeInterface $updated=null,
158+
) {
162159
$timestamps = [];
163160
if ($created !== null) {
164161
$timestamps['created'] = $created->format(\DateTime::ISO8601);

phpstan.bonus.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ includes:
55
parameters:
66
level: 10
77

8-
treatPhpDocTypesAsCertain: true
9-
108
# @see https://github.com/phpstan/phpstan-strict-rules
119
strictRules:
1210
allRules: true

phpstan.neon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ parameters:
55
- src/
66
- tests/
77
- examples/
8-
8+
99
typeAliases:
1010
PHPStanTypeAlias_InternalOptions: 'array<string, bool|int|null|\alsvanzelf\jsonapi\enums\ContentTypeEnum>'
1111

12-
treatPhpDocTypesAsCertain: false
12+
treatPhpDocTypesAsCertain: true
1313

1414
strictRules:
1515
allRules: false

src/helpers/RequestParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function hasIncludePaths(): bool {
112112
* the raw format allows for custom processing
113113
*
114114
* @param PHPStanTypeAlias_InternalOptions $options {@see RequestParser::$defaults}
115-
* @return string[]|array
115+
* @return array<string>|array<array-key, mixed>
116116
*/
117117
public function getIncludePaths(array $options=[]): array {
118118
if ($this->queryParameters['include'] === '') {

src/objects/RelationshipObject.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ public function getNestedContainedResourceObjects(): array {
316316
$resourceObjects = [];
317317

318318
foreach ($resources as $resource) {
319+
// @phpstan-ignore instanceof.alwaysTrue, identical.alwaysFalse (we _can_ have both ResourceObject and ResourceIdentifierObject here)
319320
if ($resource->getResource() instanceof ResourceObject === false) {
320321
continue;
321322
}

tests/example_output/ExampleTimestampsProfile.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ public function getOfficialLink(): string {
1414
return 'https://jsonapi.org/recommendations/#authoring-profiles';
1515
}
1616

17-
/**
18-
* @param ResourceInterface&HasAttributesInterface $resource
19-
*/
20-
public function setTimestamps(ResourceInterface $resource, ?\DateTimeInterface $created=null, ?\DateTimeInterface $updated=null) {
21-
if ($resource instanceof HasAttributesInterface === false) {
22-
throw new InputException('cannot add attributes to identifier objects');
23-
}
24-
17+
public function setTimestamps(
18+
ResourceInterface & HasAttributesInterface $resource,
19+
?\DateTimeInterface $created=null,
20+
?\DateTimeInterface $updated=null,
21+
) {
2522
$timestamps = [];
2623
if ($created !== null) {
2724
$timestamps['created'] = $created->format(\DateTime::ISO8601);

0 commit comments

Comments
 (0)