ACaptcha::addRules()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace kalanis\kw_forms\Controls\Security\Captcha;
4
5
6
use kalanis\kw_forms\Controls\AControl;
7
use kalanis\kw_forms\Interfaces\ITimeout;
8
9
10
/**
11
 * Class ACaptcha
12
 * @package kalanis\kw_forms\Controls\Security\Captcha
13
 * Class that define any Captcha
14
 * You can also pass captcha by preset timer
15
 */
16
abstract class ACaptcha extends AControl
17
{
18
    protected ?ITimeout $libTimeout = null;
19
20 1
    public function addRules(/** @scrutinizer ignore-unused */ iterable $rules = []): void
21
    {
22
        // no adding external rules applicable
23 1
    }
24
25 2
    public function getRules(): array
26
    {
27 2
        $ruleset = $this->canPass() ? [] : $this->rules;
28 2
        if ($this->libTimeout && !empty($ruleset)) {
29 1
            $this->libTimeout->updateExpire();
30
        }
31 2
        return $ruleset;
32
    }
33
34 1
    public function removeRules(): void
35
    {
36
        // no rules removal applicable
37 1
    }
38
39 1
    public function renderLabel($attributes = []): string
40
    {
41 1
        return $this->canPass() ? '' : parent::renderLabel($attributes);
42
    }
43
44 1
    public function renderInput($attributes = []): string
45
    {
46 1
        return $this->canPass() ? '' : parent::renderInput($attributes);
47
    }
48
49 1
    public function renderErrors(array $errors): string
50
    {
51 1
        return $this->canPass() ? '' : parent::renderErrors($errors);
52
    }
53
54 2
    protected function canPass(): bool
55
    {
56 2
        return ($this->libTimeout && $this->libTimeout->isRunning());
57
    }
58
59 7
    public function setTimeout(?ITimeout $libTimeout = null): self
60
    {
61 7
        $this->libTimeout = $libTimeout;
62 7
        return $this;
63
    }
64
}
65