Conditions | 15 |
Paths | 490 |
Total Lines | 63 |
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 |
||
72 | public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription) |
||
73 | { |
||
74 | if ('_action' === $fieldDescription->getName() || 'actions' === $fieldDescription->getType()) { |
||
75 | $this->buildActionFieldDescription($fieldDescription); |
||
76 | } |
||
77 | |||
78 | $fieldDescription->setAdmin($admin); |
||
79 | |||
80 | if ($admin->getModelManager()->hasMetadata($admin->getClass())) { |
||
81 | list($metadata, $lastPropertyName, $parentAssociationMappings) = $admin->getModelManager()->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName()); |
||
82 | $fieldDescription->setParentAssociationMappings($parentAssociationMappings); |
||
83 | |||
84 | // set the default field mapping |
||
85 | if (isset($metadata->fieldMappings[$lastPropertyName])) { |
||
86 | $fieldDescription->setFieldMapping($metadata->fieldMappings[$lastPropertyName]); |
||
87 | if (false !== $fieldDescription->getOption('sortable')) { |
||
88 | $fieldDescription->setOption('sortable', $fieldDescription->getOption('sortable', true)); |
||
89 | $fieldDescription->setOption('sort_parent_association_mappings', $fieldDescription->getOption('sort_parent_association_mappings', $fieldDescription->getParentAssociationMappings())); |
||
90 | $fieldDescription->setOption('sort_field_mapping', $fieldDescription->getOption('sort_field_mapping', $fieldDescription->getFieldMapping())); |
||
91 | } |
||
92 | } |
||
93 | |||
94 | // set the default association mapping |
||
95 | if (isset($metadata->associationMappings[$lastPropertyName])) { |
||
96 | $fieldDescription->setAssociationMapping($metadata->associationMappings[$lastPropertyName]); |
||
97 | } |
||
98 | |||
99 | $fieldDescription->setOption('_sort_order', $fieldDescription->getOption('_sort_order', 'ASC')); |
||
100 | } |
||
101 | |||
102 | if (!$fieldDescription->getType()) { |
||
103 | throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), \get_class($admin))); |
||
104 | } |
||
105 | |||
106 | $fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName())); |
||
107 | $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName())); |
||
108 | |||
109 | if (!$fieldDescription->getTemplate()) { |
||
|
|||
110 | if ('id' === $fieldDescription->getType()) { |
||
111 | $fieldDescription->setType('string'); |
||
112 | } |
||
113 | |||
114 | if ('int' === $fieldDescription->getType()) { |
||
115 | $fieldDescription->setType('integer'); |
||
116 | } |
||
117 | |||
118 | $template = $this->getTemplate($fieldDescription->getType()); |
||
119 | |||
120 | if (null === $template) { |
||
121 | if (ClassMetadata::ONE === $fieldDescription->getMappingType()) { |
||
122 | $template = '@SonataAdmin/CRUD/Association/list_many_to_one.html.twig'; |
||
123 | } elseif (ClassMetadata::MANY === $fieldDescription->getMappingType()) { |
||
124 | $template = '@SonataAdmin/CRUD/Association/list_many_to_many.html.twig'; |
||
125 | } |
||
126 | } |
||
127 | |||
128 | $fieldDescription->setTemplate($template); |
||
129 | } |
||
130 | |||
131 | if (\in_array($fieldDescription->getMappingType(), [ClassMetadata::ONE, ClassMetadata::MANY], true)) { |
||
132 | $admin->attachAdminClass($fieldDescription); |
||
133 | } |
||
134 | } |
||
135 | |||
185 |
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: