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

LockableTrait::isLocked()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 9.4285
cc 1
eloc 2
nc 1
nop 0
crap 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
}