Passed
Push — master ( ed3164...71916c )
by Petr
02:23
created

TAuthLock::initAuthLock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace kalanis\kw_auth_sources\Traits;
4
5
6
use kalanis\kw_auth_sources\AuthSourcesException;
7
use kalanis\kw_locks\Interfaces\ILock;
8
use kalanis\kw_locks\LockException;
9
10
11
/**
12
 * Trait TAuthLock
13
 * @package kalanis\kw_auth_sources\Traits
14
 */
15
trait TAuthLock
16
{
17
    use TLang;
18
19
    /** @var ILock|null */
20
    protected $lock = null;
21
22 55
    protected function initAuthLock(?ILock $lock): void
23
    {
24 55
        $this->lock = $lock;
25 55
    }
26
27
    /**
28
     * @throws AuthSourcesException
29
     * @return ILock
30
     */
31 30
    protected function getLock(): ILock
32
    {
33 30
        if (!$this->lock) {
34 1
            throw new AuthSourcesException($this->getAusLang()->kauLockSystemNotSet());
35
        }
36 29
        return $this->lock;
37
    }
38
39
    /**
40
     * @param string $note
41
     * @throws AuthSourcesException
42
     * @throws LockException
43
     */
44 30
    protected function checkLock(string $note = ''): void
45
    {
46 30
        if ($this->getLock()->has()) {
47 1
            throw new AuthSourcesException(empty($note) ? $this->getAusLang()->kauAuthAlreadyOpen() : $note);
48
        }
49 28
    }
50
}
51