Passed
Push — master ( 4b0d05...471523 )
by Arthur
103:49 queued 98:11
created

NotificationService::find()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.2098

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 13
rs 10
c 0
b 0
f 0
ccs 5
cts 7
cp 0.7143
crap 3.2098
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 04.10.18
6
 * Time: 16:17.
7
 */
8
9
namespace Modules\Notification\Services;
10
11
use Illuminate\Notifications\DatabaseNotification as Notification;
12
use Modules\Notification\Contracts\NotificationServiceContract;
13
use Modules\User\Contracts\UserServiceContract;
14
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
15
16
class NotificationService implements NotificationServiceContract
17
{
18
    protected $user;
19
20
    /**
21
     * NotificationService constructor.
22
     *
23
     * @param $service
24
     */
25 3
    public function __construct(UserServiceContract $service)
26
    {
27 3
        $this->user = $service;
28 3
    }
29
30 2
    public function find($id): ?Notification
31
    {
32 2
        if ($id instanceof Notification) {
33
            return $id;
34
        }
35
36 2
        $notification = Notification::find($id);
37
38 2
        if ($notification === null) {
39
            throw new NotFoundHttpException();
40
        }
41
42 2
        return $notification;
43
    }
44
45 1
    public function allNotificationsByUser($user)
46
    {
47 1
        return $this->user->find($user)->notifications;
0 ignored issues
show
Bug introduced by
The property notifications does not seem to exist on Modules\User\Entities\User. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
48
    }
49
50 1
    public function unreadNotifcationsByUser($user)
51
    {
52 1
        return  $this->user->find($user)->unreadNotifications;
0 ignored issues
show
Bug introduced by
The property unreadNotifications does not seem to exist on Modules\User\Entities\User. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
53
    }
54
55 2
    public function markAsRead($id)
56
    {
57 2
        $this->find($id)->markAsRead();
58 2
    }
59
60
    public function markAsUnread($id)
61
    {
62
        $this->find($id)->markAsUnread();
63
    }
64
}
65