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 |
||
60 | public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription): void |
||
61 | { |
||
62 | if ('_action' === $fieldDescription->getName() || 'actions' === $fieldDescription->getType()) { |
||
63 | $this->buildActionFieldDescription($fieldDescription); |
||
64 | } |
||
65 | |||
66 | $fieldDescription->setAdmin($admin); |
||
67 | |||
68 | if ($admin->getModelManager()->hasMetadata($admin->getClass())) { |
||
69 | [$metadata, $lastPropertyName, $parentAssociationMappings] = $admin->getModelManager()->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName()); |
||
70 | $fieldDescription->setParentAssociationMappings($parentAssociationMappings); |
||
71 | |||
72 | // set the default field mapping |
||
73 | if (isset($metadata->fieldMappings[$lastPropertyName])) { |
||
74 | $fieldDescription->setFieldMapping($metadata->fieldMappings[$lastPropertyName]); |
||
75 | if (false !== $fieldDescription->getOption('sortable')) { |
||
76 | $fieldDescription->setOption('sortable', $fieldDescription->getOption('sortable', true)); |
||
77 | $fieldDescription->setOption('sort_parent_association_mappings', $fieldDescription->getOption('sort_parent_association_mappings', $fieldDescription->getParentAssociationMappings())); |
||
78 | $fieldDescription->setOption('sort_field_mapping', $fieldDescription->getOption('sort_field_mapping', $fieldDescription->getFieldMapping())); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | // set the default association mapping |
||
83 | if (isset($metadata->associationMappings[$lastPropertyName])) { |
||
84 | $fieldDescription->setAssociationMapping($metadata->associationMappings[$lastPropertyName]); |
||
85 | } |
||
86 | |||
87 | $fieldDescription->setOption('_sort_order', $fieldDescription->getOption('_sort_order', 'ASC')); |
||
88 | } |
||
89 | |||
90 | if (!$fieldDescription->getType()) { |
||
91 | throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), \get_class($admin))); |
||
92 | } |
||
93 | |||
94 | $fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName())); |
||
95 | $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName())); |
||
96 | |||
97 | if (!$fieldDescription->getTemplate()) { |
||
98 | if ('id' === $fieldDescription->getType()) { |
||
99 | $fieldDescription->setType('string'); |
||
100 | } |
||
101 | |||
102 | if ('int' === $fieldDescription->getType()) { |
||
103 | $fieldDescription->setType('integer'); |
||
104 | } |
||
105 | |||
106 | $template = $this->getTemplate($fieldDescription->getType()); |
||
107 | |||
108 | if (null === $template) { |
||
109 | if (ClassMetadata::ONE === $fieldDescription->getMappingType()) { |
||
110 | $template = '@SonataAdmin/CRUD/Association/list_many_to_one.html.twig'; |
||
111 | } elseif (ClassMetadata::MANY === $fieldDescription->getMappingType()) { |
||
112 | $template = '@SonataAdmin/CRUD/Association/list_many_to_many.html.twig'; |
||
113 | } |
||
114 | } |
||
115 | |||
116 | $fieldDescription->setTemplate($template); |
||
117 | } |
||
118 | |||
119 | if (\in_array($fieldDescription->getMappingType(), [ClassMetadata::ONE, ClassMetadata::MANY], true)) { |
||
120 | $admin->attachAdminClass($fieldDescription); |
||
121 | } |
||
122 | } |
||
123 | |||
171 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.