Passed
Push — master ( f218e6...f51c1b )
by Arthur
04:59
created

NotificationService   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A markAsRead() 0 3 1
A allNotificationsByUser() 0 3 1
A unreadNotifcationsByUser() 0 3 1
A __construct() 0 3 1
A markAsUnread() 0 3 1
A find() 0 11 3
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
12
13
use Modules\Notification\Contracts\NotificationServiceContract;
14
use Modules\Notification\Entities\Notification;
0 ignored issues
show
Bug introduced by
The type Modules\Notification\Entities\Notification was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Modules\User\Contracts\UserServiceContract;
16
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
17
18
class NotificationService implements NotificationServiceContract
19
{
20
    protected $user;
21
22
    /**
23
     * NotificationService constructor.
24
     * @param $service
25
     */
26
    public function __construct(UserServiceContract $service)
27
    {
28
        $this->user = $service;
29
    }
30
31
    public function find($id): ?Notification
32
    {
33
        if ($id instanceof Notification)
34
            return $id;
35
36
        $notification = Notification::find($id);
37
38
        if ($notification === null)
39
            throw new NotFoundHttpException();
40
41
        return $notification;
42
    }
43
44
    public function allNotificationsByUser($user)
45
    {
46
        $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...
47
    }
48
49
    public function unreadNotifcationsByUser($user)
50
    {
51
        $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...
52
    }
53
54
    public function markAsRead($id)
55
    {
56
        $this->find($id)->markAsRead();
57
    }
58
59
    public function markAsUnread($id)
60
    {
61
        $this->find($id)->markAsUnread();
62
    }
63
64
}
65