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.

ModelCreating   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 20.34 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 4
dl 12
loc 59
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A beforeCreate() 0 3 1
A create() 0 12 1
A doCreate() 12 12 2
A afterCreate() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace LaravelFlare\Flare\Admin\Models\Traits;
4
5
use LaravelFlare\Flare\Events\ModelCreate;
6
use LaravelFlare\Flare\Events\AfterCreate;
7
use LaravelFlare\Flare\Events\BeforeCreate;
8
use LaravelFlare\Flare\Exceptions\ModelAdminWriteableException as WriteableException;
9
10
trait ModelCreating
11
{
12
    /**
13
     * Method fired before the Create action is undertaken.
14
     * 
15
     * @return
16
     */
17
    protected function beforeCreate()
18
    {
19
    }
20
21
    /**
22
     * Create Action.
23
     *
24
     * Fires off beforeCreate(), doCreate() and afterCreate()
25
     * 
26
     * @return
27
     */
28
    public function create()
29
    {
30
        event(new BeforeCreate($this));
31
32
        $this->beforeCreate();
33
34
        $this->doCreate();
35
36
        $this->afterCreate();
37
38
        event(new AfterCreate($this));
39
    }
40
41
    /**
42
     * The actual Create action, which does all of hte pre-processing
43
     * required before we are able to perform the save() function.
44
     * 
45
     * @return
46
     */
47 View Code Duplication
    private function doCreate()
48
    {
49
        if (is_callable(array('self', 'save'))) {
50
            $this->save();
51
52
            event(new ModelCreate($this));
53
54
            return;
55
        }
56
57
        throw new WriteableException('For a Model to be Creatable the ModelAdmin must have the Save method implemented using the ModelWriting trait', 1);
58
    }
59
60
    /**
61
     * Method fired after the Create action is complete.
62
     * 
63
     * @return
64
     */
65
    protected function afterCreate()
66
    {
67
    }
68
}
69