| Conditions | 10 |
| Paths | 14 |
| Total Lines | 56 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 3 | Features | 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 |
||
| 72 | public function prefixedColumns(array $columns) |
||
| 73 | { |
||
| 74 | $pf = $this->adapter->getPlatform(); |
||
| 75 | $identifierSeparator = $pf->getIdentifierSeparator(); |
||
| 76 | $names = array(); |
||
| 77 | $cols = array(); |
||
| 78 | foreach ($columns as $alias => $column) { |
||
| 79 | if (is_string($column)) { |
||
| 80 | if (strpos($column, self::SQL_STAR) !== false) { |
||
| 81 | $msg = __METHOD__ . " Invalid argument, prefixedColumn() does not accept sql * column specification"; |
||
| 82 | throw new Exception\InvalidArgumentException($msg); |
||
| 83 | } |
||
| 84 | $parts = explode($identifierSeparator, $column); |
||
| 85 | if (count($parts) > 1) { |
||
| 86 | $quotedParts = array(); |
||
| 87 | foreach ($parts as $part) { |
||
| 88 | $quotedParts[] = $pf->quoteIdentifier($part); |
||
| 89 | } |
||
| 90 | // to remove PHPAnalyzer warnings |
||
| 91 | //var_dump($quotedParts[count($quotedParts)-1]); |
||
| 92 | //die(); |
||
| 93 | $last_part = $parts[count($parts)-1]; |
||
| 94 | |||
| 95 | if (!is_string($alias)) { |
||
| 96 | $alias = $last_part; |
||
| 97 | } |
||
| 98 | |||
| 99 | if (in_array($alias, $names)) { |
||
| 100 | $msg = __METHOD__ . ": Invalid argument, multiple columns have the same alias ($alias)"; |
||
| 101 | throw new Exception\InvalidArgumentException($msg); |
||
| 102 | } |
||
| 103 | $names[] = $alias; |
||
| 104 | |||
| 105 | $cols[$alias] = new Expression(join($identifierSeparator, $quotedParts)); |
||
| 106 | } else { |
||
| 107 | if (in_array($alias, $names)) { |
||
| 108 | $msg = __METHOD__ . ": Invalid argument, multiple columns have the same alias ($alias)"; |
||
| 109 | throw new Exception\InvalidArgumentException($msg); |
||
| 110 | } |
||
| 111 | |||
| 112 | $cols[$alias] = $column; |
||
| 113 | $names[] = $alias; |
||
| 114 | } |
||
| 115 | } else { |
||
| 116 | if (in_array($alias, $names)) { |
||
| 117 | $msg = __METHOD__ . ": Invalid argument, multiple columns have the same alias ($alias)"; |
||
| 118 | throw new Exception\InvalidArgumentException($msg); |
||
| 119 | } |
||
| 120 | |||
| 121 | $cols[$alias] = $column; |
||
| 122 | $names[] = $alias; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | $this->columns($cols); |
||
| 126 | return $this; |
||
| 127 | } |
||
| 128 | |||
| 194 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.