Passed
Pull Request — master (#281)
by
unknown
05:45
created

getLazyLoadedNotificationRelation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 4
loc 4
rs 10
c 0
b 0
f 0
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 NotifableLaravel53
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 notifynderNotifications()
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
    protected function getLazyLoadedNotificationRelation()
57
    {
58
        return $this->notifynderNotifications();
59
    }
60
}
61