Notifable   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
morphMany() 1 1 ?
hasMany() 1 1 ?
A notifications() 9 9 2
A getLazyNotificationRelation() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Fenos\Notifynder\Traits;
4
5
use Fenos\Notifynder\Models\Notification;
6
7
/**
8
 * Class Notifable.
9
 */
10 View Code Duplication
trait Notifable
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
{
12
    use NotifableBasic;
13
14
    /**
15
     * Define a polymorphic one-to-many relationship.
16
     *
17
     * @param  string  $related
18
     * @param  string  $name
19
     * @param  string  $type
20
     * @param  string  $id
21
     * @param  string  $localKey
22
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
23
     */
24
    abstract public function morphMany($related, $name, $type = null, $id = null, $localKey = null);
25
26
    /**
27
     * Define a one-to-many relationship.
28
     *
29
     * @param  string  $related
30
     * @param  string  $foreignKey
31
     * @param  string  $localKey
32
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
33
     */
34
    abstract public function hasMany($related, $foreignKey = null, $localKey = null);
35
36
    /**
37
     * Get the notifications Relationship.
38
     *
39
     * @return \Illuminate\Database\Eloquent\Relations\HasMany|\Illuminate\Database\Eloquent\Relations\MorphMany
40
     */
41
    public function notifications()
42
    {
43
        $model = app('notifynder.resolver.model')->getModel(Notification::class);
44
        if (notifynder_config()->isPolymorphic()) {
45
            return $this->morphMany($model, 'to');
46
        }
47
48
        return $this->hasMany($model, 'to_id');
49
    }
50
51
    /**
52
     * Get the notifications Relationship without any eager loading.
53
     *
54
     * @return \Illuminate\Database\Eloquent\Relations\HasMany|\Illuminate\Database\Eloquent\Relations\MorphMany
55
     */
56
    public function getLazyNotificationRelation()
57
    {
58
        return $this->notifications();
59
    }
60
}
61