1
0
mirror of synced 2025-02-10 17:29:27 +03:00

Update docblock generation for nullable fields

This commit is contained in:
Javier Spagnoletti 2016-10-04 11:01:53 -03:00 committed by Marco Pivetta
parent c148059593
commit d3c604567b

View File

@ -1168,17 +1168,18 @@ public function __construct(<params>)
continue; continue;
} }
$nullableField = $this->getNullableField($fieldMapping);
if (( ! isset($fieldMapping['id']) || if (( ! isset($fieldMapping['id']) ||
! $fieldMapping['id'] || ! $fieldMapping['id'] ||
$metadata->generatorType == ClassMetadataInfo::GENERATOR_TYPE_NONE $metadata->generatorType == ClassMetadataInfo::GENERATOR_TYPE_NONE
) && (! $metadata->isEmbeddedClass || ! $this->embeddablesImmutable) ) && (! $metadata->isEmbeddedClass || ! $this->embeddablesImmutable)
) { ) {
if ($code = $this->generateEntityStubMethod($metadata, 'set', $fieldMapping['fieldName'], $fieldMapping['type'])) { if ($code = $this->generateEntityStubMethod($metadata, 'set', $fieldMapping['fieldName'], $fieldMapping['type'], $nullableField)) {
$methods[] = $code; $methods[] = $code;
} }
} }
if ($code = $this->generateEntityStubMethod($metadata, 'get', $fieldMapping['fieldName'], $fieldMapping['type'])) { if ($code = $this->generateEntityStubMethod($metadata, 'get', $fieldMapping['fieldName'], $fieldMapping['type'], $nullableField)) {
$methods[] = $code; $methods[] = $code;
} }
} }
@ -1205,7 +1206,7 @@ public function __construct(<params>)
if ($code = $this->generateEntityStubMethod($metadata, 'set', $associationMapping['fieldName'], $associationMapping['targetEntity'], $nullable)) { if ($code = $this->generateEntityStubMethod($metadata, 'set', $associationMapping['fieldName'], $associationMapping['targetEntity'], $nullable)) {
$methods[] = $code; $methods[] = $code;
} }
if ($code = $this->generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], $associationMapping['targetEntity'])) { if ($code = $this->generateEntityStubMethod($metadata, 'get', $associationMapping['fieldName'], $associationMapping['targetEntity'], $nullable)) {
$methods[] = $code; $methods[] = $code;
} }
} elseif ($associationMapping['type'] & ClassMetadataInfo::TO_MANY) { } elseif ($associationMapping['type'] & ClassMetadataInfo::TO_MANY) {
@ -1355,7 +1356,7 @@ public function __construct(<params>)
* *
* @return string * @return string
*/ */
protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null) protected function generateEntityStubMethod(ClassMetadataInfo $metadata, $type, $fieldName, $typeHint = null, $defaultValue = null)
{ {
$methodName = $type . Inflector::classify($fieldName); $methodName = $type . Inflector::classify($fieldName);
$variableName = Inflector::camelize($fieldName); $variableName = Inflector::camelize($fieldName);
@ -1384,7 +1385,7 @@ public function __construct(<params>)
$replacements = array( $replacements = array(
'<description>' => ucfirst($type) . ' ' . $variableName . '.', '<description>' => ucfirst($type) . ' ' . $variableName . '.',
'<methodTypeHint>' => $methodTypeHint, '<methodTypeHint>' => $methodTypeHint,
'<variableType>' => $variableType, '<variableType>' => $variableType.(null !== $defaultValue ? ('|'.$defaultValue) : ''),
'<variableName>' => $variableName, '<variableName>' => $variableName,
'<methodName>' => $methodName, '<methodName>' => $methodName,
'<fieldName>' => $fieldName, '<fieldName>' => $fieldName,
@ -1627,7 +1628,7 @@ public function __construct(<params>)
{ {
$lines = array(); $lines = array();
$lines[] = $this->spaces . '/**'; $lines[] = $this->spaces . '/**';
$lines[] = $this->spaces . ' * @var ' . $this->getType($fieldMapping['type']); $lines[] = $this->spaces . ' * @var ' . $this->getType($fieldMapping['type']) . ($this->getNullableField($fieldMapping) ? '|' . $this->getNullableField($fieldMapping) : '');;
if ($this->generateAnnotations) { if ($this->generateAnnotations) {
$lines[] = $this->spaces . ' *'; $lines[] = $this->spaces . ' *';
@ -1809,6 +1810,18 @@ public function __construct(<params>)
return static::$generatorStrategyMap[$type]; return static::$generatorStrategyMap[$type];
} }
/**
* @param array $fieldMapping
*
* @return string|null
*/
protected function getNullableField(array $fieldMapping)
{
if (isset($fieldMapping['nullable']) && true === $fieldMapping['nullable']) {
return 'null';
}
}
/** /**
* Exports (nested) option elements. * Exports (nested) option elements.
* *