Completed
Branch master (62cc10)
by Tyler
02:58
created

Pivot   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 63.64%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 29
loc 29
ccs 7
cts 11
cp 0.6364
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A boot() 20 20 2

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 Tylercd100\Database\Eloquent\Relations;
4
5
use Illuminate\Database\Eloquent\Relations\Pivot as IlluminatePivot;
6
use Tylercd100\Database\Eloquent\Traits\AutoCache;
7
use Tylercd100\Database\Eloquent\Traits\AutoValidate;
8
9 View Code Duplication
abstract class Pivot extends IlluminatePivot
0 ignored issues
show
Duplication introduced by
This class 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...
10
{
11
    use AutoCache, AutoValidate;
12
    
13
    /**
14
     * A method best used to register Eloquent events when the model boots up
15
     * @return void
16
     */
17 3
    protected static function boot()
18
    {
19 3
        parent::boot();
20
21
        // Auto Validate
22
        self::saving(function ($model) {
23
            if (!$model->validate()) {
24
                return false;
25
            }
26 3
        });
27
28
        // Auto Cache
29
        static::saved(function ($model) {
30
            $model->refresh();
31 3
        }, -1);
0 ignored issues
show
Unused Code introduced by
The call to Pivot::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...
32
33 3
        static::deleted(function ($model) {
34
            $model->refresh();
35 3
        }, -1);
0 ignored issues
show
Unused Code introduced by
The call to Pivot::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...
36 3
    }
37
}
38