Skip to content
Permalink
Browse files

Merge pull request #71 from ergebnis/fix/inline

Fix: Inline method
  • Loading branch information
localheinz committed Mar 23, 2020
2 parents f55a01e + 2acd4e1 commit 2f1b3940a2bfdd762d0ee2e38b3c9a898b6f5161
Showing with 19 additions and 16 deletions.
  1. +19 −16 src/EntityDef.php
@@ -29,13 +29,31 @@ final class EntityDef

private $configuration;

/**
* @param ORM\Mapping\ClassMetadata $classMetadata
* @param array $fieldDefinitions
* @param array $configuration
*
* @throws \Exception
*/
public function __construct(ORM\Mapping\ClassMetadata $classMetadata, array $fieldDefinitions, array $configuration)
{
$this->classMetadata = $classMetadata;
$this->fieldDefinitions = [];
$this->configuration = $configuration;

$this->normalizeFieldDefinitions($fieldDefinitions);
foreach ($fieldDefinitions as $fieldName => $fieldDefinition) {
if (!$this->classMetadata->hasField($fieldName) && !$this->classMetadata->hasAssociation($fieldName)) {
throw new \Exception(\sprintf(
'No such field in %s: %s',
$this->getClassName(),
$fieldName
));
}

$this->fieldDefinitions[$fieldName] = $this->normalizeFieldDefinition($fieldDefinition);
}

$this->collectDefaultFieldDefinitionsFromClassMetadata();
}

@@ -77,21 +95,6 @@ public function getConfiguration()
return $this->configuration;
}

private function normalizeFieldDefinitions(array $fieldDefinitions): void
{
foreach ($fieldDefinitions as $fieldName => $fieldDefinition) {
if (!$this->classMetadata->hasField($fieldName) && !$this->classMetadata->hasAssociation($fieldName)) {
throw new \Exception(\sprintf(
'No such field in %s: %s',
$this->getClassName(),
$fieldName
));
}

$this->fieldDefinitions[$fieldName] = $this->normalizeFieldDefinition($fieldDefinition);
}
}

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

0 comments on commit 2f1b394

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