Text   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 27
ccs 13
cts 13
cp 1
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A checkFillCaptcha() 0 4 2
A set() 0 10 1
A addRule() 0 2 1
1
<?php
2
3
namespace kalanis\kw_forms\Controls\Security\Captcha;
4
5
6
use ArrayAccess;
7
use kalanis\kw_rules\Interfaces\IRules;
8
9
10
/**
11
 * Class Text
12
 * @package kalanis\kw_forms\Controls\Security\Captcha
13
 * Text-filling captcha
14
 */
15
class Text extends AGraphical
16
{
17 4
    public function set(string $alias, ArrayAccess &$session, string $errorMessage, string $font = '/usr/share/fonts/truetype/freefont/FreeMono.ttf'): self
18
    {
19 4
        $this->font = $font;
20 4
        $text = strtoupper($this->generateRandomString(8));
21
22 4
        $this->setEntry($alias, null, $text);
23 4
        $this->fillSession($alias, $session, $text);
24 4
        $this->setAttribute('id', $this->getKey());
25 4
        parent::addRule(IRules::SATISFIES_CALLBACK, $errorMessage, [$this, 'checkFillCaptcha']);
26 4
        return $this;
27
    }
28
29 1
    public function addRule(/** @scrutinizer ignore-unused */ string $ruleName, /** @scrutinizer ignore-unused */ string $errorText, /** @scrutinizer ignore-unused */ ...$args): void
30
    {
31
        // no additional rules applicable
32 1
    }
33
34
    /**
35
     * @param mixed $value
36
     * @return bool
37
     */
38 1
    public function checkFillCaptcha($value): bool
39
    {
40 1
        $formName = $this->getKey() . '_last';
41 1
        return $this->getSession()->offsetExists($formName) && (strval($this->getSession()->offsetGet($formName)) == strval($value));
42
    }
43
}
44