Conditions | 10 |
Paths | 48 |
Total Lines | 54 |
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 |
||
53 | public function listAction(?Request $request = null) |
||
54 | { |
||
55 | $this->admin->checkAccess('list'); |
||
56 | |||
57 | if ($listMode = $request->get('_list_mode', 'mosaic')) { |
||
58 | $this->admin->setListMode($listMode); |
||
59 | } |
||
60 | |||
61 | $datagrid = $this->admin->getDatagrid(); |
||
62 | |||
63 | $filters = $request->get('filter'); |
||
64 | |||
65 | // set the default context |
||
66 | if (!$filters || !\array_key_exists('context', $filters)) { |
||
67 | $context = $this->admin->getPersistentParameter('context', $this->get('sonata.media.pool')->getDefaultContext()); |
||
68 | } else { |
||
69 | $context = $filters['context']['value']; |
||
70 | } |
||
71 | |||
72 | $datagrid->setValue('context', null, $context); |
||
73 | |||
74 | $rootCategory = null; |
||
75 | if ($this->has('sonata.media.manager.category')) { |
||
76 | $rootCategory = $this->get('sonata.media.manager.category')->getRootCategory($context); |
||
77 | } |
||
78 | |||
79 | if (null !== $rootCategory && !$filters) { |
||
80 | $datagrid->setValue('category', null, $rootCategory->getId()); |
||
81 | } |
||
82 | if ($this->has('sonata.media.manager.category') && $request->get('category')) { |
||
83 | $category = $this->get('sonata.media.manager.category')->findOneBy([ |
||
84 | 'id' => (int) $request->get('category'), |
||
85 | 'context' => $context, |
||
86 | ]); |
||
87 | |||
88 | if (!empty($category)) { |
||
89 | $datagrid->setValue('category', null, $category->getId()); |
||
90 | } else { |
||
91 | $datagrid->setValue('category', null, $rootCategory->getId()); |
||
92 | } |
||
93 | } |
||
94 | |||
95 | $formView = $datagrid->getForm()->createView(); |
||
96 | |||
97 | $this->setFormTheme($formView, $this->admin->getFilterTheme()); |
||
98 | |||
99 | return $this->render($this->admin->getTemplate('list'), [ |
||
100 | 'action' => 'list', |
||
101 | 'form' => $formView, |
||
102 | 'datagrid' => $datagrid, |
||
103 | 'root_category' => $rootCategory, |
||
104 | 'csrf_token' => $this->getCsrfToken('sonata.batch'), |
||
105 | ]); |
||
106 | } |
||
107 | |||
118 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.