Completed
Pull Request — master (#23)
by ARCANEDEV
07:46
created

AbstractPivot   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 43
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A registerObserver() 0 4 1
A getObserverClass() 0 4 1
1
<?php namespace Arcanedev\LaravelAuth\Models\Pivots;
2
3
use Illuminate\Database\Eloquent\Relations\Pivot;
4
use Illuminate\Database\Eloquent\Model;
5
6
/**
7
 * Class     AbstractPivot
8
 *
9
 * @package  Arcanedev\LaravelAuth\Models\Pivots
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
abstract class AbstractPivot extends Pivot
13
{
14
    /* -----------------------------------------------------------------
15
     |  Constructor
16
     | -----------------------------------------------------------------
17
     */
18
    /**
19
     * Create a new pivot model instance.
20
     *
21
     * @param  \Illuminate\Database\Eloquent\Model  $parent
22
     * @param  array                                $attributes
23
     * @param  string                               $table
24
     * @param  bool                                 $exists
25
     */
26 57
    public function __construct(Model $parent, $attributes, $table, $exists = false)
27
    {
28 57
        parent::__construct($parent, $attributes, $table, $exists);
29
30 57
        $this->registerObserver();
0 ignored issues
show
Unused Code introduced by
The call to the method Arcanedev\LaravelAuth\Mo...vot::registerObserver() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
31 57
    }
32
33
    /* -----------------------------------------------------------------
34
     |  Getters & Setters
35
     | -----------------------------------------------------------------
36
     */
37
    /**
38
     * Register the observable events.
39
     */
40 57
    private function registerObserver()
41
    {
42
        // TODO: Add the observable events
43 57
    }
44
45
    /**
46
     * Get the observer class for the pivot table.
47
     *
48
     * @return string|null
49
     */
50
    protected function getObserverClass()
51
    {
52
        return null;
53
    }
54
}
55