Skip to content

Commit

Permalink
Added return null to methods declared with nullable return types
Browse files Browse the repository at this point in the history
  • Loading branch information
tPl0ch committed Aug 14, 2017
1 parent 027f142 commit 83497d0
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions lib/Doctrine/ORM/Tools/EntityGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,18 +604,20 @@ protected function getType($type): string
*/
protected function generateEntityNamespace(ClassMetadataInfo $metadata): ?string
{
if ($this->hasNamespace($metadata)) {
return 'namespace ' . $this->getNamespace($metadata) .';';
if (!$this->hasNamespace($metadata)) {
return null;
}

return 'namespace ' . $this->getNamespace($metadata) .';';
}

protected function generateEntityUse(): ?string
{
if ($this->generateAnnotations) {
return "\n".'use Doctrine\ORM\Mapping as ORM;'."\n";
} else {
return "";
if (!$this->generateAnnotations) {
return null;
}

return "\n".'use Doctrine\ORM\Mapping as ORM;'."\n";
}

/**
Expand Down Expand Up @@ -738,9 +740,7 @@ private function generateEmbeddableConstructor(ClassMetadataInfo $metadata): str
}

foreach ($fieldMappings as $fieldMapping) {
if (isset($fieldMapping['declaredField']) &&
isset($metadata->embeddedClasses[$fieldMapping['declaredField']])
) {
if (isset($fieldMapping['declaredField'], $metadata->embeddedClasses[$fieldMapping['declaredField']])) {
continue;
}

Expand Down Expand Up @@ -954,7 +954,7 @@ protected function extendsClass(): bool
/**
* @return string
*/
protected function getClassToExtend(): string
protected function getClassToExtend(): ?string
{
return $this->classToExtend;
}
Expand Down Expand Up @@ -1117,6 +1117,8 @@ protected function generateInheritanceAnnotation(ClassMetadataInfo $metadata): ?
if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
return '@' . $this->annotationsPrefix . 'InheritanceType("'.$this->getInheritanceTypeString($metadata->inheritanceType).'")';
}

return null;
}

/**
Expand All @@ -1134,6 +1136,8 @@ protected function generateDiscriminatorColumnAnnotation(ClassMetadataInfo $meta

return '@' . $this->annotationsPrefix . 'DiscriminatorColumn(' . $columnDefinition . ')';
}

return null;
}

/**
Expand All @@ -1143,15 +1147,17 @@ protected function generateDiscriminatorColumnAnnotation(ClassMetadataInfo $meta
*/
protected function generateDiscriminatorMapAnnotation(ClassMetadataInfo $metadata): ?string
{
if ($metadata->inheritanceType != ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
$inheritanceClassMap = [];
if ($metadata->inheritanceType === ClassMetadataInfo::INHERITANCE_TYPE_NONE) {
return null;
}

foreach ($metadata->discriminatorMap as $type => $class) {
$inheritanceClassMap[] .= '"' . $type . '" = "' . $class . '"';
}
$inheritanceClassMap = [];

return '@' . $this->annotationsPrefix . 'DiscriminatorMap({' . implode(', ', $inheritanceClassMap) . '})';
foreach ($metadata->discriminatorMap as $type => $class) {
$inheritanceClassMap[] .= '"' . $type . '" = "' . $class . '"';
}

return '@' . $this->annotationsPrefix . 'DiscriminatorMap({' . implode(', ', $inheritanceClassMap) . '})';
}

/**
Expand All @@ -1164,9 +1170,7 @@ protected function generateEntityStubMethods(ClassMetadataInfo $metadata): strin
$methods = [];

foreach ($metadata->fieldMappings as $fieldMapping) {
if (isset($fieldMapping['declaredField']) &&
isset($metadata->embeddedClasses[$fieldMapping['declaredField']])
) {
if (isset($fieldMapping['declaredField'], $metadata->embeddedClasses[$fieldMapping['declaredField']])) {
continue;
}

Expand Down

0 comments on commit 83497d0

Please sign in to comment.