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

NotificationController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 22
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 3 1
A allUnread() 0 3 1
A read() 0 10 2
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