Conditions | 28 |
Paths | 107 |
Total Lines | 99 |
Code Lines | 51 |
Lines | 12 |
Ratio | 12.12 % |
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 |
||
153 | private function readExtendedMetadata(ORM\Mapping\ClassMetadata $metadata, array $config) |
||
154 | { |
||
155 | $class = $metadata->getReflectionClass(); |
||
156 | |||
157 | // Create doctrine annotation reader |
||
158 | $reader = $this->getDefaultAnnotationReader(); |
||
159 | |||
160 | // Property annotations |
||
161 | foreach ($class->getProperties() as $property) { |
||
162 | if ($metadata->isMappedSuperclass && $property->isPrivate() === FALSE || |
||
163 | $metadata->isInheritedField($property->getName()) || |
||
164 | isset($metadata->associationMappings[$property->getName()]['inherited']) |
||
165 | ) { |
||
166 | continue; |
||
167 | } |
||
168 | |||
169 | if ($blameable = $reader->getPropertyAnnotation($property, self::EXTENSION_ANNOTATION)) { |
||
|
|||
170 | $field = $property->getName(); |
||
171 | |||
172 | // No map field nor association |
||
173 | if ($metadata->hasField($field) === FALSE && $metadata->hasAssociation($field) === FALSE && $this->configuration->useLazyAssociation() === FALSE) { |
||
174 | if ($this->configuration->automapField) { |
||
175 | if ($this->configuration->automapWithAssociation()) { |
||
176 | $entityMap = [ |
||
177 | 'targetEntity' => $this->configuration->userEntity, |
||
178 | 'fieldName' => $field, |
||
179 | 'joinColumns' => [ |
||
180 | [ |
||
181 | 'onDelete' => 'SET NULL', |
||
182 | ] |
||
183 | ] |
||
184 | ]; |
||
185 | |||
186 | View Code Duplication | if (isset($blameable->association['column']) && $blameable->association['column'] !== NULL) { |
|
187 | $entityMap['joinColumns'][0]['name'] = $blameable->columnName; |
||
188 | } |
||
189 | |||
190 | View Code Duplication | if (isset($blameable->association['referencedColumn']) && $blameable->association['referencedColumn'] !== NULL) { |
|
191 | $entityMap['joinColumns'][0]['referencedColumnName'] = $blameable->referencedColumnName; |
||
192 | } |
||
193 | |||
194 | $metadata->mapManyToOne($entityMap); |
||
195 | |||
196 | } else if ($this->configuration->automapWithField()) { |
||
197 | $metadata->mapField([ |
||
198 | 'fieldName' => $field, |
||
199 | 'type' => 'string', |
||
200 | 'nullable' => TRUE, |
||
201 | ]); |
||
202 | |||
203 | } else { |
||
204 | throw new Exceptions\InvalidMappingException("Unable to find blameable [{$field}] as mapped property in entity - {$metadata->getName()}"); |
||
205 | } |
||
206 | |||
207 | } else { |
||
208 | throw new Exceptions\InvalidMappingException("Unable to find blameable [{$field}] as mapped property in entity - {$metadata->getName()}"); |
||
209 | } |
||
210 | } |
||
211 | |||
212 | if ($metadata->hasField($field)) { |
||
213 | View Code Duplication | if (!$this->isValidField($metadata, $field) && $this->configuration->useLazyAssociation() === FALSE) { |
|
214 | throw new Exceptions\InvalidMappingException("Field - [{$field}] type is not valid and must be 'string' or a one-to-many relation in class - {$metadata->getName()}"); |
||
215 | } |
||
216 | |||
217 | } else if ($metadata->hasAssociation($field)) { |
||
218 | // association |
||
219 | View Code Duplication | if ($metadata->isSingleValuedAssociation($field) === FALSE && $this->configuration->useLazyAssociation() === FALSE) { |
|
220 | throw new Exceptions\InvalidMappingException("Association - [{$field}] is not valid, it must be a one-to-many relation or a string field - {$metadata->getName()}"); |
||
221 | } |
||
222 | } |
||
223 | |||
224 | // Check for valid events |
||
225 | if (!in_array($blameable->on, ['update', 'create', 'change', 'delete'])) { |
||
226 | throw new Exceptions\InvalidMappingException("Field - [{$field}] trigger 'on' is not one of [update, create, change] in class - {$metadata->getName()}"); |
||
227 | } |
||
228 | |||
229 | if ($blameable->on === 'change') { |
||
230 | if (!isset($blameable->field)) { |
||
231 | throw new Exceptions\InvalidMappingException("Missing parameters on property - {$field}, field must be set on [change] trigger in class - {$metadata->getName()}"); |
||
232 | } |
||
233 | |||
234 | if (is_array($blameable->field) && isset($blameable->value)) { |
||
235 | throw new Exceptions\InvalidMappingException("Blameable extension does not support multiple value changeset detection yet."); |
||
236 | } |
||
237 | |||
238 | $field = [ |
||
239 | 'field' => $field, |
||
240 | 'trackedField' => $blameable->field, |
||
241 | 'value' => $blameable->value, |
||
242 | ]; |
||
243 | } |
||
244 | |||
245 | // properties are unique and mapper checks that, no risk here |
||
246 | $config[$blameable->on][] = $field; |
||
247 | } |
||
248 | } |
||
249 | |||
250 | return $config; |
||
251 | } |
||
252 | |||
349 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.