Conditions | 12 |
Paths | 175 |
Total Lines | 52 |
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 |
||
58 | public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription): void |
||
59 | { |
||
60 | $fieldDescription->setAdmin($admin); |
||
61 | |||
62 | if ($admin->getModelManager()->hasMetadata($admin->getClass())) { |
||
63 | [$metadata, $lastPropertyName, $parentAssociationMappings] = $admin->getModelManager()->getParentMetadataForProperty($admin->getClass(), $fieldDescription->getName()); |
||
64 | $fieldDescription->setParentAssociationMappings($parentAssociationMappings); |
||
65 | |||
66 | // set the default field mapping |
||
67 | if (isset($metadata->fieldMappings[$lastPropertyName])) { |
||
68 | $fieldDescription->setFieldMapping($metadata->fieldMappings[$lastPropertyName]); |
||
69 | } |
||
70 | |||
71 | // set the default association mapping |
||
72 | if (isset($metadata->associationMappings[$lastPropertyName])) { |
||
73 | $fieldDescription->setAssociationMapping($metadata->associationMappings[$lastPropertyName]); |
||
74 | } |
||
75 | } |
||
76 | |||
77 | if (!$fieldDescription->getType()) { |
||
78 | throw new \RuntimeException(sprintf('Please define a type for field `%s` in `%s`', $fieldDescription->getName(), \get_class($admin))); |
||
79 | } |
||
80 | |||
81 | $fieldDescription->setOption('code', $fieldDescription->getOption('code', $fieldDescription->getName())); |
||
82 | $fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName())); |
||
83 | |||
84 | if (!$fieldDescription->getTemplate()) { |
||
85 | if ('id' === $fieldDescription->getType()) { |
||
86 | $fieldDescription->setType('string'); |
||
87 | } |
||
88 | |||
89 | if ('int' === $fieldDescription->getType()) { |
||
90 | $fieldDescription->setType('integer'); |
||
91 | } |
||
92 | |||
93 | $template = $this->getTemplate($fieldDescription->getType()); |
||
94 | |||
95 | if (null === $template) { |
||
96 | if (ClassMetadata::ONE === $fieldDescription->getMappingType()) { |
||
97 | $template = '@SonataAdmin/CRUD/Association/show_many_to_one.html.twig'; |
||
98 | } elseif (ClassMetadata::MANY === $fieldDescription->getMappingType()) { |
||
99 | $template = '@SonataAdmin/CRUD/Association/show_many_to_many.html.twig'; |
||
100 | } |
||
101 | } |
||
102 | |||
103 | $fieldDescription->setTemplate($template); |
||
104 | } |
||
105 | |||
106 | if (\in_array($fieldDescription->getMappingType(), [ClassMetadata::ONE, ClassMetadata::MANY], true)) { |
||
107 | $admin->attachAdminClass($fieldDescription); |
||
108 | } |
||
109 | } |
||
110 | |||
123 |
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.