Captcha   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getCaptcha() 0 3 1
A baseHtml() 0 3 1
A validate() 0 3 1
A __construct() 0 4 1
A prepare() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Enjoys\Forms\Elements;
6
7
use Enjoys\Forms\Element;
8
use Enjoys\Forms\Exception\ExceptionRule;
9
use Enjoys\Forms\Interfaces\CaptchaInterface;
10
use Enjoys\Forms\Interfaces\Descriptionable;
11
use Enjoys\Forms\Interfaces\Ruleable;
12
use Enjoys\Forms\Rules;
13
use Enjoys\Forms\Traits;
14
15
class Captcha extends Element implements Ruleable, Descriptionable
16
{
17
    use Traits\Description;
18
    use Traits\Rules;
19
20
21
    /**
22
     * @noinspection PhpMissingParentConstructorInspection
23
     */
24 6
    public function __construct(private CaptchaInterface $captcha)
25
    {
26 6
        $this->setRequest();
27 6
        $this->setName($this->captcha->getName());
28
    }
29
30
    /**
31
     * @throws ExceptionRule
32
     */
33 1
    public function prepare(): bool
34
    {
35 1
        $this->captcha->setRequest($this->getRequest());
36 1
        $this->addRule(Rules::CAPTCHA, $this->captcha->getRuleMessage());
37
38 1
        return false;
39
    }
40
41 1
    public function validate(): bool
42
    {
43 1
        return $this->captcha->validate($this);
44
    }
45
46
47 1
    public function baseHtml(): string
48
    {
49 1
        return $this->captcha->renderHtml($this);
50
    }
51
52 1
    public function getCaptcha(): CaptchaInterface
53
    {
54 1
        return $this->captcha;
55
    }
56
}
57