Conditions | 10 |
Paths | 55 |
Total Lines | 40 |
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 |
||
65 | public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription): void |
||
66 | { |
||
67 | $fieldDescription->setAdmin($admin); |
||
68 | |||
69 | if ($admin->getModelManager()->hasMetadata($admin->getClass())) { |
||
70 | list($metadata, $lastPropertyName, $parentAssociationMappings) = $admin->getModelManager()->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName()); |
||
71 | $fieldDescription->setParentAssociationMappings($parentAssociationMappings); |
||
72 | |||
73 | // set the default field mapping |
||
74 | if (isset($metadata->fieldMappings[$lastPropertyName])) { |
||
75 | $fieldDescription->setFieldMapping($metadata->fieldMappings[$lastPropertyName]); |
||
76 | } |
||
77 | |||
78 | // set the default association mapping |
||
79 | if (isset($metadata->associationMappings[$lastPropertyName])) { |
||
80 | $fieldDescription->setAssociationMapping($metadata->associationMappings[$lastPropertyName]); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | if (!$fieldDescription->getType()) { |
||
85 | throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), \get_class($admin))); |
||
86 | } |
||
87 | |||
88 | $fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName())); |
||
89 | $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName())); |
||
90 | |||
91 | if (!$fieldDescription->getTemplate()) { |
||
|
|||
92 | $fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType())); |
||
93 | } |
||
94 | |||
95 | switch ($fieldDescription->getMappingType()) { |
||
96 | case ClassMetadata::MANY_TO_ONE: |
||
97 | case ClassMetadata::ONE_TO_ONE: |
||
98 | case ClassMetadata::ONE_TO_MANY: |
||
99 | case ClassMetadata::MANY_TO_MANY: |
||
100 | $admin->attachAdminClass($fieldDescription); |
||
101 | |||
102 | break; |
||
103 | } |
||
104 | } |
||
105 | |||
135 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: