Conditions | 8 |
Paths | 20 |
Total Lines | 51 |
Code Lines | 29 |
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 |
||
29 | public function getAction() |
||
30 | { |
||
31 | /** @var \ZF\ContentNegotiation\Request $request */ |
||
32 | $request = $this->getRequest(); |
||
|
|||
33 | $gridName = $request->getQuery('grid'); |
||
34 | $limit = (int)$request->getQuery('limit', 25); |
||
35 | $offset = (int)$request->getQuery('offset', 0); |
||
36 | $orderField = $request->getQuery('sidx', null); |
||
37 | $orderType = $request->getQuery('sorder', null); |
||
38 | $collapsedRows = is_array($request->getPost('collapsedRows')) ? $request->getPost('collapsedRows') : []; |
||
39 | /** |
||
40 | * $conditions => [ |
||
41 | * [ |
||
42 | * 'key' => $name, |
||
43 | * 'value' => $value |
||
44 | * ] |
||
45 | * ]; |
||
46 | */ |
||
47 | $conditions = $request->getQuery('conditions', []); |
||
48 | if (!$gridName) { |
||
49 | throw new Exception\InvalidGridNameException('Не задано имя таблицы для получения данных'); |
||
50 | } |
||
51 | /** @var GridInterface $grid */ |
||
52 | $grid = $this->getServiceLocator()->get('GridManager')->get('grids.' . $gridName); |
||
53 | |||
54 | $adapter = $grid->getAdapter(); |
||
55 | if ($adapter instanceof DoctrineDBAL) { |
||
56 | $adapter->setLimit($limit); |
||
57 | $adapter->setOffset($offset); |
||
58 | if ($orderField && $orderType) { |
||
59 | $adapter->setOrder([ |
||
60 | [ |
||
61 | 'field' => $orderField, |
||
62 | 'order' => $orderType |
||
63 | ] |
||
64 | ]); |
||
65 | } |
||
66 | } |
||
67 | |||
68 | $conditionsObj = new Conditions(); |
||
69 | foreach ($conditions as $cond) { |
||
70 | if (is_array($cond)) { |
||
71 | $condition = $this->getCondition($cond); |
||
72 | $conditionsObj[] = $condition; |
||
73 | } |
||
74 | } |
||
75 | $grid->setConditions($conditionsObj); |
||
76 | $result = new ViewModel(['grid' => $grid, 'collapsedRows' => $collapsedRows]); |
||
77 | $result->setTerminal(true); |
||
78 | return $result; |
||
79 | } |
||
80 | |||
101 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.