Issues (84)

Http/Controllers/ResultSubmissionsController.php (10 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Association;
6
use App\Result;
7
use App\TeamResult;
8
use App\ResultSubmission;
9
use Illuminate\Http\Request;
10
11
class ResultSubmissionsController extends Controller
12
{
13
    /**
14
     * Display a listing of the resource.
15
     *
16
     * @return \Illuminate\Http\Response
17
     */
18
    public function index(Association $association)
19
    {
20
        return view('result_submissions.approve', ['association' => $association]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('result_subm...tion' => $association)) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
21
    }
22
23
    /**
24
     * Show the form for creating a new resource.
25
     *
26
     * @return \Illuminate\Http\Response
27
     */
28
    public function create()
29
    {
30
        //
31
    }
32
33
    /**
34
     * Store a newly created resource in storage.
35
     *
36
     * @param  \Illuminate\Http\Request  $request
37
     * @return \Illuminate\Http\Response
38
     */
39
    public function store(Request $request)
0 ignored issues
show
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

39
    public function store(/** @scrutinizer ignore-unused */ Request $request)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
40
    {
41
        //
42
    }
43
44
    /**
45
     * Display the specified resource.
46
     *
47
     * @param  int  $id
48
     * @return \Illuminate\Http\Response
49
     */
50
    public function show($id)
0 ignored issues
show
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

50
    public function show(/** @scrutinizer ignore-unused */ $id)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
51
    {
52
        //
53
    }
54
55
    /**
56
     * Show the form for editing the specified resource.
57
     *
58
     * @param  int  $id
59
     * @return \Illuminate\Http\Response
60
     */
61
    public function edit($id)
0 ignored issues
show
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

61
    public function edit(/** @scrutinizer ignore-unused */ $id)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
62
    {
63
        //
64
    }
65
66
    /**
67
     * Update the specified resource in storage.
68
     *
69
     * @param  \Illuminate\Http\Request  $request
70
     * @param  int  $id
71
     * @return \Illuminate\Http\Response
72
     */
73
    public function update(Request $request, $id)
74
    {
75
        $submission = ResultSubmission::find($id);
76
77
        if ($request->delete == 'delete') {
78
            $submission->delete();
79
        }
80
        else {
81
            $result = Result::where('match_id', $submission->match_id)->first();
82
83
            if (empty($result)) {
84
                $result = new Result();
85
                $result->match_id = $submission->match_id;
86
            }
87
88
            $result->home_team_id = $submission->match->home_team_id;
0 ignored issues
show
The property home_team_id does not seem to exist on App\PLMatch. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
89
            $result->away_team_id = $submission->match->away_team_id;
0 ignored issues
show
The property away_team_id does not seem to exist on App\PLMatch. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
90
            $result->home_team_score = $submission->home_team_score;
91
            $result->away_team_score = $submission->away_team_score;
92
93
            $result->save();
94
95
            // home team result:
96
            $team_result = TeamResult::where('schedule_id', $submission->match->schedule_id)
0 ignored issues
show
The property schedule_id does not exist on App\PLMatch. Did you mean schedule?
Loading history...
97
                ->where('match_id', $submission->match_id)
98
                ->where('team_id', $result->home_team_id)
99
                ->first();
100
101
            if (empty($team_result)) {
102
                $team_result = new TeamResult();
103
                $team_result->schedule_id = $submission->match->schedule_id;
104
                $team_result->match_id = $submission->match->id;
105
                $team_result->team_id = $result->home_team_id;
106
            }
107
108
            $team_result->points = $result->home_team_score;
109
            $team_result->win = $result->home_team_id == $submission->win_team_id ? 1 : 0;
110
            $team_result->loss = $result->home_team_id != $submission->win_team_id ? 1 : 0;
111
            $team_result->tie = 0;
112
            $team_result->save();
113
114
            // away team result;
115
            $team_result = TeamResult::where('schedule_id', $submission->match->schedule_id)
116
                ->where('match_id', $submission->match_id)
117
                ->where('team_id', $result->away_team_id)
118
                ->first();
119
120
            if (empty($team_result)) {
121
                $team_result = new TeamResult();
122
                $team_result->schedule_id = $submission->match->schedule_id;
123
                $team_result->match_id = $submission->match->id;
124
                $team_result->team_id = $result->away_team_id;
125
            }
126
127
            $team_result->points = $result->away_team_score;
128
            $team_result->win = $result->away_team_id == $submission->win_team_id ? 1 : 0;
129
            $team_result->loss = $result->away_team_id != $submission->win_team_id ? 1 : 0;
130
            $team_result->tie = 0;
131
            $team_result->save();
132
133
            $submission->approved = TRUE;
134
            $submission->save();
135
        }
136
137
        $url = $request->url;
138
139
        if (!empty($url)) {
140
            return redirect($url)->with('success', 'Data saved successfully!');
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect($url)->w...a saved successfully!') also could return the type Illuminate\Http\Redirect...nate\Routing\Redirector which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
141
        }
142
143
        return redirect()->route('user', ['id' => \Auth::user()->id]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route...' => Auth::user()->id)) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
144
    }
145
146
    /**
147
     * Remove the specified resource from storage.
148
     *
149
     * @param  int  $id
150
     * @return \Illuminate\Http\Response
151
     */
152
    public function destroy($id)
0 ignored issues
show
The parameter $id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

152
    public function destroy(/** @scrutinizer ignore-unused */ $id)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
153
    {
154
        //
155
    }
156
}
157