| Conditions | 6 |
| Paths | 10 |
| Total Lines | 63 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 29 | public function __invoke(array $entityClasses): array |
||
| 30 | { |
||
| 31 | $globalIgnore = $this->config->getGlobalIgnore(); |
||
| 32 | |||
| 33 | foreach ($entityClasses as $entityClass) { |
||
| 34 | // Get extract by value or reference |
||
| 35 | $byValue = $this->config->getGlobalByValue() ?? true; |
||
| 36 | |||
| 37 | // Save entity-level metadata |
||
| 38 | $this->metadataConfig[$entityClass] = [ |
||
| 39 | 'entityClass' => $entityClass, |
||
| 40 | 'byValue' => $byValue, |
||
| 41 | 'namingStrategy' => null, |
||
| 42 | 'fields' => [], |
||
| 43 | 'filters' => [], |
||
| 44 | 'excludeCriteria' => [], |
||
| 45 | 'description' => $entityClass, |
||
| 46 | 'typeName' => $this->getTypeName($entityClass), |
||
| 47 | ]; |
||
| 48 | |||
| 49 | // Fetch fields |
||
| 50 | $entityClassMetadata = $this->entityManager->getMetadataFactory()->getMetadataFor($entityClass); |
||
| 51 | $fieldNames = $entityClassMetadata->getFieldNames(); |
||
| 52 | |||
| 53 | foreach ($fieldNames as $fieldName) { |
||
| 54 | if (in_array($fieldName, $globalIgnore)) { |
||
| 55 | continue; |
||
| 56 | } |
||
| 57 | |||
| 58 | $this->metadataConfig[$entityClass]['fields'][$fieldName]['description'] = |
||
| 59 | $fieldName; |
||
| 60 | |||
| 61 | $this->metadataConfig[$entityClass]['fields'][$fieldName]['type'] = |
||
| 62 | $entityClassMetadata->getTypeOfField($fieldName); |
||
| 63 | |||
| 64 | // Set default strategy based on field type |
||
| 65 | $this->metadataConfig[$entityClass]['fields'][$fieldName]['strategy'] = |
||
| 66 | $this->getDefaultStrategy($entityClassMetadata->getTypeOfField($fieldName)); |
||
| 67 | |||
| 68 | $this->metadataConfig[$entityClass]['fields'][$fieldName]['excludeCriteria'] = []; |
||
| 69 | } |
||
| 70 | |||
| 71 | // Fetch attributes for associations |
||
| 72 | $associationNames = $this->entityManager->getMetadataFactory() |
||
| 73 | ->getMetadataFor($entityClass)->getAssociationNames(); |
||
| 74 | |||
| 75 | foreach ($associationNames as $associationName) { |
||
| 76 | if (in_array($associationName, $globalIgnore)) { |
||
| 77 | continue; |
||
| 78 | } |
||
| 79 | |||
| 80 | $this->metadataConfig[$entityClass]['fields'][$associationName]['excludeCriteria'] = []; |
||
| 81 | $this->metadataConfig[$entityClass]['fields'][$associationName]['description'] = $associationName; |
||
| 82 | $this->metadataConfig[$entityClass]['fields'][$associationName]['filterCriteriaEventName'] |
||
| 83 | = null; |
||
| 84 | |||
| 85 | // NullifyOwningAssociation is not used for globalEnable |
||
| 86 | $this->metadataConfig[$entityClass]['fields'][$associationName]['strategy'] = |
||
| 87 | Strategy\AssociationDefault::class; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | return $this->metadataConfig; |
||
| 92 | } |
||
| 94 |