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 ( 4eeb3b...c62624 )
by Aden
03:43
created

ModelEditing::edit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 14
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
1
<?php
2
3
namespace LaravelFlare\Flare\Admin\Models\Traits;
4
5
use LaravelFlare\Flare\Events\ModelEdit;
6
use LaravelFlare\Flare\Events\AfterEdit;
7
use LaravelFlare\Flare\Events\BeforeEdit;
8
use LaravelFlare\Flare\Exceptions\ModelAdminWriteableException as WriteableException;
9
10
trait ModelEditing
11
{
12
    /**
13
     * Method fired before the Edit action is undertaken.
14
     * 
15
     * @return
16
     */
17
    protected function beforeEdit()
18
    {
19
    }
20
21
    /**
22
     * Edit Action.
23
     *
24
     * Fires off beforeEdit(), doEdit() and afterEdit()
25
     * 
26
     * @param int $modelitemId
27
     * 
28
     * @return
29
     */
30
    public function edit($modelitemId)
31
    {
32
        $this->find($modelitemId);
0 ignored issues
show
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...
33
34
        event(new BeforeEdit($this));
35
36
        $this->beforeEdit();
37
38
        $this->doEdit();
39
40
        $this->afterEdit();
41
42
        event(new AfterEdit($this));
43
    }
44
45
    /**
46
     * The actual Edit action, which does all of the pre-processing
47
     * required before we are able to perform the save() function.
48
     * 
49
     * @return
50
     */
51 View Code Duplication
    private function doEdit()
0 ignored issues
show
Duplication introduced by
This method 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...
52
    {
53
        if (is_callable(array('self', 'save'))) {
54
            $this->save();
0 ignored issues
show
Bug introduced by
It seems like save() 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...
55
56
            event(new ModelEdit($this));
57
58
            return;
59
        }
60
61
        throw new WriteableException('For a Model to be Editable the ModelAdmin must have the Save method implemented using the ModelWriting trait', 1);
62
    }
63
64
    /**
65
     * Method fired after the Edit action is complete.
66
     * 
67
     * @return
68
     */
69
    protected function afterEdit()
70
    {
71
    }
72
}
73