Completed
Push — master ( 22caaa...988d36 )
by Maxime
15:13 queued 03:59
created

LockableTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 42.86%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 39
ccs 6
cts 14
cp 0.4286
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isLocked() 0 6 1
A incrementLock() 0 8 1
A unlock() 0 8 1
A lock() 0 7 1
1
<?php namespace Distilleries\Expendable\Models;
2
3
4
trait LockableTrait
5
{
6
    protected $config_key_security_lock = 'expendable.auth.nb_of_try';
7
    protected $column_nb_of_try_name = 'nb_of_try';
8
9 4
    public function isLocked()
10
    {
11
12 4
        return ($this->{$this->column_nb_of_try_name} >= config($this->config_key_security_lock));
13
14
    }
15
16
    public function incrementLock()
17
    {
18
19
        $this->{$this->column_nb_of_try_name} += 1;
20
        $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...
21
22
        return $this;
23
    }
24
25 12
    public function unlock()
26
    {
27 12
        $this->{$this->column_nb_of_try_name} = 0;
28 12
        $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...
29
30 12
        return $this;
31
32
    }
33
34
    public function lock()
35
    {
36
        $this->{$this->column_nb_of_try_name} = config($this->config_key_security_lock) + 1;
37
        $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...
38
39
        return $this;
40
    }
41
42
}