Conditions | 2 |
Paths | 1 |
Total Lines | 144 |
Code Lines | 108 |
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 |
||
67 | public function shouldReadAnnotations() |
||
68 | { |
||
69 | $someAnnotationA = new Service(); |
||
70 | $someAnnotationA->id = "some_service"; |
||
71 | $someAnnotationA->field = "foo"; |
||
72 | |||
73 | $someAnnotationB = new Service(); |
||
74 | $someAnnotationB->id = "other_service"; |
||
75 | $someAnnotationB->field = "bar"; |
||
76 | $someAnnotationB->lax = true; |
||
77 | |||
78 | $someAnnotationC = new Choice(); |
||
79 | $someAnnotationC->column = "baz_column"; |
||
80 | $someAnnotationC->nullable = true; |
||
81 | $someAnnotationC->choices = [ |
||
82 | 'foo' => $someAnnotationA, |
||
83 | 'bar' => $someAnnotationB, |
||
84 | ]; |
||
85 | |||
86 | $someAnnotationD = new Choice(); |
||
87 | $someAnnotationD->column = "faz_column"; |
||
88 | $someAnnotationD->nullable = false; |
||
89 | $someAnnotationD->choices = [ |
||
90 | 'foo' => $someAnnotationA, |
||
91 | 'bar' => $someAnnotationB, |
||
92 | ]; |
||
93 | |||
94 | $someAnnotationF = new ORMColumn(); |
||
95 | $someAnnotationF->name = "someField"; |
||
96 | $someAnnotationF->length = 12; |
||
97 | |||
98 | $someAnnotationE = new RDMObject(); |
||
99 | $someAnnotationE->{"class"} = ValueObjectExample::class; |
||
100 | $someAnnotationE->fields = [ |
||
101 | 'foo' => $someAnnotationA, |
||
102 | 'bar' => $someAnnotationF, |
||
103 | ]; |
||
104 | |||
105 | $someAnnotationG = new RDMArray(); |
||
106 | $someAnnotationG->entries = [ |
||
107 | 'foo' => $someAnnotationA, |
||
108 | 'bar' => $someAnnotationF, |
||
109 | ]; |
||
110 | |||
111 | /** @var string $entityClass */ |
||
112 | $entityClass = EntityExample::class; |
||
113 | |||
114 | /** @var array<MappingInterface> $expectedFieldMappings */ |
||
115 | $expectedFieldMappings = [ |
||
116 | 'foo' => new ServiceMapping( |
||
117 | $this->container, |
||
118 | "some_service", |
||
119 | false, |
||
120 | "in entity '{$entityClass}' on field 'foo'" |
||
121 | ), |
||
122 | 'bar' => new ServiceMapping( |
||
123 | $this->container, |
||
124 | "other_service", |
||
125 | true, |
||
126 | "in entity '{$entityClass}' on field 'bar'" |
||
127 | ), |
||
128 | 'baz' => new ChoiceMapping('baz_column', [ |
||
129 | 'foo' => new ServiceMapping( |
||
130 | $this->container, |
||
131 | "some_service", |
||
132 | false, |
||
133 | "in entity '{$entityClass}' on field 'baz'" |
||
134 | ), |
||
135 | 'bar' => new ServiceMapping( |
||
136 | $this->container, |
||
137 | "other_service", |
||
138 | true, |
||
139 | "in entity '{$entityClass}' on field 'baz'" |
||
140 | ), |
||
141 | ], "in entity 'Addiks\RDMBundle\Tests\Hydration\EntityExample' on field 'baz'"), |
||
142 | 'faz' => new ChoiceMapping(new DBALColumn('faz_column', Type::getType('string'), [ |
||
143 | 'notnull' => true, |
||
144 | 'length' => 255, |
||
145 | ]), [ |
||
146 | 'foo' => new ServiceMapping( |
||
147 | $this->container, |
||
148 | "some_service", |
||
149 | false, |
||
150 | "in entity '{$entityClass}' on field 'faz'" |
||
151 | ), |
||
152 | 'bar' => new ServiceMapping( |
||
153 | $this->container, |
||
154 | "other_service", |
||
155 | true, |
||
156 | "in entity '{$entityClass}' on field 'faz'" |
||
157 | ), |
||
158 | ], "in entity 'Addiks\RDMBundle\Tests\Hydration\EntityExample' on field 'faz'"), |
||
159 | 'boo' => new ObjectMapping(ValueObjectExample::class, [ |
||
160 | 'foo' => new ServiceMapping( |
||
161 | $this->container, |
||
162 | "some_service", |
||
163 | false, |
||
164 | "in entity '{$entityClass}' on field 'boo->foo'" |
||
165 | ), |
||
166 | 'bar' => new FieldMapping(new DBALColumn('someField', Type::getType('string'), [ |
||
167 | 'notnull' => true, |
||
168 | 'precision' => 0, |
||
169 | 'length' => 12, |
||
170 | ]), "in entity '{$entityClass}' on field 'boo->bar'"), |
||
171 | ], null, "in entity 'Addiks\RDMBundle\Tests\Hydration\EntityExample' on field 'boo'"), |
||
172 | 'arr' => new ArrayMapping([ |
||
173 | 'foo' => new ServiceMapping( |
||
174 | $this->container, |
||
175 | "some_service", |
||
176 | false, |
||
177 | "in entity '{$entityClass}' on field 'arr->foo'" |
||
178 | ), |
||
179 | 'bar' => new FieldMapping(new DBALColumn('someField', Type::getType('string'), [ |
||
180 | 'notnull' => true, |
||
181 | 'precision' => 0, |
||
182 | 'length' => 12, |
||
183 | ]), "in entity '{$entityClass}' on field 'arr->bar'"), |
||
184 | ], "in entity 'Addiks\RDMBundle\Tests\Hydration\EntityExample' on field 'arr'") |
||
185 | ]; |
||
186 | |||
187 | /** @var array<array<Service>> $annotationMap */ |
||
188 | $annotationMap = [ |
||
189 | 'foo' => [$someAnnotationA], |
||
190 | 'bar' => [$someAnnotationB], |
||
191 | 'baz' => [$someAnnotationC], |
||
192 | 'faz' => [$someAnnotationD], |
||
193 | 'boo' => [$someAnnotationE], |
||
194 | 'arr' => [$someAnnotationG], |
||
195 | ]; |
||
196 | |||
197 | $this->annotationReader->method('getPropertyAnnotations')->will($this->returnCallback( |
||
198 | function (ReflectionProperty $propertyReflection) use ($annotationMap) { |
||
199 | if (isset($annotationMap[$propertyReflection->getName()])) { |
||
200 | return $annotationMap[$propertyReflection->getName()]; |
||
201 | } else { |
||
202 | return []; |
||
203 | } |
||
204 | } |
||
205 | )); |
||
206 | |||
207 | /** @var EntityMapping $actualMapping */ |
||
208 | $actualMapping = $this->mappingDriver->loadRDMMetadataForClass(EntityExample::class); |
||
209 | |||
210 | $this->assertEquals($expectedFieldMappings, $actualMapping->getFieldMappings()); |
||
211 | } |
||
214 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..