| Conditions | 11 |
| Paths | 9 |
| Total Lines | 38 |
| Code Lines | 26 |
| 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 |
||
| 8 | public static function init($data, $required = []) |
||
| 9 | { |
||
| 10 | parent::init($data, ['draw', 'columns', 'order', 'start', 'length', 'search']); |
||
| 11 | |||
| 12 | foreach (['columns', 'order', 'search'] as $item) { |
||
| 13 | if (!is_array($data[$item])) { |
||
| 14 | throw new \InvalidArgumentException(sprintf('Invalid parameter: %s', $item)); |
||
| 15 | } |
||
| 16 | } |
||
| 17 | |||
| 18 | $columns = new Items(new ColumnArrayObject()); |
||
| 19 | foreach ($data['columns'] as $item) { |
||
| 20 | $columnItem = new Column( |
||
| 21 | isset($item['data']) ? $item['data'] : null, |
||
| 22 | isset($item['name']) ? $item['name'] : null, |
||
| 23 | isset($item['searchable']) ? $item['searchable'] : null, |
||
| 24 | isset($item['orderable']) ? $item['orderable'] : null, |
||
| 25 | SearchHelper::init($item['search']) |
||
| 26 | ); |
||
| 27 | $columns->set(null, $columnItem); |
||
| 28 | } |
||
| 29 | |||
| 30 | $order = new Items(new OrderArrayObject()); |
||
| 31 | foreach ($data['order'] as $item) { |
||
| 32 | $orderItem = new Order( |
||
| 33 | isset($item['column']) ? $item['column'] : null, |
||
| 34 | isset($item['dir']) ? $item['dir'] : null |
||
| 35 | ); |
||
| 36 | $order->set(null, $orderItem); |
||
| 37 | } |
||
| 38 | |||
| 39 | return new Request( |
||
| 40 | $data['draw'], |
||
| 41 | $columns, |
||
| 42 | $order, |
||
| 43 | $data['start'], |
||
| 44 | $data['length'], |
||
| 45 | SearchHelper::init($data['search']) |
||
| 46 | ); |
||
| 49 |