| Conditions | 13 |
| Paths | 84 |
| Total Lines | 42 |
| Code Lines | 28 |
| 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 |
||
| 60 | private function recognizeColsByName($srcCols, bool $nameSpecified, $key, string $value) |
||
| 61 | { |
||
| 62 | if ($value[0] == '/') { // PCRE macro |
||
| 63 | $pcre = $value; |
||
| 64 | $matchAll = true; |
||
| 65 | $repl = ($nameSpecified ? $key : null); |
||
| 66 | } else { |
||
| 67 | $pcre = self::simpleMacroPatternToPcre($value, $starCnt); |
||
| 68 | $matchAll = ($starCnt > 0); |
||
| 69 | $repl = ($nameSpecified ? self::simpleMacroReplacementToPcre($key) : null); |
||
| 70 | } |
||
| 71 | |||
| 72 | if ($repl === null) { |
||
| 73 | $cns = []; |
||
| 74 | foreach ($srcCols as $i => $c) { |
||
| 75 | $name = $c->getName(); |
||
| 76 | if ($name !== null) { |
||
| 77 | $cns[$i] = $name; |
||
| 78 | } |
||
| 79 | } |
||
| 80 | $matched = preg_grep($pcre, $cns); |
||
| 81 | } else { |
||
| 82 | $matched = []; |
||
| 83 | foreach ($srcCols as $i => $c) { |
||
| 84 | if ($c->getName() !== null) { |
||
| 85 | $newName = preg_replace($pcre, $repl, $c->getName(), 1, $cnt); |
||
| 86 | if ($cnt > 0) { |
||
| 87 | $matched[$i] = $newName; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | if (!$matched) { |
||
|
|
|||
| 94 | throw new UndefinedColumnException($value); |
||
| 95 | } |
||
| 96 | if (!$matchAll && count($matched) > 1) { |
||
| 97 | throw new AmbiguousException($value); |
||
| 98 | } |
||
| 99 | |||
| 100 | return $matched; |
||
| 101 | } |
||
| 102 | |||
| 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.