Captcha::getCaptcha()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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