MatchesController   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 3
dl 0
loc 116
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A show() 0 4 1
A __construct() 0 5 1
A index() 0 4 1
A create() 0 5 1
A store() 0 5 1
B edit() 0 29 3
A update() 0 4 1
A destroy() 0 4 1
1
<?php
2
3
use GolfLeague\Services\MatchService as MatchService;
4
use GolfLeague\Storage\Match\MatchRepository as MatchRepository;
5
use Carbon\Carbon;
6
7
class MatchesController 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...
8
9
10
    public function __construct(MatchService $match, MatchRepository $matchRepo)
11
    {
12
        $this->match = $match;
13
		$this->matchRepo = $matchRepo;
14
    }
15
16
	/**
17
	 * Display a listing of the resource.
18
	 *
19
	 * @return Response
20
	 */
21
	public function index()
22
	{
23
		return $this->matchRepo->all();
24
	}
25
26
27
	/**
28
	 * Show the form for creating a new resource.
29
	 *
30
	 * @return Response
31
	 */
32
	public function create()
33
	{
34
		$view = View::make('creatematch');
35
        return $view;
36
	}
37
38
	/**
39
	 * Store a newly created resource in storage.
40
	 *
41
	 * @return Response
42
	 */
43
	public function store()
44
	{
45
	    $input = Input::all();
46
		return $this->match->create($input);
47
	}
48
49
50
	/**
51
	 * Display the specified resource.
52
	 *
53
	 * @param  int  $id
54
	 * @return Response
55
	 */
56
	public function show($id)
57
	{
58
		return $this->matchRepo->get($id);
59
	}
60
61
62
	/**
63
	 * Show the form for editing the specified resource.
64
	 *
65
	 * @param  int  $id
66
	 * @return Response
67
	 */
68
	public function edit($id)
69
	{
70
71
        $enterView = 'EnterTeamMatch';
72
	    $data = $this->match->get($id);
73
        $view = View::make($enterView, $data);
74
        return $view;
75
76
	    // Logic to allow editable for day of match only
77
		$today = Carbon::today();
0 ignored issues
show
Unused Code introduced by
// Logic to allow editab...Carbon\Carbon::today(); 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...
78
79
        $teamMatchDate = new Carbon('first day of January 2017');
80
		$matchDate = new Carbon($data['date']);
81
82
		if($matchDate >= $teamMatchDate){
83
		    $enterView = 'EnterTeamMatch';
84
        }
85
86
		if($today <= $matchDate){
87
			//Show Editable View
88
			$view = View::make($enterView, $data);
89
			return $view;
90
		}
91
		else {
92
			//Show Readonly View
93
			$view = View::make('ViewMatch', $data);
94
			return $view;
95
		}
96
	}
97
98
99
	/**
100
	 * Update the specified resource in storage.
101
	 *
102
	 * @param  int  $id
103
	 * @return Response
104
	 */
105
	public function update($id)
106
	{
107
		//
108
	}
109
110
111
	/**
112
	 * Remove the specified resource from storage.
113
	 *
114
	 * @param  int  $id
115
	 * @return Response
116
	 */
117
	public function destroy($id)
118
	{
119
		return $this->matchRepo->delete($id);
120
	}
121
122
}
123