Skip to content
Permalink
Browse files

Merge pull request #59 from ergebnis/feature/merge

Fix: Inline method
  • Loading branch information
localheinz committed Mar 23, 2020
2 parents 2f1b394 + a5ae048 commit f4b5392e378b310c3df54ea33d08dc1d13f77429
Showing with 22 additions and 27 deletions.
  1. +22 −27 src/EntityDef.php
@@ -54,7 +54,28 @@ public function __construct(ORM\Mapping\ClassMetadata $classMetadata, array $fie
$this->fieldDefinitions[$fieldName] = $this->normalizeFieldDefinition($fieldDefinition);
}

$this->collectDefaultFieldDefinitionsFromClassMetadata();
$defaultEntity = $this->classMetadata->newInstance();

$fieldNames = \array_merge(
$this->classMetadata->getFieldNames(),
$this->classMetadata->getAssociationNames()
);

foreach ($fieldNames as $fieldName) {
if (!isset($this->fieldDefinitions[$fieldName])) {
$defaultFieldValue = $this->classMetadata->getFieldValue($defaultEntity, $fieldName);

if (null !== $defaultFieldValue) {
$this->fieldDefinitions[$fieldName] = static function () use ($defaultFieldValue) {
return $defaultFieldValue;
};
} else {
$this->fieldDefinitions[$fieldName] = static function () {
return null;
};
}
}
}
}

/**
@@ -95,32 +116,6 @@ public function getConfiguration()
return $this->configuration;
}

private function collectDefaultFieldDefinitionsFromClassMetadata(): void
{
$defaultEntity = $this->getClassMetadata()->newInstance();

$fieldNames = \array_merge(
$this->classMetadata->getFieldNames(),
$this->classMetadata->getAssociationNames()
);

foreach ($fieldNames as $fieldName) {
if (!isset($this->fieldDefinitions[$fieldName])) {
$defaultFieldValue = $this->classMetadata->getFieldValue($defaultEntity, $fieldName);

if (null !== $defaultFieldValue) {
$this->fieldDefinitions[$fieldName] = static function () use ($defaultFieldValue) {
return $defaultFieldValue;
};
} else {
$this->fieldDefinitions[$fieldName] = static function () {
return null;
};
}
}
}
}

private function normalizeFieldDefinition($fieldDefinition)
{
if (\is_callable($fieldDefinition)) {

0 comments on commit f4b5392

Please sign in to comment.
You can’t perform that action at this time.