Passed
Push — master ( 848980...7bc374 )
by Arthur
04:30
created

NotificationController::read()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 10
ccs 6
cts 7
cp 0.8571
crap 2.0116
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 14.10.18
6
 * Time: 18:58
7
 */
8
9
namespace Foundation\Controllers;
10
11
use Foundation\Resources\NotificationResource;
12
use Illuminate\Routing\Controller;
13
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
14
15
class NotificationController extends Controller
16
{
17 1
    public function all()
18
    {
19 1
        return NotificationResource::collection(get_authenticated_user()->notifications);
0 ignored issues
show
Bug introduced by
Accessing notifications on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
20
    }
21
22 1
    public function allUnread()
23
    {
24 1
        return NotificationResource::collection(get_authenticated_user()->unreadNotifications);
0 ignored issues
show
Bug introduced by
Accessing unreadNotifications on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
25
    }
26
27 2
    public function read($id)
28
    {
29 2
        $notification = get_authenticated_user()->unreadNotifications()->find($id);
30
31 2
        if ($notification === null)
32
            throw new NotFoundHttpException("Could not find notification");
33
34 2
        $notification->markAsRead();
35 2
        return response()->json([
36 2
            "success"
37
        ]);
38
    }
39
}
40