Text::checkFillCaptcha()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
c 1
b 0
f 0
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