@@ -103,14 +103,23 @@ public function generateDocblock(StructureShape $shape, ClassName $shapeClassNam
103
103
}
104
104
}
105
105
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
+
106
115
if ($ nullable ) {
107
- $ body [] = sprintf (' %s?: %s, ' , $ member -> getName () , 'null| ' . $ param );
116
+ $ body [] = sprintf (' %s?: %s, ' , $ phpdocMemberName , 'null| ' . $ param );
108
117
} elseif ($ allNullable ) {
109
118
// For input objects, the constructor allows to omit all members to set them later. But when provided,
110
119
// they should respect the nullability of the member.
111
- $ body [] = sprintf (' %s?: %s, ' , $ member -> getName () , $ param );
120
+ $ body [] = sprintf (' %s?: %s, ' , $ phpdocMemberName , $ param );
112
121
} else {
113
- $ body [] = sprintf (' %s: %s, ' , $ member -> getName () , $ param );
122
+ $ body [] = sprintf (' %s: %s, ' , $ phpdocMemberName , $ param );
114
123
}
115
124
}
116
125
$ body = array_merge ($ body , $ extra );
0 commit comments