EnterScoresController::view()   C
last analyzed

Complexity

Conditions 10
Paths 9

Size

Total Lines 63
Code Lines 48

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 63
rs 6.3636
c 0
b 0
f 0
cc 10
eloc 48
nc 9
nop 0

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
3
class EnterScoresController extends \BaseController {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
5
    /**
6
     * Display a listing of the resource.
7
     *
8
     * @return Response
9
     */
10
    public function view()
11
    {
12
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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>";
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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();
0 ignored issues
show
Coding Style Compatibility introduced by
The method view() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
66
		$scores = Score::where('player_id', '=', 2)->orderBy('date', 'desc')->take(20)->get();
0 ignored issues
show
Unused Code introduced by
$scores = \Score::where(...esc')->take(20)->get(); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
67
68
		foreach( $scores->id as $scoreId) {
69
			$holescores[$score_id] = Holescore::where('score_id', '=', $scoreId)->get();
70
		}
71
		return $scores;
72
    }
73
74
    /**
75
76
    /**
77
     * Remove the specified resource from storage.
78
     *
79
     * @param  int  $id
80
     * @return Response
81
     */
82
    public function destroy($id)
83
    {
84
        //
85
    }
86
87
}