| Conditions | 7 |
| Paths | 6 |
| Total Lines | 51 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 148 | private function buildMetadataForAssociations( |
||
| 149 | ClassMetadata $entityClassMetadata, |
||
| 150 | ReflectionClass $reflectionClass, |
||
| 151 | ): void { |
||
| 152 | // Fetch attributes for associations |
||
| 153 | $associationNames = $this->entityManager->getMetadataFactory() |
||
| 154 | ->getMetadataFor($reflectionClass->getName())->getAssociationNames(); |
||
| 155 | |||
| 156 | foreach ($associationNames as $associationName) { |
||
| 157 | $associationInstance = null; |
||
| 158 | $reflectionAssociation = $reflectionClass->getProperty($associationName); |
||
| 159 | |||
| 160 | foreach ($reflectionAssociation->getAttributes(Attribute\Association::class) as $attribute) { |
||
| 161 | $instance = $attribute->newInstance(); |
||
| 162 | |||
| 163 | // Only process attributes for the same group |
||
| 164 | if ($instance->getGroup() !== $this->config->getGroup()) { |
||
| 165 | continue; |
||
| 166 | } |
||
| 167 | |||
| 168 | // Only one matching instance per group is allowed |
||
| 169 | assert( |
||
| 170 | ! $associationInstance, |
||
| 171 | 'Duplicate attribute found for association ' |
||
| 172 | . $associationName . ', group ' . $instance->getGroup(), |
||
| 173 | ); |
||
| 174 | $associationInstance = $instance; |
||
| 175 | |||
| 176 | $this->metadata[$reflectionClass->getName()]['fields'][$associationName]['description'] = |
||
| 177 | $instance->getDescription(); |
||
| 178 | $this->metadata[$reflectionClass->getName()]['fields'][$associationName]['excludeCriteria'] = |
||
| 179 | $instance->getExcludeCriteria(); |
||
| 180 | $this->metadata[$reflectionClass->getName()]['fields'][$associationName]['filterCriteriaEventName'] = |
||
| 181 | $instance->getFilterCriteriaEventName(); |
||
| 182 | |||
| 183 | if ($instance->getStrategy()) { |
||
| 184 | $this->metadata[$reflectionClass->getName()]['fields'][$associationName]['strategy'] |
||
| 185 | = $instance->getStrategy(); |
||
| 186 | |||
| 187 | continue; |
||
| 188 | } |
||
| 189 | |||
| 190 | $mapping = $entityClassMetadata->getAssociationMapping($associationName); |
||
| 191 | |||
| 192 | // See comment on NullifyOwningAssociation for details of why this is done |
||
| 193 | if ($mapping['type'] === ClassMetadataInfo::MANY_TO_MANY && $mapping['isOwningSide']) { |
||
| 194 | $this->metadata[$reflectionClass->getName()]['fields'][$associationName]['strategy'] = |
||
| 195 | Strategy\NullifyOwningAssociation::class; |
||
| 196 | } else { |
||
| 197 | $this->metadata[$reflectionClass->getName()]['fields'][$associationName]['strategy'] = |
||
| 198 | Strategy\AssociationDefault::class; |
||
| 199 | } |
||
| 204 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.