diff --git a/Spryker/Traits/SignatureTrait.php b/Spryker/Traits/SignatureTrait.php index e2b4c668..2a5b8b66 100644 --- a/Spryker/Traits/SignatureTrait.php +++ b/Spryker/Traits/SignatureTrait.php @@ -57,12 +57,24 @@ protected function getMethodSignature(File $phpCsFile, int $stackPtr): array $typehint = substr($typehint, 1); } + // Determine if parameter accepts null (nullable or explicit null) + $nullable = $parameter['nullable_type']; + if ($nullable === false && $typehint != '') { + for ($i = $parameter['type_hint_token']; $i <= $parameter['type_hint_end_token']; $i++) { + if ($tokens[$i]['code'] === T_NULL) { + $nullable = true; + + break; + } + } + } + $arguments[] = [ 'variableIndex' => $parameter['token'], 'variable' => $parameter['name'], 'typehint' => $typehint, 'typehintFull' => $parameter['type_hint'], - 'nullable' => $parameter['nullable_type'], + 'nullable' => $nullable, 'defaultIndex' => $defaultIndex, 'default' => $default, ]; diff --git a/tests/_data/DocBlockParamAllowDefaultValue/after.php b/tests/_data/DocBlockParamAllowDefaultValue/after.php index d7817442..d3c1fe3d 100644 --- a/tests/_data/DocBlockParamAllowDefaultValue/after.php +++ b/tests/_data/DocBlockParamAllowDefaultValue/after.php @@ -67,4 +67,14 @@ public function registerTableMapClass(string $tableMapClass): void public function toPHP(mixed $value): mixed { return $value; } + + /** + * This typehint is correct and should not change. See issue #368. + * + * @param int|string|null $value + * @return void + */ + public function multipleUnion(int|string|null $value): void + { + } } diff --git a/tests/_data/DocBlockParamAllowDefaultValue/before.php b/tests/_data/DocBlockParamAllowDefaultValue/before.php index d5d9216f..65bb99af 100644 --- a/tests/_data/DocBlockParamAllowDefaultValue/before.php +++ b/tests/_data/DocBlockParamAllowDefaultValue/before.php @@ -67,4 +67,14 @@ public function registerTableMapClass(string $tableMapClass): void public function toPHP(mixed $value): mixed { return $value; } + + /** + * This typehint is correct and should not change. See issue #368. + * + * @param int|string|null $value + * @return void + */ + public function multipleUnion(int|string|null $value): void + { + } }