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

NotificationService   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 78.95%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 47
ccs 15
cts 19
cp 0.7895
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A markAsRead() 0 3 1
A markAsUnread() 0 3 1
A find() 0 13 3
A allNotificationsByUser() 0 3 1
A unreadNotifcationsByUser() 0 3 1
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