Conditions | 11 |
Paths | 13 |
Total Lines | 34 |
Code Lines | 19 |
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 |
||
94 | public function buildView(FormView $view, FormInterface $form, array $options) |
||
95 | { |
||
96 | if (isset($view->vars['sonata_admin']['admin'])) { |
||
97 | $genericAdmin = $view->vars['sonata_admin']['admin']; |
||
98 | |||
99 | $parentAdmin = $genericAdmin->getParent(); |
||
100 | |||
101 | $subject = $form->getParent()->getData(); |
||
102 | |||
103 | $view->vars['type'] = null; |
||
104 | $view->vars['edit_url'] = null; |
||
105 | |||
106 | |||
107 | try { |
||
108 | if ($subject->getRegion() !== null && $typeAdmin = $this->sonata->getAdminByClass(get_class($subject))) { |
||
109 | $view->vars['type']= Str::humanize(Str::classname($subject->getConvertToType())); |
||
110 | $childAdmin = $this->sonata->getAdminByAdminCode($parentAdmin->getCode() . '|' . $typeAdmin->getCode()); |
||
111 | $childAdmin->setRequest($genericAdmin->getRequest()); |
||
112 | |||
113 | if ($subject && $subject->getPage() && $subject->getPage()->getId()) { |
||
114 | try { |
||
115 | $view->vars['edit_url'] = $childAdmin->generateObjectUrl('edit', $subject); |
||
116 | } catch (InvalidParameterException $e) { |
||
117 | //2.2 edit url not needed when generating other admins (this is done in the POST of the sonata_collection_type) |
||
118 | } catch (MissingMandatoryParametersException $e) { |
||
119 | //>= 2.3 |
||
120 | } catch (\Exception $e) { |
||
121 | } |
||
122 | } |
||
123 | } |
||
124 | } catch (\RuntimeException $e) { |
||
125 | } |
||
126 | } |
||
127 | } |
||
128 | |||
140 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: