Completed
Push — version-4 ( 5bb021 )
by
unknown
08:16
created

Notification::from()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 4 Features 1
Metric Value
cc 2
eloc 4
c 6
b 4
f 1
nc 2
nop 0
dl 0
loc 7
rs 9.4285
1
<?php
2
3
namespace Fenos\Notifynder\Models;
4
5
use Fenos\Notifynder\Notifications\ExtraParams;
6
use Fenos\Notifynder\Parsers\NotifynderParser;
7
use Illuminate\Contracts\Container\Container;
8
use Illuminate\Database\Eloquent\Collection;
9
use Illuminate\Database\Eloquent\Model;
10
use Carbon\Carbon;
11
use Illuminate\Support\Arr;
12
13
class Notification extends Model
14
{
15
    protected $fillable = [
16
        'to_id',
17
        'to_type',
18
        'from_id',
19
        'from_type',
20
        'category_id',
21
        'read',
22
        'url',
23
        'extra',
24
        'expire_time',
25
        'stack_id',
26
    ];
27
28
    public function __construct(array $attributes = [])
29
    {
30
        $this->fillable($this->mergeFillables());
31
32
        parent::__construct($attributes);
33
    }
34
35
    public function category()
36
    {
37
        return $this->belongsTo(NotificationCategory::class, 'category_id');
38
    }
39
40
    public function from()
41
    {
42
        if (notifynder_config()->isPolymorphic()) {
43
            return $this->belongsTo(notifynder_config()->getModel(), 'from_id');
0 ignored issues
show
Bug introduced by
The method getModel() does not seem to exist on object<Fenos\Notifynder\Contracts\ConfigContract>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
        }
45
        return $this->morphTo();
46
    }
47
48
    public function to()
49
    {
50
        if (notifynder_config()->isPolymorphic()) {
51
            return $this->belongsTo(notifynder_config()->getModel(), 'to_id');
0 ignored issues
show
Bug introduced by
The method getModel() does not seem to exist on object<Fenos\Notifynder\Contracts\ConfigContract>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
        }
53
        return $this->morphTo();
54
    }
55
56
    public function getCustomFillableFields()
57
    {
58
        return notifynder_config()->getAdditionalFields();
59
    }
60
61
    protected function mergeFillables()
62
    {
63
        $fillables = array_unique($this->getFillable() + $this->getCustomFillableFields());
64
65
        return $fillables;
66
    }
67
}
68