GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CommentController::destroy()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 4
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace BristolSU\Module\UploadFile\Http\Controllers\ParticipantApi;
4
5
use BristolSU\Module\UploadFile\Events\CommentCreated;
6
use BristolSU\Module\UploadFile\Events\CommentDeleted;
7
use BristolSU\Module\UploadFile\Events\CommentUpdated;
8
use BristolSU\Module\UploadFile\Http\Controllers\Controller;
9
use BristolSU\Module\UploadFile\Models\Comment;
10
use BristolSU\Module\UploadFile\Models\File;
11
use BristolSU\Support\Activity\Activity;
12
use BristolSU\Support\ActivityInstance\Contracts\ActivityInstanceResolver;
13
use BristolSU\Support\Authentication\Contracts\Authentication;
14
use BristolSU\Support\ModuleInstance\ModuleInstance;
15
use Illuminate\Auth\Access\AuthorizationException;
16
use Illuminate\Http\Request;
17
18
class CommentController extends Controller
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class CommentController
Loading history...
19
{
20
21 4
    public function index(Request $request, Activity $activity, ModuleInstance $moduleInstance, File $file)
0 ignored issues
show
Unused Code introduced by
The parameter $activity 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

21
    public function index(Request $request, /** @scrutinizer ignore-unused */ Activity $activity, ModuleInstance $moduleInstance, File $file)

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...
Unused Code introduced by
The parameter $moduleInstance 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

21
    public function index(Request $request, Activity $activity, /** @scrutinizer ignore-unused */ ModuleInstance $moduleInstance, File $file)

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...
Unused Code introduced by
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

21
    public function index(/** @scrutinizer ignore-unused */ Request $request, Activity $activity, ModuleInstance $moduleInstance, File $file)

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...
Coding Style introduced by
Missing doc comment for function index()
Loading history...
22
    {
23 4
        $this->authorize('comment.index');
24 3
        if ((int)$file->activity_instance_id !== (int)app(ActivityInstanceResolver::class)->getActivityInstance()->id) {
25 1
            throw new AuthorizationException();
26
        }
27 2
        return $file->comments;
28
    }
29
30 5
    public function store(Request $request, Activity $activity, ModuleInstance $moduleInstance, File $file)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function store()
Loading history...
31
    {
32 5
        $this->authorize('comment.store');
33
34 4
        $comment = $file->comments()->create([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
35 4
            'comment' => $request->input('comment'),
36 4
            'posted_by' => app(Authentication::class)->getUser()->id
0 ignored issues
show
Bug introduced by
Accessing id on the interface BristolSU\ControlDB\Contracts\Models\User suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
37
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
38
39 4
        event(new CommentCreated($comment));
40
41 4
        return $comment;
42
    }
43
44 6
    public function destroy(Request $request, Activity $activity, ModuleInstance $moduleInstance, Comment $comment)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function destroy()
Loading history...
45
    {
46 6
        $this->authorize('comment.destroy');
47
48 5
        if ((int)$comment->file->activity_instance_id !== (int)app(ActivityInstanceResolver::class)->getActivityInstance()->id) {
49 1
            throw new AuthorizationException();
50
        }
51
52 4
        $comment->delete();
53
54 4
        event(new CommentDeleted($comment));
55
56 4
        return $comment;
57
    }
58
59 6
    public function update(Request $request, Activity $activity, ModuleInstance $moduleInstance, Comment $comment)
0 ignored issues
show
Unused Code introduced by
The parameter $moduleInstance 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

59
    public function update(Request $request, Activity $activity, /** @scrutinizer ignore-unused */ ModuleInstance $moduleInstance, Comment $comment)

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...
Unused Code introduced by
The parameter $activity 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

59
    public function update(Request $request, /** @scrutinizer ignore-unused */ Activity $activity, ModuleInstance $moduleInstance, Comment $comment)

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...
Coding Style introduced by
Missing doc comment for function update()
Loading history...
60
    {
61 6
        $this->authorize('comment.update');
62
63 5
        if ((int)$comment->file->activity_instance_id !== (int)app(ActivityInstanceResolver::class)->getActivityInstance()->id) {
64 1
            throw new AuthorizationException();
65
        }
66
67 4
        $comment->comment = $request->input('comment', $comment->comment);
68
69 4
        $comment->save();
70
71 4
        event(new CommentUpdated($comment));
72
        
73 4
        return $comment;
74
    }
75
76
}