| Conditions | 6 |
| Paths | 32 |
| Total Lines | 38 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 27 | protected static function doGenerate(\ReflectionParameter $parameter): string |
||
| 28 | { |
||
| 29 | try { |
||
| 30 | $defaultValue = !$parameter->allowsNull() |
||
| 31 | ? var_export($parameter->getDefaultValue(), true) |
||
| 32 | : 'null'; |
||
| 33 | |||
| 34 | $defaultValue = '=' . $defaultValue; |
||
| 35 | } catch (\ReflectionException $exception) { |
||
| 36 | $defaultValue = ''; |
||
| 37 | } |
||
| 38 | |||
| 39 | $type = $parameter->getType() |
||
| 40 | ? (string)$parameter->getType() |
||
| 41 | : ''; |
||
| 42 | |||
| 43 | $isPassedByReference = $parameter->isPassedByReference() |
||
| 44 | ? '&' |
||
| 45 | : ''; |
||
| 46 | |||
| 47 | $isVariadic = ''; |
||
| 48 | if ($parameter->isVariadic()) { |
||
| 49 | $isVariadic = '...'; |
||
| 50 | $isPassedByReference = ''; |
||
| 51 | $defaultValue = ''; |
||
| 52 | } |
||
| 53 | |||
| 54 | $name = '$' . $parameter->getName(); |
||
| 55 | |||
| 56 | return sprintf( |
||
| 57 | self::TEMPLATE, |
||
| 58 | $type, |
||
| 59 | $isVariadic, |
||
| 60 | $isPassedByReference, |
||
| 61 | $name, |
||
| 62 | $defaultValue |
||
| 63 | ); |
||
| 64 | } |
||
| 65 | } |
||
| 66 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.