GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 54ff14...7df1ea )
by Aden
02:49
created

ModelCloning::afterClone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace LaravelFlare\Flare\Admin\Models\Traits;
4
5
trait ModelCloning
6
{
7
    /**
8
     * Method fired before the Clone action is undertaken.
9
     * 
10
     * @return
11
     */
12
    protected function beforeClone()
13
    {
14
    }
15
16
    /**
17
     * Clone Action.
18
     *
19
     * Fires off beforeClone(), doClone() and afterClone()
20
     *
21
     * @param int $modelitemId
22
     * 
23
     * @return
24
     */
25
    public function clone($modelitemId)
0 ignored issues
show
Unused Code introduced by
The parameter $modelitemId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
    {
27
        event(new BeforeClone($this));
28
29
        $this->beforeClone();
30
31
        $this->doClone();
32
33
        $this->afterClone();
34
35
        event(new AfterClone($this));
36
    }
37
38
    /**
39
     * The actual Clone action, which does all of hte pre-processing
40
     * required before we are able to perform the save() function.
41
     * 
42
     * @return
43
     */
44
    private function doClone()
45
    {
46
        if (is_callable(array('self', 'save'))) {
47
            $this->find($modelitemId)->replicate($this->excludeOnClone())->save();
0 ignored issues
show
Bug introduced by
The variable $modelitemId does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
It seems like find() 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...
48
49
            event(new ModelClone($this));
50
51
            return;
52
        }
53
54
        throw new WriteableException('For a Model to be Creatable the ModelAdmin must have the Save method implemented using the ModelWriting trait', 1);
55
    }
56
57
    /**
58
     * Method fired after the Clone action is complete.
59
     * 
60
     * @return
61
     */
62
    protected function afterClone()
63
    {
64
    }
65
66
    /**
67
     * An Array of Fields to Exclude on Clone.
68
     *
69
     * When cloning a Model ceratin data might need to be skipped
70
     * either because it is irrelevant (such as datestamps) or
71
     * because it is primary or unique data in the database.
72
     * 
73
     * @return array
74
     */
75
    public function excludeOnClone()
76
    {
77
        return [
78
            $this->model->getKeyName(),
79
            $this->model->getCreatedAtColumn(),
80
            $this->model->getUpdatedAtColumn(),
81
        ];
82
    }
83
84
    /**
85
     * 
86
     */
87
    public function unCloneableColumns()
88
    {
89
        // We will use this: SHOW INDEXES FROM users WHERE Non_unique != 0 AND Column_name != 'id'
90
        // To determine if there are unCloneable Columns and if that is the case, we will render
91
        // the clone view and validate the unCloneable Columns to be unique before saving.
92
    }
93
}
94