TAuthLock::getLock()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
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
    protected ?ILock $lock = null;
20
21 81
    protected function initAuthLock(?ILock $lock): void
22
    {
23 81
        $this->lock = $lock;
24 81
    }
25
26
    /**
27
     * @throws AuthSourcesException
28
     * @return ILock
29
     */
30 51
    protected function getLock(): ILock
31
    {
32 51
        if (!$this->lock) {
33 1
            throw new AuthSourcesException($this->getAusLang()->kauLockSystemNotSet());
34
        }
35 50
        return $this->lock;
36
    }
37
38
    /**
39
     * @param string $note
40
     * @throws AuthSourcesException
41
     * @throws LockException
42
     */
43 51
    protected function checkLock(string $note = ''): void
44
    {
45 51
        if ($this->getLock()->has()) {
46 22
            throw new AuthSourcesException(empty($note) ? $this->getAusLang()->kauAuthAlreadyOpen() : $note);
47
        }
48 28
    }
49
}
50