Completed
Push — master ( 7bbb47...c865af )
by Tyler
180:44 queued 177:43
created

Model::boot()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2.2559

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 9
cts 15
cp 0.6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 1
nop 0
crap 2.2559
1
<?php
2
3
namespace Tylercd100\Database\Eloquent;
4
5
use Illuminate\Database\Eloquent\Model as IlluminateModel;
6
use Tylercd100\Database\Eloquent\Traits\AutoCache;
7
use Tylercd100\Database\Eloquent\Traits\AutoValidate;
8
9
abstract class Model extends IlluminateModel
10
{
11
    use AutoCache, AutoValidate;
12
13
    /**
14
     * Toggle the auto cache feature.
15
     *
16
     * @var int
17
     */
18
    const AUTO_CACHE_ENABLED = true;
19
20
    /**
21
     * A method best used to register Eloquent events when the model boots up
22
     * @return void
23
     */
24 6
    protected static function boot()
25
    {
26 6
        parent::boot();
27
28
        // Auto Validate
29 3
        self::saving(function ($model) {
30
            if (!$model->validate()) {
31
                return false;
32
            }
33 6
        });
34
35
        // Auto Cache
36 3
        static::saved(function ($model) {
37
            $model->refresh();
38 6
        }, -1);
0 ignored issues
show
Unused Code introduced by
The call to Model::saved() has too many arguments starting with -1.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
39
40 6
        static::deleted(function ($model) {
41
            $model->refresh();
42 6
        }, -1);
0 ignored issues
show
Unused Code introduced by
The call to Model::deleted() has too many arguments starting with -1.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
43 6
    }
44
}
45