| Conditions | 12 |
| Paths | 16 |
| Total Lines | 34 |
| Code Lines | 25 |
| 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 |
||
| 15 | protected function buildTableName($alias, $name) { |
||
| 16 | if(is_object($name) && !($name instanceof VirtualTable) && method_exists($name, '__toString')) { |
||
| 17 | $name = (string) $name; |
||
| 18 | $lines = explode("\n", $name); |
||
| 19 | foreach($lines as &$line) { |
||
| 20 | $line = "\t{$line}"; |
||
| 21 | } |
||
| 22 | $name = join("\n", $lines); |
||
| 23 | $name = '(' . trim(rtrim(trim($name), ';')) . ')'; |
||
| 24 | } |
||
| 25 | if(is_array($name)) { |
||
| 26 | $parts = []; |
||
| 27 | foreach($name as $index => $bucket) { |
||
| 28 | if(ctype_digit((string) $index) && is_scalar($bucket)) { |
||
| 29 | $parts[] = "SELECT {$this->db()->quote($bucket)} AS {$this->db()->quoteField('value')}"; |
||
| 30 | } else { |
||
| 31 | $values = []; |
||
| 32 | foreach($bucket as $field => $value) { |
||
| 33 | $values[] = sprintf('%s AS %s', $this->db()->quote($value), $this->db()->quoteField($field)); |
||
| 34 | } |
||
| 35 | $parts[] = sprintf("SELECT %s", join(', ', $values)); |
||
| 36 | } |
||
| 37 | } |
||
| 38 | $name = '(' . join("\n\tUNION\n\t", $parts) . ')'; |
||
| 39 | } |
||
| 40 | if($this->db()->getVirtualTables()->has($name)) { |
||
| 41 | $select = (string) $this->db()->getVirtualTables()->get($name); |
||
| 42 | $name = sprintf('(%s)', join("\n\t", explode("\n", trim($select)))); |
||
| 43 | } |
||
| 44 | $name = $this->aliasReplacer()->replace($name); |
||
|
|
|||
| 45 | if($alias !== null) { |
||
| 46 | return sprintf("%s %s", $name, $alias); |
||
| 47 | } |
||
| 48 | return $name; |
||
| 49 | } |
||
| 56 |