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

NotificationController::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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