Completed
Push — issue-103 ( 69239e...9bd575 )
by
unknown
03:24
created

Notifable   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 9
Bugs 3 Features 2
Metric Value
wmc 11
c 9
b 3
f 2
lcom 1
cbo 1
dl 0
loc 138
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A notifications() 0 11 2
A readAllNotifications() 0 6 1
A readLimitNotifications() 0 6 1
A deleteLimitNotifications() 0 6 1
A deleteAllNotifications() 0 6 1
A getNotificationsNotRead() 0 6 1
A getNotifications() 0 6 1
A getLastNotification() 0 6 1
A countNotificationsNotRead() 0 6 1
A notifynderInstance() 0 4 1
1
<?php
2
3
namespace Fenos\Notifynder;
4
5
use Closure;
6
7
/**
8
 * Class Notifable.
9
 *
10
 * Trait to implement in your models
11
 * that want to be notified, it will set relations
12
 * and nice short cut for the management of notifications
13
 */
14
trait Notifable
15
{
16
    /**
17
     * Notification Relation.
18
     *
19
     * @return mixed
20
     */
21
    public function notifications()
22
    {
23
        // check if on the configurations file there is the option
24
        // polymorphic setted to true, if so Notifynder will work
25
        // polymorphic.
26
        if (config('notifynder.polymorphic') == false) {
27
            return $this->morphMany(config('notifynder.notification_model'), 'to');
0 ignored issues
show
Bug introduced by
It seems like morphMany() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
28
        } else {
29
            return $this->hasMany(config('notifynder.notification_model'), 'to_id');
0 ignored issues
show
Bug introduced by
It seems like hasMany() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
30
        }
31
    }
32
33
    /**
34
     * Read all Notifications.
35
     *
36
     * @return mixed
37
     */
38
    public function readAllNotifications()
39
    {
40
        return $this->notifynderInstance()->entity(
41
            $this->getMorphClass()
0 ignored issues
show
Bug introduced by
It seems like getMorphClass() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
42
        )->readAll($this->id);
0 ignored issues
show
Bug introduced by
The property id does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
43
    }
44
45
    /**
46
     * Read Limiting Notifications.
47
     *
48
     * @param  int    $numbers
49
     * @param  string $order
50
     * @return mixed
51
     */
52
    public function readLimitNotifications($numbers = 10, $order = 'ASC')
53
    {
54
        return $this->notifynderInstance()->entity(
55
            $this->getMorphClass()
0 ignored issues
show
Bug introduced by
It seems like getMorphClass() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
56
        )->readLimit($this->id, $numbers, $order);
57
    }
58
59
    /**
60
     * Delete Limiting Notifications.
61
     *
62
     * @param  int    $numbers
63
     * @param  string $order
64
     * @return mixed
65
     */
66
    public function deleteLimitNotifications($numbers = 10, $order = 'ASC')
67
    {
68
        return $this->notifynderInstance()->entity(
69
            $this->getMorphClass()
0 ignored issues
show
Bug introduced by
It seems like getMorphClass() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
70
        )->deleteLimit($this->id, $numbers, $order);
71
    }
72
73
    /**
74
     * Delete all Notifications.
75
     *
76
     * @return bool
77
     */
78
    public function deleteAllNotifications()
79
    {
80
        return $this->notifynderInstance()->entity(
81
            $this->getMorphClass()
0 ignored issues
show
Bug introduced by
It seems like getMorphClass() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
82
        )->deleteAll($this->id);
83
    }
84
85
    /**
86
     * Get Not Read.
87
     *
88
     * @param  null     $limit
89
     * @param  int|null $paginate
90
     * @param  string   $order
91
     * @param Closure   $filterScope
92
     * @return mixed
93
     */
94
    public function getNotificationsNotRead($limit = null, $paginate = null, $order = 'desc', Closure $filterScope = null)
95
    {
96
        return $this->notifynderInstance()->entity(
97
            $this->getMorphClass()
0 ignored issues
show
Bug introduced by
It seems like getMorphClass() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
98
        )->getNotRead($this->id, $limit, $paginate, $order, $filterScope);
99
    }
100
101
    /**
102
     * Get all notifications.
103
     *
104
     * @param  null     $limit
105
     * @param  int|null $paginate
106
     * @param  string   $order
107
     * @param Closure   $filterScope
108
     * @return mixed
109
     */
110
    public function getNotifications($limit = null, $paginate = null, $order = 'desc', Closure $filterScope = null)
111
    {
112
        return $this->notifynderInstance()->entity(
113
            $this->getMorphClass()
0 ignored issues
show
Bug introduced by
It seems like getMorphClass() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
114
        )->getAll($this->id, $limit, $paginate, $order, $filterScope);
115
    }
116
117
    /**
118
     * Get last notification.
119
     *
120
     * @param null    $category
121
     * @param Closure $filterScope
122
     * @return mixed
123
     */
124
    public function getLastNotification($category = null, Closure $filterScope = null)
125
    {
126
        return $this->notifynderInstance()->entity(
127
            $this->getMorphClass()
0 ignored issues
show
Bug introduced by
It seems like getMorphClass() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
128
        )->getLastNotification($this->id, $category, $filterScope);
129
    }
130
131
    /**
132
     * Count Not read notification.
133
     *
134
     * @param Closure $filterScope
135
     * @return mixed
136
     */
137
    public function countNotificationsNotRead(Closure $filterScope = null)
138
    {
139
        return $this->notifynderInstance()->entity(
140
            $this->getMorphClass()
0 ignored issues
show
Bug introduced by
It seems like getMorphClass() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
141
        )->countNotRead($this->id, $filterScope);
142
    }
143
144
    /**
145
     * @return \Fenos\Notifynder\NotifynderManager
146
     */
147
    protected function notifynderInstance()
148
    {
149
        return app('notifynder');
150
    }
151
}
152