| Conditions | 10 |
| Paths | 21 |
| Total Lines | 75 |
| Code Lines | 51 |
| 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 |
||
| 112 | private function formatSelect($baseSelect) |
||
| 113 | { |
||
| 114 | $relatedTables = $this->tdbmService->_getRelatedTablesByInheritance($this->mainTable); |
||
| 115 | $tableGroup = $this->getTableGroupName($relatedTables); |
||
| 116 | |||
| 117 | $connection = $this->tdbmService->getConnection(); |
||
| 118 | $formattedSelect = []; |
||
| 119 | $columnDescritors = []; |
||
| 120 | $fetchedTables = []; |
||
| 121 | |||
| 122 | foreach ($baseSelect as $entry) { |
||
| 123 | if ($entry['expr_type'] !== 'colref') { |
||
| 124 | $formattedSelect[] = $entry; |
||
| 125 | continue; |
||
| 126 | } |
||
| 127 | |||
| 128 | $noQuotes = $entry['no_quotes']; |
||
| 129 | if ($noQuotes['delim'] != '.' || count($noQuotes['parts']) !== 2) { |
||
| 130 | $formattedSelect[] = $entry; |
||
| 131 | continue; |
||
| 132 | } |
||
| 133 | |||
| 134 | $tableName = $noQuotes['parts'][0]; |
||
| 135 | if (!in_array($tableName, $relatedTables)) { |
||
| 136 | $formattedSelect[] = $entry; |
||
| 137 | continue; |
||
| 138 | } |
||
| 139 | |||
| 140 | $columnName = $noQuotes['parts'][1]; |
||
| 141 | if ($columnName !== '*') { |
||
| 142 | $formattedSelect[] = $entry; |
||
| 143 | continue; |
||
| 144 | } |
||
| 145 | |||
| 146 | $table = $this->schema->getTable($tableName); |
||
| 147 | foreach ($table->getColumns() as $column) { |
||
| 148 | $columnName = $column->getName(); |
||
| 149 | $alias = "{$tableName}____{$columnName}"; |
||
| 150 | $formattedSelect[] = [ |
||
| 151 | 'expr_type' => 'colref', |
||
| 152 | 'base_expr' => $connection->quoteIdentifier($tableName).'.'.$connection->quoteIdentifier($columnName), |
||
| 153 | 'no_quotes' => [ |
||
| 154 | 'delim' => '.', |
||
| 155 | 'parts' => [ |
||
| 156 | $tableName, |
||
| 157 | $columnName |
||
| 158 | ] |
||
| 159 | ], |
||
| 160 | 'alias' => [ |
||
| 161 | 'as' => true, |
||
| 162 | 'name' => $alias, |
||
| 163 | ] |
||
| 164 | ]; |
||
| 165 | |||
| 166 | $columnDescritors[$alias] = [ |
||
| 167 | 'as' => $alias, |
||
| 168 | 'table' => $tableName, |
||
| 169 | 'column' => $columnName, |
||
| 170 | 'type' => $column->getType(), |
||
| 171 | 'tableGroup' => $tableGroup, |
||
| 172 | ]; |
||
| 173 | } |
||
| 174 | $fetchedTables[] = $tableName; |
||
| 175 | } |
||
| 176 | |||
| 177 | $missingTables = array_diff($relatedTables, $fetchedTables); |
||
| 178 | if (!empty($missingTables)) { |
||
| 179 | throw new TDBMException('Missing tables '.implode(', ', $missingTables).' in SELECT statement'); |
||
| 180 | } |
||
| 181 | |||
| 182 | for ($i = 0; $i < count($formattedSelect) - 1; $i++) { |
||
| 183 | $formattedSelect[$i]['delim'] = ','; |
||
| 184 | } |
||
| 185 | return [$formattedSelect, $columnDescritors]; |
||
| 186 | } |
||
| 187 | |||
| 268 |