Conditions | 21 |
Paths | 152 |
Total Lines | 72 |
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 |
||
33 | public function loadMetadataForClass($className, ClassMetadata $class) |
||
34 | { |
||
35 | $reflClass = $class->getReflectionClass(); |
||
36 | |||
37 | $isValidDocument = false; |
||
38 | $classAnnotations = $this->reader->getClassAnnotations($reflClass); |
||
39 | |||
40 | foreach ($classAnnotations AS $classAnnotation) { |
||
41 | if ($classAnnotation instanceof ODM\Document) { |
||
42 | if ($classAnnotation->indexed) { |
||
43 | $class->indexed = true; |
||
|
|||
44 | } |
||
45 | $class->setCustomRepositoryClass($classAnnotation->repositoryClass); |
||
46 | $isValidDocument = true; |
||
47 | } elseif ($classAnnotation instanceof ODM\EmbeddedDocument) { |
||
48 | $class->isEmbeddedDocument = true; |
||
49 | $isValidDocument = true; |
||
50 | } else if ($classAnnotation instanceof ODM\MappedSuperclass) { |
||
51 | $class->isMappedSuperclass = true; |
||
52 | $isValidDocument = true; |
||
53 | } else if ($classAnnotation instanceof ODM\Index) { |
||
54 | $class->indexed = true; |
||
55 | } else if ($classAnnotation instanceof ODM\InheritanceRoot) { |
||
56 | $class->markInheritanceRoot(); |
||
57 | } |
||
58 | } |
||
59 | |||
60 | if ( ! $isValidDocument) { |
||
61 | throw MappingException::classIsNotAValidDocument($className); |
||
62 | } |
||
63 | |||
64 | foreach ($reflClass->getProperties() as $property) { |
||
65 | if ($class->isInheritedAssociation($property->name) || $class->isInheritedField($property->name)) { |
||
66 | continue; |
||
67 | } |
||
68 | |||
69 | $mapping = array(); |
||
70 | $mapping['fieldName'] = $property->name; |
||
71 | |||
72 | if ($this->reader->getPropertyAnnotation($property, 'Doctrine\ODM\CouchDB\Mapping\Annotations\Index')) { |
||
73 | $mapping['indexed'] = true; |
||
74 | } |
||
75 | |||
76 | foreach ($this->reader->getPropertyAnnotations($property) as $fieldAnnot) { |
||
77 | if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Field) { |
||
78 | if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Version) { |
||
79 | $mapping['isVersionField'] = true; |
||
80 | } |
||
81 | |||
82 | $mapping = array_merge($mapping, (array) $fieldAnnot); |
||
83 | unset($mapping['value']); |
||
84 | $class->mapField($mapping); |
||
85 | } else if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\ReferenceOne) { |
||
86 | $mapping = array_merge($mapping, (array) $fieldAnnot); |
||
87 | $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade); |
||
88 | unset($mapping['value']); |
||
89 | $class->mapManyToOne($mapping); |
||
90 | } else if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\ReferenceMany) { |
||
91 | $mapping = array_merge($mapping, (array) $fieldAnnot); |
||
92 | $mapping['cascade'] = $this->getCascadeMode($fieldAnnot->cascade); |
||
93 | unset($mapping['value']); |
||
94 | $class->mapManyToMany($mapping); |
||
95 | } else if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\Attachments) { |
||
96 | $class->mapAttachments($mapping['fieldName']); |
||
97 | } else if ($fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\EmbedOne || $fieldAnnot instanceof \Doctrine\ODM\CouchDB\Mapping\Annotations\EmbedMany) { |
||
98 | $mapping = array_merge($mapping, (array) $fieldAnnot); |
||
99 | unset($mapping['value']); |
||
100 | $class->mapEmbedded($mapping); |
||
101 | } |
||
102 | } |
||
103 | } |
||
104 | } |
||
105 | |||
126 |
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: