Conditions | 6 |
Paths | 10 |
Total Lines | 65 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
52 | |||
53 | if ($this->config->getGlobalEnable()) { |
||
54 | $globalEnable = $this->container->get(GlobalEnable::class); |
||
55 | |||
56 | return new Metadata($this->container, $globalEnable($entityClasses)); |
||
57 | } |
||
58 | |||
59 | foreach ($entityClasses as $entityClass) { |
||
60 | $reflectionClass = new ReflectionClass($entityClass); |
||
61 | $entityClassMetadata = $this->entityManager |
||
62 | ->getMetadataFactory()->getMetadataFor($reflectionClass->getName()); |
||
63 | |||
64 | $this->buildMetadataConfigForEntity($reflectionClass); |
||
65 | $this->buildMetadataConfigForFields($entityClassMetadata, $reflectionClass); |
||
66 | $this->buildMetadataConfigForAssociations($entityClassMetadata, $reflectionClass); |
||
67 | } |
||
68 | |||
69 | $this->metadata = new Metadata($this->container, $this->metadataConfig); |
||
70 | |||
71 | return $this->metadata; |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * Using the entity class attributes, generate the metadataConfig. |
||
76 | * The buildMetadataConfig* functions exist to simplify the buildMetadata |
||
77 | * function. |
||
78 | */ |
||
79 | private function buildMetadataConfigForEntity(ReflectionClass $reflectionClass): void |
||
80 | { |
||
81 | $entityInstance = null; |
||
82 | |||
83 | // Fetch attributes for the entity class filterd by Attribute\Entity |
||
84 | foreach ($reflectionClass->getAttributes(Attribute\Entity::class) as $attribute) { |
||
85 | $instance = $attribute->newInstance(); |
||
86 | |||
87 | // Only process attributes for the Config group |
||
88 | if ($instance->getGroup() !== $this->config->getGroup()) { |
||
89 | continue; |
||
90 | } |
||
91 | |||
92 | // Only one matching instance per group is allowed |
||
93 | assert( |
||
94 | ! $entityInstance, |
||
95 | 'Duplicate attribute found for entity ' |
||
96 | . $reflectionClass->getName() . ', group ' . $instance->getGroup(), |
||
97 | ); |
||
98 | $entityInstance = $instance; |
||
99 | |||
100 | // Save entity-level metadata |
||
101 | $this->metadataConfig[$reflectionClass->getName()] = [ |
||
102 | 'entityClass' => $reflectionClass->getName(), |
||
103 | 'byValue' => $this->config->getGlobalByValue() ?? $instance->getByValue(), |
||
104 | 'namingStrategy' => $instance->getNamingStrategy(), |
||
105 | 'fields' => [], |
||
106 | 'filters' => $instance->getFilters(), |
||
107 | 'excludeCriteria' => $instance->getExcludeCriteria(), |
||
108 | 'description' => $instance->getDescription(), |
||
109 | 'typeName' => $instance->getTypeName() |
||
110 | ? $this->appendGroupSuffix($instance->getTypeName()) : |
||
111 | $this->getTypeName($reflectionClass->getName()), |
||
112 | ]; |
||
113 | } |
||
114 | } |
||
115 | |||
116 | private function buildMetadataConfigForFields( |
||
117 | ClassMetadata $entityClassMetadata, |
||
219 |