| Conditions | 43 |
| Paths | 3363 |
| Total Lines | 127 |
| Lines | 60 |
| Ratio | 47.24 % |
| 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 |
||
| 36 | public function loadMetadataForClass($className, ClassMetadata $class) |
||
| 37 | { |
||
| 38 | /** @var $class \Doctrine\ODM\CouchDB\Mapping\ClassMetadata */ |
||
| 39 | try { |
||
| 40 | $xmlRoot = $this->getElement($className); |
||
| 41 | } catch (DoctrineMappingException $e) { |
||
| 42 | // Convert Exception type for consistency with other drivers |
||
| 43 | throw new MappingException($e->getMessage(), $e->getCode(), $e); |
||
| 44 | } |
||
| 45 | |||
| 46 | if (!$xmlRoot) { |
||
| 47 | return; |
||
| 48 | } |
||
| 49 | |||
| 50 | if ($xmlRoot->getName() == 'document') { |
||
| 51 | $class->setCustomRepositoryClass( |
||
| 52 | isset($xmlRoot['repository-class']) ? (string)$xmlRoot['repository-class'] : null |
||
| 53 | ); |
||
| 54 | |||
| 55 | if (isset($xmlRoot['indexed']) && $xmlRoot['indexed'] == true) { |
||
| 56 | $class->indexed = true; |
||
| 57 | } |
||
| 58 | |||
| 59 | if (isset($xmlRoot['inheritance-root']) && $xmlRoot['inheritance-root']) { |
||
| 60 | $class->markInheritanceRoot(); |
||
| 61 | } |
||
| 62 | } else if ($xmlRoot->getName() == "embedded-document") { |
||
| 63 | $class->isEmbeddedDocument = true; |
||
| 64 | |||
| 65 | if (isset($xmlRoot['inheritance-root']) && $xmlRoot['inheritance-root']) { |
||
| 66 | $class->markInheritanceRoot(); |
||
| 67 | } |
||
| 68 | } else if ($xmlRoot->getName() == "mapped-superclass") { |
||
| 69 | $class->isMappedSuperclass = true; |
||
| 70 | } else { |
||
| 71 | throw MappingException::classIsNotAValidDocument($className); |
||
| 72 | } |
||
| 73 | |||
| 74 | // Evaluate <field ...> mappings |
||
| 75 | if (isset($xmlRoot->field)) { |
||
|
|
|||
| 76 | View Code Duplication | foreach ($xmlRoot->field as $fieldMapping) { |
|
| 77 | $class->mapField(array( |
||
| 78 | 'fieldName' => (string)$fieldMapping['name'], |
||
| 79 | 'jsonName' => (isset($fieldMapping['json-name'])) ? (string)$fieldMapping['json-name'] : null, |
||
| 80 | 'indexed' => (isset($fieldMapping['index'])) ? (bool)$fieldMapping['index'] : false, |
||
| 81 | 'type' => (isset($fieldMapping['type'])) ? (string)$fieldMapping['type'] : null, |
||
| 82 | 'isVersionField' => (isset($fieldMapping['version'])) ? true : null, |
||
| 83 | )); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | // Evaluate <id ..> mappings |
||
| 88 | View Code Duplication | foreach ($xmlRoot->id as $idElement) { |
|
| 89 | $class->mapField(array( |
||
| 90 | 'fieldName' => (string)$idElement['name'], |
||
| 91 | 'indexed' => (isset($idElement['index'])) ? (bool)$idElement['index'] : false, |
||
| 92 | 'type' => (isset($idElement['type'])) ? (string)$idElement['type'] : null, |
||
| 93 | 'id' => true, |
||
| 94 | 'strategy' => (isset($idElement['strategy'])) ? (string)$idElement['strategy'] : null, |
||
| 95 | )); |
||
| 96 | } |
||
| 97 | |||
| 98 | // Evaluate <version ..> mappings |
||
| 99 | foreach ($xmlRoot->version as $versionElement) { |
||
| 100 | $class->mapField(array( |
||
| 101 | 'fieldName' => (string)$versionElement['name'], |
||
| 102 | 'type' => 'string', |
||
| 103 | 'isVersionField' => true, |
||
| 104 | 'jsonName' => '_rev', |
||
| 105 | )); |
||
| 106 | } |
||
| 107 | |||
| 108 | // Evaluate <many-to-one ..> mappings |
||
| 109 | View Code Duplication | if (isset($xmlRoot->{"reference-one"})) { |
|
| 110 | foreach ($xmlRoot->{"reference-one"} as $referenceOneElement) { |
||
| 111 | $class->mapManyToOne(array( |
||
| 112 | 'cascade' => (isset($referenceOneElement->cascade)) ? $this->getCascadeMode($referenceOneElement->cascade) : 0, |
||
| 113 | 'targetDocument' => (string)$referenceOneElement['target-document'], |
||
| 114 | 'fieldName' => (string)$referenceOneElement['field'], |
||
| 115 | 'jsonName' => (isset($referenceOneElement['json-name'])) ? (string)$referenceOneElement['json-name'] : null, |
||
| 116 | 'indexed' => (isset($referenceOneElement['index'])) ? (bool)$referenceOneElement['index'] : false, |
||
| 117 | )); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | // Evaluate <many-to-one ..> mappings |
||
| 122 | View Code Duplication | if (isset($xmlRoot->{"reference-many"})) { |
|
| 123 | foreach ($xmlRoot->{"reference-many"} as $referenceManyElement) { |
||
| 124 | $class->mapManyToMany(array( |
||
| 125 | 'cascade' => (isset($referenceManyElement->cascade)) ? $this->getCascadeMode($referenceManyElement->cascade) : 0, |
||
| 126 | 'targetDocument' => (string)$referenceManyElement['target-document'], |
||
| 127 | 'fieldName' => (string)$referenceManyElement['field'], |
||
| 128 | 'jsonName' => (isset($referenceManyElement['json-name'])) ? (string)$referenceManyElement['json-name'] : null, |
||
| 129 | 'mappedBy' => (isset($referenceManyElement['mapped-by'])) ? (string)$referenceManyElement['mapped-by'] : null, |
||
| 130 | )); |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 134 | // Evaluate <attachments ..> mapping |
||
| 135 | if (isset($xmlRoot->{"attachments"})) { |
||
| 136 | $class->mapAttachments((string)$xmlRoot->{"attachments"}[0]['field']); |
||
| 137 | } |
||
| 138 | |||
| 139 | // Evaluate <embed-one /> |
||
| 140 | View Code Duplication | if (isset($xmlRoot->{'embed-one'})) { |
|
| 141 | foreach ($xmlRoot->{'embed-one'} AS $embedOneElement) { |
||
| 142 | $class->mapEmbedded(array( |
||
| 143 | 'targetDocument' => (isset($embedOneElement['target-document']) ? (string)$embedOneElement['target-document'] : null), |
||
| 144 | 'fieldName' => (string)$embedOneElement['field'], |
||
| 145 | 'jsonName' => (isset($embedOneElement['json-name'])) ? (string)$embedOneElement['json-name'] : null, |
||
| 146 | 'embedded' => 'one', |
||
| 147 | )); |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | // Evaluate <embed-many /> |
||
| 152 | View Code Duplication | if (isset($xmlRoot->{'embed-many'})) { |
|
| 153 | foreach ($xmlRoot->{'embed-many'} AS $embedManyElement) { |
||
| 154 | $class->mapEmbedded(array( |
||
| 155 | 'targetDocument' => (isset($embedManyElement['target-document']) ? (string)$embedManyElement['target-document'] : null), |
||
| 156 | 'fieldName' => (string)$embedManyElement['field'], |
||
| 157 | 'jsonName' => (isset($embedManyElement['json-name'])) ? (string)$embedManyElement['json-name'] : null, |
||
| 158 | 'embedded' => 'many', |
||
| 159 | )); |
||
| 160 | } |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 209 |
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: