From b13564c6c063b7adc4a610c0ad4ff8bda0b90fe2 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Tue, 8 Oct 2024 12:25:31 +0200 Subject: [PATCH] Make nullable parameters explicit in generated entities (#11625) --- src/Tools/EntityGenerator.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Tools/EntityGenerator.php b/src/Tools/EntityGenerator.php index 04be6551881..3c72da123aa 100644 --- a/src/Tools/EntityGenerator.php +++ b/src/Tools/EntityGenerator.php @@ -767,6 +767,9 @@ private function generateEmbeddableConstructor(ClassMetadataInfo $metadata): str if ($fieldMapping['type'] === 'datetime') { $param = $this->getType($fieldMapping['type']) . ' ' . $param; + if (! empty($fieldMapping['nullable'])) { + $param = '?' . $param; + } } if (! empty($fieldMapping['nullable'])) { @@ -1385,6 +1388,9 @@ protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, if ($typeHint && ! isset($types[$typeHint])) { $variableType = '\\' . ltrim($variableType, '\\'); $methodTypeHint = '\\' . $typeHint . ' '; + if ($defaultValue === 'null') { + $methodTypeHint = '?' . $methodTypeHint; + } } $replacements = [