Conditions | 7 |
Paths | 19 |
Total Lines | 92 |
Code Lines | 67 |
Lines | 24 |
Ratio | 26.09 % |
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 |
||
33 | public function loadMetadataForClass(\ReflectionClass $class) |
||
34 | { |
||
35 | if (!isset($this->config[$class->getName()])) { |
||
|
|||
36 | return; |
||
37 | } |
||
38 | |||
39 | $config = $this->resolveConfig([ |
||
40 | 'grids' => [], |
||
41 | 'queries' => [], |
||
42 | ], $this->config[$class->getName()]); |
||
43 | |||
44 | $queries = []; |
||
45 | foreach ($config['queries'] as $queryName => $queryConfig) { |
||
46 | $queryConfig = $this->resolveConfig([ |
||
47 | 'name' => null, |
||
48 | 'selects' => [], |
||
49 | 'joins' => [], |
||
50 | 'criteria' => [], |
||
51 | ], $queryConfig); |
||
52 | $queries[$queryName] = new QueryMetadata( |
||
53 | $queryName, $queryConfig['selects'], $queryConfig['joins'], $queryConfig['criteria'] |
||
54 | ); |
||
55 | } |
||
56 | |||
57 | foreach ($config['grids'] as $gridName => $gridConfig) { |
||
58 | $gridConfig = $this->resolveConfig([ |
||
59 | 'name' => null, |
||
60 | 'query' => null, |
||
61 | 'columns' => [], |
||
62 | 'filters' => [], |
||
63 | 'actions' => [], |
||
64 | 'page_size' => 50, |
||
65 | ], $gridConfig); |
||
66 | |||
67 | $columns = []; |
||
68 | View Code Duplication | foreach ($gridConfig['columns'] as $columnName => $columnConfig) { |
|
69 | $columnConfig = $this->resolveConfig([ |
||
70 | 'type' => null, |
||
71 | 'options' => [], |
||
72 | ], $columnConfig); |
||
73 | |||
74 | $columns[$columnName] = new ColumnMetadata( |
||
75 | $columnName, |
||
76 | $columnConfig['type'], |
||
77 | $columnConfig['options'] |
||
78 | ); |
||
79 | } |
||
80 | |||
81 | $filters = []; |
||
82 | foreach ($gridConfig['filters'] as $filterName => $filterConfig) { |
||
83 | $filterConfig = $this->resolveConfig([ |
||
84 | 'type' => null, |
||
85 | 'field' => null, |
||
86 | 'options' => [], |
||
87 | ], $filterConfig); |
||
88 | |||
89 | $filters[$filterName] = new FilterMetadata( |
||
90 | $filterName, |
||
91 | $filterConfig['type'], |
||
92 | $filterConfig['field'], |
||
93 | $filterConfig['options'] |
||
94 | ); |
||
95 | } |
||
96 | |||
97 | $actions = []; |
||
98 | View Code Duplication | foreach ($gridConfig['actions'] as $actionName => $actionConfig) { |
|
99 | $actionConfig = $this->resolveConfig([ |
||
100 | 'type' => null, |
||
101 | 'options' => [], |
||
102 | ], $actionConfig); |
||
103 | |||
104 | $actions[$actionName] = new ActionMetadata( |
||
105 | $actionName, |
||
106 | $actionConfig['type'], |
||
107 | $actionConfig['options'] |
||
108 | ); |
||
109 | } |
||
110 | |||
111 | $grids[$gridName] = new GridMetadata( |
||
112 | $gridName, |
||
113 | $columns, |
||
114 | $filters, |
||
115 | $actions, |
||
116 | $gridConfig['page_size'], |
||
117 | $gridConfig['query'] |
||
118 | ); |
||
119 | } |
||
120 | |||
121 | $classMetadata = new ClassMetadata($class->getName(), $grids, $queries); |
||
122 | |||
123 | return $classMetadata; |
||
124 | } |
||
125 | |||
146 |