@@ -893,26 +893,18 @@ protected function createPhpDocs($class)
893
893
* Get the parameters and format them correctly
894
894
*
895
895
* @param $method
896
- * @param bool $withTypeHint
897
896
* @return array
898
897
* @throws \ReflectionException
899
898
*/
900
- public function getParameters ($ method, bool $ withTypeHint = false )
899
+ public function getParameters ($ method )
901
900
{
902
901
//Loop through the default values for parameters, and make the correct output string
903
902
$ paramsWithDefault = [];
904
903
/** @var \ReflectionParameter $param */
905
904
foreach ($ method ->getParameters () as $ param ) {
906
- $ paramType = $ param ->getType ();
907
-
908
905
$ paramStr = '$ ' . $ param ->getName ();
909
- if ($ paramType ) {
910
- $ paramTypeStr = $ paramType ->getName ();
911
- if (!$ paramType ->isBuiltin ()) {
912
- $ paramTypeStr = '\\' . $ paramTypeStr ;
913
- }
914
-
915
- $ paramStr = $ paramTypeStr . ' ' . $ paramStr ;
906
+ if ($ paramType = $ this ->getParamType ($ method , $ param )) {
907
+ $ paramStr = $ paramType . ' ' . $ paramStr ;
916
908
}
917
909
918
910
if ($ param ->isOptional () && $ param ->isDefaultValueAvailable ()) {
@@ -932,10 +924,6 @@ public function getParameters($method, bool $withTypeHint = false)
932
924
$ paramStr .= " = $ default " ;
933
925
}
934
926
935
- if ($ withTypeHint && $ paramType = $ this ->getParamType ($ method , $ param )) {
936
- $ paramStr = $ paramType . ' ' . $ paramStr ;
937
- }
938
-
939
927
$ paramsWithDefault [] = $ paramStr ;
940
928
}
941
929
return $ paramsWithDefault ;
@@ -1176,7 +1164,7 @@ protected function writeModelExternalBuilderMethods(string $builder, Model $mode
1176
1164
1177
1165
foreach ($ newMethodsFromNewBuilder as $ builderMethod ) {
1178
1166
$ reflection = new \ReflectionMethod ($ builder , $ builderMethod );
1179
- $ args = $ this ->getParameters ($ reflection, true );
1167
+ $ args = $ this ->getParameters ($ reflection );
1180
1168
1181
1169
$ this ->setMethod (
1182
1170
$ builderMethod ,
@@ -1189,11 +1177,17 @@ protected function writeModelExternalBuilderMethods(string $builder, Model $mode
1189
1177
protected function getParamType (\ReflectionMethod $ method , \ReflectionParameter $ parameter ): ?string
1190
1178
{
1191
1179
if ($ paramType = $ parameter ->getType ()) {
1180
+ $ parameterName = $ paramType ->getName ();
1181
+
1182
+ if (!$ paramType ->isBuiltin ()) {
1183
+ $ parameterName = '\\' . $ parameterName ;
1184
+ }
1185
+
1192
1186
if ($ paramType ->allowsNull ()) {
1193
- return '? ' . $ paramType -> getName () ;
1187
+ return '? ' . $ parameterName ;
1194
1188
}
1195
1189
1196
- return $ paramType -> getName () ;
1190
+ return $ parameterName ;
1197
1191
}
1198
1192
1199
1193
$ docComment = $ method ->getDocComment ();
@@ -1239,14 +1233,18 @@ protected function getParamType(\ReflectionMethod $method, \ReflectionParameter
1239
1233
$ type = '? ' . $ type ;
1240
1234
}
1241
1235
1242
- $ typesThatAreNotAllowed = [
1243
- 'null ' ,
1244
- 'mixed ' ,
1245
- 'nullable ' ,
1236
+ // convert to proper type hint types in php
1237
+ $ type = str_replace (['boolean ' , 'integer ' ], ['bool ' , 'int ' ], $ type );
1238
+
1239
+ $ allowedTypes = [
1240
+ 'int ' ,
1241
+ 'bool ' ,
1242
+ 'string ' ,
1243
+ 'float ' ,
1246
1244
];
1247
1245
1248
1246
// we replace the ? with an empty string so we can check the actual type
1249
- if (in_array (str_replace ('? ' , '' , $ type ), $ typesThatAreNotAllowed )) {
1247
+ if (! in_array (str_replace ('? ' , '' , $ type ), $ allowedTypes )) {
1250
1248
return null ;
1251
1249
}
1252
1250
0 commit comments