| Conditions | 24 |
| Paths | 4944 |
| Total Lines | 87 |
| Code Lines | 50 |
| 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 |
||
| 26 | public function loadMetadataForClass($className, ClassMetadata $metadata) |
||
| 27 | { |
||
| 28 | $element = $this->getElement($className); |
||
| 29 | |||
| 30 | switch ($element['type']) { |
||
| 31 | case 'entity': |
||
| 32 | if (array_key_exists('repositoryClass', $element)) { |
||
| 33 | $metadata->setCustomRepositoryClass($element['repositoryClass']); |
||
| 34 | } |
||
| 35 | break; |
||
| 36 | case 'mappedSuperclass': |
||
| 37 | $metadata->isMappedSuperclass = true; |
||
|
|
|||
| 38 | $metadata->setCustomRepositoryClass( |
||
| 39 | array_key_exists('repositoryClass', $element) ? $element['repositoryClass'] : null |
||
| 40 | ); |
||
| 41 | break; |
||
| 42 | } |
||
| 43 | |||
| 44 | // Configure API |
||
| 45 | if (array_key_exists('api', $element)) { |
||
| 46 | if (array_key_exists('name', $element['api'])) { |
||
| 47 | $metadata->apiName = $element['api']['name']; |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | // Configure Client |
||
| 52 | if (array_key_exists('client', $element)) { |
||
| 53 | if (array_key_exists('name', $element['client'])) { |
||
| 54 | $metadata->clientName = $element['client']['name']; |
||
| 55 | } |
||
| 56 | |||
| 57 | $methodProvider = null; |
||
| 58 | if (array_key_exists('methods', $element['client'])) { |
||
| 59 | $methodProvider = new MethodProvider($element['client']['methods']); |
||
| 60 | } |
||
| 61 | if (array_key_exists('entityPath', $element['client'])) { |
||
| 62 | $pathSeparator = |
||
| 63 | array_key_exists('entityPathSeparator', $element['client']) ? |
||
| 64 | $element['client']['entityPathSeparator'] : |
||
| 65 | EntityMethodProvider::DEFAULT_PATH_SEPARATOR; |
||
| 66 | $methodProvider = |
||
| 67 | new EntityMethodProvider($element['client']['entityPath'], $pathSeparator, $methodProvider); |
||
| 68 | } |
||
| 69 | |||
| 70 | if (null === $methodProvider && null === $metadata->methodProvider) { |
||
| 71 | throw MappingException::noMethods(); |
||
| 72 | } |
||
| 73 | |||
| 74 | if (null !== $methodProvider) { |
||
| 75 | $metadata->methodProvider = $methodProvider; |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | // Configure fields |
||
| 80 | if (array_key_exists('fields', $element)) { |
||
| 81 | foreach ($element['fields'] as $field => $mapping) { |
||
| 82 | $mapping = $this->fieldToArray($field, $mapping); |
||
| 83 | $metadata->mapField($mapping); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | // Configure identifiers |
||
| 88 | $associationIds = []; |
||
| 89 | if (array_key_exists('id', $element)) { |
||
| 90 | // Evaluate identifier settings |
||
| 91 | foreach ($element['id'] as $name => $idElement) { |
||
| 92 | if (isset($idElement['associationKey']) && (bool)$idElement['associationKey'] === true) { |
||
| 93 | $associationIds[$name] = true; |
||
| 94 | continue; |
||
| 95 | } |
||
| 96 | |||
| 97 | $mapping = $this->fieldToArray($name, $idElement); |
||
| 98 | |||
| 99 | $mapping['id'] = true; |
||
| 100 | $metadata->mapField($mapping); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | foreach (['oneToOne', 'manyToOne', 'oneToMany'] as $type) { |
||
| 105 | if (array_key_exists($type, $element)) { |
||
| 106 | $associations = $element[$type]; |
||
| 107 | foreach ($associations as $name => $association) { |
||
| 108 | $this->mapAssociation($metadata, $type, $name, $association, $associationIds); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 203 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: