| Conditions | 41 |
| Paths | > 20000 |
| Total Lines | 106 |
| Code Lines | 69 |
| Lines | 30 |
| Ratio | 28.3 % |
| Tests | 85 |
| CRAP Score | 47.6808 |
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 |
||
| 50 | 4 | public function loadMetadataForClass($className, ClassMetadata $class) |
|
| 51 | { |
||
| 52 | /* @var $class ClassMetadataInfo */ |
||
| 53 | 4 | $element = $this->getElement($className); |
|
| 54 | 4 | if ( ! $element) { |
|
|
|
|||
| 55 | return; |
||
| 56 | } |
||
| 57 | 4 | $element['type'] = isset($element['type']) ? $element['type'] : 'document'; |
|
| 58 | |||
| 59 | 4 | if (isset($element['db'])) { |
|
| 60 | 1 | $class->setDatabase($element['db']); |
|
| 61 | 1 | } |
|
| 62 | 4 | if (isset($element['collection'])) { |
|
| 63 | 4 | $class->setCollection($element['collection']); |
|
| 64 | 4 | } |
|
| 65 | 4 | if ($element['type'] == 'document') { |
|
| 66 | 4 | if (isset($element['repositoryClass'])) { |
|
| 67 | $class->setCustomRepositoryClass($element['repositoryClass']); |
||
| 68 | } |
||
| 69 | 4 | View Code Duplication | } elseif ($element['type'] === 'mappedSuperclass') { |
| 70 | $class->setCustomRepositoryClass( |
||
| 71 | isset($element['repositoryClass']) ? $element['repositoryClass'] : null |
||
| 72 | ); |
||
| 73 | $class->isMappedSuperclass = true; |
||
| 74 | 1 | } elseif ($element['type'] === 'embeddedDocument') { |
|
| 75 | 1 | $class->isEmbeddedDocument = true; |
|
| 76 | 1 | } |
|
| 77 | 4 | if (isset($element['indexes'])) { |
|
| 78 | 1 | foreach($element['indexes'] as $index) { |
|
| 79 | 1 | $class->addIndex($index['keys'], isset($index['options']) ? $index['options'] : array()); |
|
| 80 | 1 | } |
|
| 81 | 1 | } |
|
| 82 | 4 | if (isset($element['inheritanceType'])) { |
|
| 83 | $class->setInheritanceType(constant('Doctrine\ODM\MongoDB\Mapping\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($element['inheritanceType']))); |
||
| 84 | } |
||
| 85 | 4 | if (isset($element['discriminatorField'])) { |
|
| 86 | 1 | $class->setDiscriminatorField($this->parseDiscriminatorField($element['discriminatorField'])); |
|
| 87 | 1 | } |
|
| 88 | 4 | if (isset($element['discriminatorMap'])) { |
|
| 89 | 1 | $class->setDiscriminatorMap($element['discriminatorMap']); |
|
| 90 | 1 | } |
|
| 91 | 4 | if (isset($element['defaultDiscriminatorValue'])) { |
|
| 92 | 1 | $class->setDefaultDiscriminatorValue($element['defaultDiscriminatorValue']); |
|
| 93 | 1 | } |
|
| 94 | 4 | View Code Duplication | if (isset($element['changeTrackingPolicy'])) { |
| 95 | $class->setChangeTrackingPolicy(constant('Doctrine\ODM\MongoDB\Mapping\ClassMetadata::CHANGETRACKING_' |
||
| 96 | . strtoupper($element['changeTrackingPolicy']))); |
||
| 97 | } |
||
| 98 | 4 | if (isset($element['requireIndexes'])) { |
|
| 99 | $class->setRequireIndexes($element['requireIndexes']); |
||
| 100 | } |
||
| 101 | 4 | if (isset($element['slaveOkay'])) { |
|
| 102 | $class->setSlaveOkay($element['slaveOkay']); |
||
| 103 | } |
||
| 104 | 4 | if (isset($element['fields'])) { |
|
| 105 | 4 | foreach ($element['fields'] as $fieldName => $mapping) { |
|
| 106 | 4 | if (is_string($mapping)) { |
|
| 107 | 1 | $type = $mapping; |
|
| 108 | 1 | $mapping = array(); |
|
| 109 | 1 | $mapping['type'] = $type; |
|
| 110 | 1 | } |
|
| 111 | 4 | if ( ! isset($mapping['fieldName'])) { |
|
| 112 | 4 | $mapping['fieldName'] = $fieldName; |
|
| 113 | 4 | } |
|
| 114 | 4 | if (isset($mapping['type']) && ! empty($mapping['embedded'])) { |
|
| 115 | 2 | $this->addMappingFromEmbed($class, $fieldName, $mapping, $mapping['type']); |
|
| 116 | 4 | } elseif (isset($mapping['type']) && ! empty($mapping['reference'])) { |
|
| 117 | 2 | $this->addMappingFromReference($class, $fieldName, $mapping, $mapping['type']); |
|
| 118 | 2 | } else { |
|
| 119 | 4 | $this->addFieldMapping($class, $mapping); |
|
| 120 | } |
||
| 121 | 4 | } |
|
| 122 | 4 | } |
|
| 123 | 4 | View Code Duplication | if (isset($element['embedOne'])) { |
| 124 | 2 | foreach ($element['embedOne'] as $fieldName => $embed) { |
|
| 125 | 2 | $this->addMappingFromEmbed($class, $fieldName, $embed, 'one'); |
|
| 126 | 2 | } |
|
| 127 | 2 | } |
|
| 128 | 4 | View Code Duplication | if (isset($element['embedMany'])) { |
| 129 | 2 | foreach ($element['embedMany'] as $fieldName => $embed) { |
|
| 130 | 2 | $this->addMappingFromEmbed($class, $fieldName, $embed, 'many'); |
|
| 131 | 2 | } |
|
| 132 | 2 | } |
|
| 133 | 4 | View Code Duplication | if (isset($element['referenceOne'])) { |
| 134 | 2 | foreach ($element['referenceOne'] as $fieldName => $reference) { |
|
| 135 | 2 | $this->addMappingFromReference($class, $fieldName, $reference, 'one'); |
|
| 136 | 2 | } |
|
| 137 | 2 | } |
|
| 138 | 4 | View Code Duplication | if (isset($element['referenceMany'])) { |
| 139 | 2 | foreach ($element['referenceMany'] as $fieldName => $reference) { |
|
| 140 | 2 | $this->addMappingFromReference($class, $fieldName, $reference, 'many'); |
|
| 141 | 2 | } |
|
| 142 | 2 | } |
|
| 143 | 4 | if (isset($element['lifecycleCallbacks'])) { |
|
| 144 | 2 | foreach ($element['lifecycleCallbacks'] as $type => $methods) { |
|
| 145 | 2 | foreach ($methods as $method) { |
|
| 146 | 2 | $class->addLifecycleCallback($method, constant('Doctrine\ODM\MongoDB\Events::' . $type)); |
|
| 147 | 2 | } |
|
| 148 | 2 | } |
|
| 149 | 2 | } |
|
| 150 | 4 | if (isset($element['alsoLoadMethods'])) { |
|
| 151 | 1 | foreach ($element['alsoLoadMethods'] as $methodName => $fieldName) { |
|
| 152 | 1 | $class->registerAlsoLoadMethod($methodName, $fieldName); |
|
| 153 | 1 | } |
|
| 154 | 1 | } |
|
| 155 | 4 | } |
|
| 156 | |||
| 339 |
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.