| Conditions | 10 |
| Paths | 9 |
| Total Lines | 63 |
| Code Lines | 48 |
| 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 |
||
| 10 | public function view() |
||
| 11 | { |
||
| 12 | /* |
||
| 13 | foreach (Score::with('player')->get() as $score) { |
||
| 14 | echo $score->player->name . "<br>"; |
||
| 15 | } |
||
| 16 | */ |
||
| 17 | $holescores = Holescore::with('hole')->where('created_at', '>=', '2015-04-28')->get(); |
||
| 18 | $count = $holescores->count(); |
||
| 19 | |||
| 20 | $eagles = 0; |
||
| 21 | $birdies = 0; |
||
| 22 | $pars = 0; |
||
| 23 | $bogeys = 0; |
||
| 24 | $doubleBogeys = 0; |
||
| 25 | $triples = 0; |
||
| 26 | $others = 0; |
||
| 27 | $holes = 1; |
||
| 28 | foreach (Holescore::with('hole')->where('created_at', '>=', '2015-04-28')->get() as $holescore) { |
||
| 29 | $diff = ($holescore->score) - ($holescore->hole->par); |
||
| 30 | |||
| 31 | switch ($diff) { |
||
| 32 | case -2: |
||
| 33 | $eagles++; |
||
| 34 | break; |
||
| 35 | case -1: |
||
| 36 | $birdies++; |
||
| 37 | break; |
||
| 38 | case 0: |
||
| 39 | $pars++; |
||
| 40 | break; |
||
| 41 | case 1: |
||
| 42 | $bogeys++; |
||
| 43 | break; |
||
| 44 | case 2: |
||
| 45 | $doubleBogeys++; |
||
| 46 | break; |
||
| 47 | case 3: |
||
| 48 | $triples++; |
||
| 49 | break; |
||
| 50 | case ($diff > 3): |
||
| 51 | $others++; |
||
| 52 | break; |
||
| 53 | } |
||
| 54 | $holes++; |
||
| 55 | //echo $holescore->hole->number . " score = " . $holescore->score ." " . $diff . "<br>"; |
||
| 56 | |||
| 57 | } |
||
| 58 | echo "Number of holes played by all = " . $count . "<br>"; |
||
| 59 | echo "Number of birdies =" . $birdies . " " . round($birdies/$count,2) . "%<br>"; |
||
| 60 | echo "Number of pars = " . $pars . " " . round($pars/$count,2) . "%<br>"; |
||
| 61 | echo "Number of bogeys =" . $bogeys . " " . round($bogeys/$count,2) . "%<br>"; |
||
| 62 | echo "Number of double bogeys = " . $doubleBogeys . " " . round($doubleBogeys/$count,2) . "%<br>"; |
||
| 63 | echo "Number of triples =" . $triples . " " . round($triples/$count,2) . "%<br>"; |
||
| 64 | echo "Number of others = " . $others . " " . round($others/$count,2) . "%<br>"; |
||
| 65 | exit(); |
||
| 66 | $scores = Score::where('player_id', '=', 2)->orderBy('date', 'desc')->take(20)->get(); |
||
| 67 | |||
| 68 | foreach( $scores->id as $scoreId) { |
||
| 69 | $holescores[$score_id] = Holescore::where('score_id', '=', $scoreId)->get(); |
||
| 70 | } |
||
| 71 | return $scores; |
||
| 72 | } |
||
| 73 | |||
| 87 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.