LaraCedTrait   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 1
dl 0
loc 86
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A bootLaraCedTrait() 0 4 1
A isUseSoftDeletes() 0 9 2
A getUserModel() 0 6 1
A getCreatorColumn() 0 4 2
A getEditorColumn() 0 4 2
A getDestroyerColumn() 0 4 2
A creator() 0 4 1
A editor() 0 4 1
A destroyer() 0 4 1
1
<?php
2
3
namespace LaraCed;
4
5
trait LaraCedTrait
6
{
7
    public static function bootLaraCedTrait()
8
    {
9
        static::observe(new LaraCedObserver);
10
    }
11
12
    /**
13
     * Has the model loaded the SoftDeletes trait.
14
     *
15
     * @return bool
16
     */
17
    public static function isUseSoftDeletes()
18
    {
19
        static $isUseSoftDeletes;
20
        if (is_null($isUseSoftDeletes)) {
21
            return $isUseSoftDeletes = in_array('Illuminate\Database\Eloquent\SoftDeletes', class_uses_recursive(get_called_class()));
22
        }
23
24
        return $isUseSoftDeletes;
25
    }
26
27
    /**
28
     *  Get user model.
29
     */
30
    public function getUserModel()
31
    {
32
        $class = config('auth.providers.users.model');
33
34
        return $class;
35
    }
36
37
    /**
38
     * Get the name of the "creator" column.
39
     *
40
     * @return string
41
     */
42
    public function getCreatorColumn()
43
    {
44
        return defined('static::CREATOR_COLUMN') ? static::CREATOR_COLUMN : 'created_by';
45
    }
46
47
    /**
48
     * Get the name of the "editor" column.
49
     *
50
     * @return string
51
     */
52
    public function getEditorColumn()
53
    {
54
        return defined('static::EDITOR_COLUMN') ? static::EDITOR_COLUMN : 'updated_by';
55
    }
56
57
    /**
58
     * Get the name of the "destroyer" column.
59
     *
60
     * @return string
61
     */
62
    public function getDestroyerColumn()
63
    {
64
        return defined('static::DESTROYER_COLUMN') ? static::DESTROYER_COLUMN : 'deleted_by';
65
    }
66
67
    /**
68
     * Creator, relation with user model.
69
     */
70
    public function creator()
71
    {
72
        return $this->belongsTo($this->getUserModel(), $this->getCreatorColumn());
0 ignored issues
show
Bug introduced by
It seems like belongsTo() 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...
73
    }
74
75
    /**
76
     * Editor, relation with user model.
77
     */
78
    public function editor()
79
    {
80
        return $this->belongsTo($this->getUserModel(), $this->getEditorColumn());
0 ignored issues
show
Bug introduced by
It seems like belongsTo() 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...
81
    }
82
83
    /**
84
     * Destroyer, relation with user model.
85
     */
86
    public function destroyer()
87
    {
88
        return $this->belongsTo($this->getUserModel(), $this->getDestroyerColumn());
0 ignored issues
show
Bug introduced by
It seems like belongsTo() 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...
89
    }
90
}
91