Conditions | 7 |
Paths | 19 |
Total Lines | 94 |
Code Lines | 68 |
Lines | 24 |
Ratio | 25.53 % |
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 | |||
58 | $grids = []; |
||
59 | foreach ($config['grids'] as $gridName => $gridConfig) { |
||
60 | $gridConfig = $this->resolveConfig([ |
||
61 | 'name' => null, |
||
62 | 'query' => null, |
||
63 | 'columns' => [], |
||
64 | 'filters' => [], |
||
65 | 'actions' => [], |
||
66 | 'page_size' => 50, |
||
67 | ], $gridConfig); |
||
68 | |||
69 | $columns = []; |
||
70 | View Code Duplication | foreach ($gridConfig['columns'] as $columnName => $columnConfig) { |
|
71 | $columnConfig = $this->resolveConfig([ |
||
72 | 'type' => null, |
||
73 | 'options' => [], |
||
74 | ], $columnConfig); |
||
75 | |||
76 | $columns[$columnName] = new ColumnMetadata( |
||
77 | $columnName, |
||
78 | $columnConfig['type'], |
||
79 | $columnConfig['options'] |
||
80 | ); |
||
81 | } |
||
82 | |||
83 | $filters = []; |
||
84 | foreach ($gridConfig['filters'] as $filterName => $filterConfig) { |
||
85 | $filterConfig = $this->resolveConfig([ |
||
86 | 'type' => null, |
||
87 | 'field' => null, |
||
88 | 'options' => [], |
||
89 | ], $filterConfig); |
||
90 | |||
91 | $filters[$filterName] = new FilterMetadata( |
||
92 | $filterName, |
||
93 | $filterConfig['type'], |
||
94 | $filterConfig['field'], |
||
95 | $filterConfig['options'] |
||
96 | ); |
||
97 | } |
||
98 | |||
99 | $actions = []; |
||
100 | View Code Duplication | foreach ($gridConfig['actions'] as $actionName => $actionConfig) { |
|
101 | $actionConfig = $this->resolveConfig([ |
||
102 | 'type' => null, |
||
103 | 'options' => [], |
||
104 | ], $actionConfig); |
||
105 | |||
106 | $actions[$actionName] = new ActionMetadata( |
||
107 | $actionName, |
||
108 | $actionConfig['type'], |
||
109 | $actionConfig['options'] |
||
110 | ); |
||
111 | } |
||
112 | |||
113 | $grids[$gridName] = new GridMetadata( |
||
114 | $gridName, |
||
115 | $columns, |
||
116 | $filters, |
||
117 | $actions, |
||
118 | $gridConfig['page_size'], |
||
119 | $gridConfig['query'] |
||
120 | ); |
||
121 | } |
||
122 | |||
123 | $classMetadata = new ClassMetadata($class->getName(), $grids, $queries); |
||
124 | |||
125 | return $classMetadata; |
||
126 | } |
||
127 | |||
148 |