Skip to content

Commit ff484b3

Browse files
authored
Use quoted literal in phpdoc when psalm needs them (#1518)
1 parent 5b80c9d commit ff484b3

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

psalm.baseline.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@
5353
<code><![CDATA[array_merge($options, ['Bucket' => $bucket, 'Key' => $key])]]></code>
5454
</InvalidArgument>
5555
</file>
56-
<file src="src/Integration/Laravel/Cache/src/AsyncAwsDynamoDbStore.php">
57-
<RedundantCast>
58-
<code><![CDATA[(int) $e->getCode()]]></code>
59-
</RedundantCast>
60-
</file>
6156
<file src="src/Integration/Laravel/Cache/src/ServiceProvider.php">
6257
<InvalidArgument>
6358
<code>$config</code>
@@ -133,12 +128,6 @@
133128
<code><![CDATA[list<AutoRollbackEvent::*>]]></code>
134129
</MoreSpecificReturnType>
135130
</file>
136-
<file src="src/Service/DynamoDb/src/ValueObject/AttributeValue.php">
137-
<InvalidArrayOffset>
138-
<code><![CDATA[$input['BOOL']]]></code>
139-
<code><![CDATA[$input['NULL']]]></code>
140-
</InvalidArrayOffset>
141-
</file>
142131
<file src="src/Service/Kinesis/src/Result/DescribeStreamOutput.php">
143132
<LessSpecificReturnStatement>
144133
<code>$items</code>

src/CodeGenerator/src/Generator/CodeGenerator/TypeGenerator.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,23 @@ public function generateDocblock(StructureShape $shape, ClassName $shapeClassNam
103103
}
104104
}
105105

106+
$phpdocMemberName = $member->getName();
107+
108+
// Psalm treats a scalar type names as keywords and makes them lowercase even in array shape keys which are not types.
109+
// When a different case is needed, it requires using a quoted literal instead of an identifier.
110+
// TODO remove that code once https://github.com/vimeo/psalm/issues/10008 is solved (in a release)
111+
if (\in_array(strtolower($phpdocMemberName), ['bool', 'null', 'int', 'float', 'double', 'scalar']) && $phpdocMemberName !== strtolower($phpdocMemberName)) {
112+
$phpdocMemberName = "'" . $phpdocMemberName . "'";
113+
}
114+
106115
if ($nullable) {
107-
$body[] = sprintf(' %s?: %s,', $member->getName(), 'null|' . $param);
116+
$body[] = sprintf(' %s?: %s,', $phpdocMemberName, 'null|' . $param);
108117
} elseif ($allNullable) {
109118
// For input objects, the constructor allows to omit all members to set them later. But when provided,
110119
// they should respect the nullability of the member.
111-
$body[] = sprintf(' %s?: %s,', $member->getName(), $param);
120+
$body[] = sprintf(' %s?: %s,', $phpdocMemberName, $param);
112121
} else {
113-
$body[] = sprintf(' %s: %s,', $member->getName(), $param);
122+
$body[] = sprintf(' %s: %s,', $phpdocMemberName, $param);
114123
}
115124
}
116125
$body = array_merge($body, $extra);

src/Service/DynamoDb/src/ValueObject/AttributeValue.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ final class AttributeValue
119119
* BS?: null|string[],
120120
* M?: null|array<string, AttributeValue|array>,
121121
* L?: null|array<AttributeValue|array>,
122-
* NULL?: null|bool,
123-
* BOOL?: null|bool,
122+
* 'NULL'?: null|bool,
123+
* 'BOOL'?: null|bool,
124124
* } $input
125125
*/
126126
public function __construct(array $input)
@@ -147,8 +147,8 @@ public function __construct(array $input)
147147
* BS?: null|string[],
148148
* M?: null|array<string, AttributeValue|array>,
149149
* L?: null|array<AttributeValue|array>,
150-
* NULL?: null|bool,
151-
* BOOL?: null|bool,
150+
* 'NULL'?: null|bool,
151+
* 'BOOL'?: null|bool,
152152
* }|AttributeValue $input
153153
*/
154154
public static function create($input): self

0 commit comments

Comments
 (0)