Passed
Push — master ( 704626...cc5609 )
by Enjoys
02:50 queued 48s
created

Captcha   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A prepare() 0 4 1
A getCaptcha() 0 3 1
A baseHtml() 0 3 1
A validate() 0 3 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\Interfaces\CaptchaInterface;
9
use Enjoys\Forms\Interfaces\Descriptionable;
10
use Enjoys\Forms\Interfaces\Ruleable;
11
use Enjoys\Forms\Rules;
12
use Enjoys\Forms\Traits;
13
14
class Captcha extends Element implements Ruleable, Descriptionable
15
{
16
    use Traits\Description;
17
    use Traits\Rules;
18
19
20
    /**
21
     * @param CaptchaInterface $captcha
22
     * @param string|null $message
23
     * @noinspection PhpMissingParentConstructorInspection
24
     */
25 6
    public function __construct(private CaptchaInterface $captcha, string $message = null)
26
    {
27 6
        $this->setRequest();
28 6
        $this->setName($this->captcha->getName());
29
    }
30
31 1
    public function prepare()
32
    {
33 1
        $this->captcha->setRequest($this->getRequest());
34 1
        $this->addRule(Rules::CAPTCHA, $this->captcha->getRuleMessage());
35
    }
36
37
    /**
38
     *
39
     * @return bool
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