| Conditions | 11 |
| Paths | 41 |
| Total Lines | 33 |
| Code Lines | 23 |
| 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 |
||
| 19 | private function defineColumns(IRelation $source, $colDef) |
||
| 20 | { |
||
| 21 | $srcCols = $source->getColumns(); |
||
| 22 | |||
| 23 | $columns = []; |
||
| 24 | $this->projectionList = []; |
||
| 25 | |||
| 26 | foreach ($colDef as $key => $value) { |
||
| 27 | $nameSpecified = (filter_var($key, FILTER_VALIDATE_INT) === false || is_object($value)); |
||
| 28 | $colName = ($nameSpecified ? $key : (isset($srcCols[$value]) ? $srcCols[$value]->getName() : $value)); |
||
| 29 | |||
| 30 | if (filter_var($value, FILTER_VALIDATE_INT) !== false) { // column offset |
||
| 31 | if (!isset($srcCols[$value])) { |
||
| 32 | throw new UndefinedColumnException($value); |
||
| 33 | } |
||
| 34 | $columns[] = new Column($this, count($this->projectionList), $colName, $srcCols[$value]->getType()); |
||
| 35 | $this->projectionList[] = (int)$value; |
||
| 36 | } elseif (is_string($value)) { // column name |
||
| 37 | $matched = $this->recognizeColsByName($srcCols, $nameSpecified, $key, $value); |
||
| 38 | foreach ($matched as $i => $cn) { |
||
| 39 | $columns[] = new Column($this, count($this->projectionList), $cn, $srcCols[$i]->getType()); |
||
| 40 | $this->projectionList[] = $i; |
||
| 41 | } |
||
| 42 | } elseif ($value instanceof ITupleEvaluator || $value instanceof \Closure) { |
||
| 43 | $columns[] = new Column($this, $value, $colName, null); |
||
| 44 | $this->projectionList[] = $value; |
||
| 45 | } else { |
||
| 46 | throw new \InvalidArgumentException("Invalid specification of the projection item '$key'"); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | return $columns; |
||
| 51 | } |
||
| 52 | |||
| 123 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.