LockableTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 40%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 19
c 2
b 0
f 0
dl 0
loc 44
ccs 8
cts 20
cp 0.4
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A unlock() 0 9 1
A lock() 0 9 1
A isLocked() 0 4 1
A incrementLock() 0 8 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 2
    public function isLocked()
10
    {
11
12 2
        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
        \DB::table($this->getTable())
0 ignored issues
show
Bug introduced by
It seems like getTable() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
        \DB::table($this->/** @scrutinizer ignore-call */ getTable())
Loading history...
21
            ->where($this->getKeyName(), $this->getKey())
0 ignored issues
show
Bug introduced by
It seems like getKeyName() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

21
            ->where($this->/** @scrutinizer ignore-call */ getKeyName(), $this->getKey())
Loading history...
Bug introduced by
It seems like getKey() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

21
            ->where($this->getKeyName(), $this->/** @scrutinizer ignore-call */ getKey())
Loading history...
22
            ->increment($this->column_nb_of_try_name);
23
        return $this;
24
25
    }
26
27 4
    public function unlock()
28
    {
29
30 4
        \DB::table($this->getTable())
31 4
            ->where($this->getKeyName(), $this->getKey())
32 4
            ->decrement($this->column_nb_of_try_name, $this->{$this->column_nb_of_try_name});
33
34 4
        $this->{$this->column_nb_of_try_name} = 0;
35 4
        return $this;
36
37
    }
38
39
    public function lock()
40
    {
41
        $this->{$this->column_nb_of_try_name} = config($this->config_key_security_lock) + 1;
42
43
        \DB::table($this->getTable())
44
            ->where($this->getKeyName(), $this->getKey())
45
            ->increment($this->column_nb_of_try_name, $this->{$this->column_nb_of_try_name} );
46
47
        return $this;
48
    }
49
50
}