| Conditions | 16 |
| Paths | 15 |
| Total Lines | 37 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 22 |
| CRAP Score | 18.5194 |
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 |
||
| 24 | 2 | public function with($team, $result = null) |
|
| 25 | { |
||
| 26 | 2 | if (!$team || !$team->isValid()) { |
|
| 27 | 1 | return $this; |
|
| 28 | } |
||
| 29 | |||
| 30 | switch ($result) { |
||
| 31 | 2 | case "wins": |
|
| 32 | 1 | case "win": |
|
| 33 | 1 | case "victory": |
|
| 34 | 1 | case "victories": |
|
| 35 | $query = "(team_a = ? AND team_a_points > team_b_points) OR (team_b = ? AND team_b_points > team_a_points)"; |
||
| 36 | break; |
||
| 37 | 1 | case "loss": |
|
| 38 | 1 | case "lose": |
|
| 39 | 1 | case "losses": |
|
| 40 | 1 | case "defeat": |
|
| 41 | 1 | case "defeats": |
|
| 42 | $query = "(team_a = ? AND team_b_points > team_a_points) OR (team_b = ? AND team_a_points > team_b_points)"; |
||
| 43 | break; |
||
| 44 | 1 | case "draw": |
|
| 45 | 1 | case "draws": |
|
| 46 | 1 | case "tie": |
|
| 47 | 2 | case "ties": |
|
| 48 | $query = "(team_a = ? OR team_b = ?) AND team_a_points = team_b_points"; |
||
| 49 | break; |
||
| 50 | default: |
||
| 51 | 2 | $query = "team_a = ? OR team_b = ?"; |
|
| 52 | } |
||
| 53 | |||
| 54 | 2 | $this->conditions[] = $query; |
|
| 55 | 2 | $this->parameters[] = $team->getId(); |
|
| 56 | 2 | $this->parameters[] = $team->getId(); |
|
| 57 | 2 | $this->types .= 'ii'; |
|
| 58 | |||
| 59 | 2 | return $this; |
|
| 60 | } |
||
| 61 | } |
||
| 62 |