Issues (31)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Http/Controllers/LessonsController.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Scool\Timetables\Http\Controllers;
4
5
use Prettus\Validator\Contracts\ValidatorInterface;
6
use Prettus\Validator\Exceptions\ValidatorException;
7
use Scool\Timetables\Http\Requests\LessonCreateRequest;
8
use Scool\Timetables\Http\Requests\LessonUpdateRequest;
9
use Scool\Timetables\Repositories\LessonRepository;
10
use Scool\Timetables\Validators\LessonValidator;
11
12
class LessonsController extends Controller
13
{
14
15
    /**
16
     * @var LessonRepository
17
     */
18
    protected $repository;
19
20
    /**
21
     * @var LessonValidator
22
     */
23
    protected $validator;
24
25
    public function __construct(LessonRepository $repository, LessonValidator $validator)
26
    {
27
        $this->repository = $repository;
28
        $this->validator  = $validator;
29
    }
30
31
32
    /**
33
     * Display a listing of the resource.
34
     *
35
     * @return \Illuminate\Http\Response
36
     */
37
    public function index()
38
    {
39
        $this->repository->pushCriteria(app('Prettus\Repository\Criteria\RequestCriteria'));
40
        $lessons = $this->repository->with(['users'])->paginate(2);
41
42
        if (request()->wantsJson()) {
43
            return response()->json([
44
                'data' => $lessons,
45
            ]);
46
        }
47
48
        return view('timetables::lessons.index', compact('lessons'));
49
    }
50
51
    /**
52
     * Show the form for creating the specified resource.
53
     *
54
     * @return \Illuminate\Http\Response
55
     */
56
    public function create()
57
    {
58
        return view('lessons.create');
59
    }
60
61
    /**
62
     * Store a newly created resource in storage.
63
     *
64
     * @param  LessonCreateRequest $request
65
     *
66
     * @return \Illuminate\Http\Response
67
     */
68 View Code Duplication
    public function store(LessonCreateRequest $request)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        try {
71
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_CREATE);
72
73
            $lesson = $this->repository->create($request->all());
74
75
            if ($request->has('user_id')) {
76
                $user_id = $request->input('user_id');
77
                $user = \App\User::find($user_id);
78
                $lesson->users()->save($user);
79
            }
80
81
            $response = [
82
                'message' => 'Lesson created.',
83
                'data'    => $lesson->toArray(),
84
            ];
85
86
            if ($request->wantsJson()) {
87
                return response()->json($response);
88
            }
89
90
            return redirect()->back()->with('message', $response['message']);
91
        } catch (ValidatorException $e) {
92
            if ($request->wantsJson()) {
93
                return response()->json([
94
                    'error'   => true,
95
                    'message' => $e->getMessageBag()
96
                ]);
97
            }
98
99
            return redirect()->back()->withErrors($e->getMessageBag())->withInput();
100
        }
101
    }
102
103
104
    /**
105
     * Display the specified resource.
106
     *
107
     * @param  int $id
108
     *
109
     * @return \Illuminate\Http\Response
110
     */
111
    public function show($id)
112
    {
113
        $lesson = $this->repository->find($id);
114
115
        if (request()->wantsJson()) {
116
            return response()->json([
117
                'data' => $lesson,
118
            ]);
119
        }
120
121
        return view('lessons.show', compact('lesson'));
122
    }
123
124
125
    /**
126
     * Show the form for editing the specified resource.
127
     *
128
     * @param  int $id
129
     *
130
     * @return \Illuminate\Http\Response
131
     */
132
    public function edit($id)
133
    {
134
        $lesson = $this->repository->find($id);
135
136
        return view('lessons.edit', compact('lesson'));
137
    }
138
139
140
    /**
141
     * Update the specified resource in storage.
142
     *
143
     * @param  LessonUpdateRequest $request
144
     * @param  string            $id
145
     *
146
     * @return Response
147
     */
148 View Code Duplication
    public function update(LessonUpdateRequest $request, $id)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
149
    {
150
        try {
151
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_UPDATE);
152
153
            $lesson = $this->repository->update($request->all(), $id);
154
155
            if ($request->has('user_id')) {
156
                $user_id = $request->input('user_id');
157
                $user = \App\User::find($user_id);
158
                $lesson->users()->save($user);
159
            }
160
161
            $response = [
162
                'message' => 'Lesson updated.',
163
                'data'    => $lesson->toArray(),
164
            ];
165
166
            if ($request->wantsJson()) {
167
                return response()->json($response);
168
            }
169
170
            return redirect()->back()->with('message', $response['message']);
171
        } catch (ValidatorException $e) {
172
            if ($request->wantsJson()) {
173
                return response()->json([
174
                    'error'   => true,
175
                    'message' => $e->getMessageBag()
176
                ]);
177
            }
178
179
            return redirect()->back()->withErrors($e->getMessageBag())->withInput();
180
        }
181
    }
182
183
184
    /**
185
     * Remove the specified resource from storage.
186
     *
187
     * @param  int $id
188
     *
189
     * @return \Illuminate\Http\Response
190
     */
191
    public function destroy($id)
192
    {
193
        $lesson = $this->repository->find($id);
194
        $lesson->users()->detach();
195
        $deleted = $this->repository->delete($id);
196
197
198
        if (request()->wantsJson()) {
199
            return response()->json([
200
                'message' => 'Lesson deleted.',
201
                'deleted' => $deleted,
202
            ]);
203
        }
204
205
        return redirect()->back()->with('message', 'Lesson deleted.');
206
    }
207
}
208