Conditions | 6 |
Paths | 8 |
Total Lines | 57 |
Code Lines | 35 |
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 |
||
100 | protected function resolve(): array |
||
101 | { |
||
102 | $data = $this->generateJsonData(); |
||
103 | |||
104 | // On force les valeurs par d�faut. |
||
105 | $resolverTable = new OptionsResolver(); |
||
106 | $resolverTable->setRequired(['columns']); |
||
107 | $resolverTable->setDefaults( |
||
108 | [ |
||
109 | 'columns' => [], |
||
110 | 'indexes' => [], |
||
111 | 'fulltexts' => [], |
||
112 | 'primary' => null, |
||
113 | 'uniques' => [], |
||
114 | 'collate' => null, |
||
115 | ] |
||
116 | ); |
||
117 | |||
118 | $resolverColumns = new OptionsResolver(); |
||
119 | $resolverColumns->setRequired(['type']); |
||
120 | $resolverColumns->setDefaults( |
||
121 | [ |
||
122 | 'length' => null, |
||
123 | 'nullable' => false, |
||
124 | 'defaultValue' => null, |
||
125 | 'extra' => null, |
||
126 | 'collate' => null, |
||
127 | ] |
||
128 | ); |
||
129 | |||
130 | $resolverIndex = new OptionsResolver(); |
||
131 | $resolverIndex->setDefaults( |
||
132 | [ |
||
133 | 'name' => '', |
||
134 | 'columns' => [], |
||
135 | ] |
||
136 | ); |
||
137 | $export = []; |
||
138 | $data = $data['tables']; |
||
139 | if(empty($data['tables'])){ |
||
140 | return []; |
||
141 | } |
||
142 | |||
143 | foreach ($data as $nomTable => $table) { |
||
144 | $dataTable = $resolverTable->resolve($table); |
||
145 | foreach ((array)$dataTable['columns'] as $columnName => $column) { |
||
146 | $dataTable['columns'][$columnName] = $resolverColumns->resolve($column); |
||
147 | } |
||
148 | foreach (['indexes', 'uniques'] as $indexKey) { |
||
149 | foreach ((array)$dataTable[$indexKey] as $keyIndex => $index) { |
||
150 | $dataTable[$indexKey][$keyIndex] = $resolverIndex->resolve($index); |
||
151 | } |
||
152 | } |
||
153 | $export[$nomTable] = $dataTable; |
||
154 | } |
||
155 | |||
156 | return $export; |
||
157 | } |
||
171 |