| Conditions | 18 |
| Paths | 30 |
| Total Lines | 46 |
| Code Lines | 37 |
| 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 |
||
| 24 | public function with($participant, $result = null) |
||
| 25 | { |
||
| 26 | if (!$participant || !$participant->isValid()) { |
||
| 27 | return $this; |
||
| 28 | } |
||
| 29 | |||
| 30 | if ($participant instanceof Team) { |
||
| 31 | $team_a_query = "team_a = ?"; |
||
| 32 | $team_b_query = "team_b = ?"; |
||
| 33 | } elseif ($participant instanceof Player) { |
||
| 34 | $team_a_query = "FIND_IN_SET(?, team_a_players)"; |
||
| 35 | $team_b_query = "FIND_IN_SET(?, team_b_players)"; |
||
| 36 | } else { |
||
| 37 | throw new InvalidArgumentException("Invalid model provided"); |
||
| 38 | } |
||
| 39 | |||
| 40 | switch ($result) { |
||
| 41 | case "wins": |
||
| 42 | case "win": |
||
| 43 | case "victory": |
||
| 44 | case "victories": |
||
| 45 | $query = "($team_a_query AND team_a_points > team_b_points) OR ($team_b_query AND team_b_points > team_a_points)"; |
||
| 46 | break; |
||
| 47 | case "loss": |
||
| 48 | case "lose": |
||
| 49 | case "losses": |
||
| 50 | case "defeat": |
||
| 51 | case "defeats": |
||
| 52 | $query = "($team_a_query AND team_b_points > team_a_points) OR ($team_b_query AND team_a_points > team_b_points)"; |
||
| 53 | break; |
||
| 54 | case "draw": |
||
| 55 | case "draws": |
||
| 56 | case "tie": |
||
| 57 | case "ties": |
||
| 58 | $query = "($team_a_query OR $team_b_query) AND team_a_points = team_b_points"; |
||
| 59 | break; |
||
| 60 | default: |
||
| 61 | $query = "$team_a_query OR $team_b_query"; |
||
| 62 | } |
||
| 63 | |||
| 64 | $this->whereConditions[] = $query; |
||
| 65 | $this->parameters[] = $participant->getId(); |
||
| 66 | $this->parameters[] = $participant->getId(); |
||
| 67 | |||
| 68 | return $this; |
||
| 69 | } |
||
| 70 | |||
| 125 |