Passed
Push — master ( 641a6e...dc98f1 )
by Enjoys
59s queued 12s
created

Captcha   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 11
c 1
b 0
f 0
dl 0
loc 50
ccs 12
cts 14
cp 0.8571
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A renderHtml() 0 3 1
A getCaptcha() 0 3 1
A prepare() 0 4 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 string
40
     */
41 1
    public function renderHtml(): string
42
    {
43 1
        return $this->captcha->renderHtml($this);
44
    }
45
46
    /**
47
     *
48
     * @return bool
49
     */
50 1
    public function validate(): bool
51
    {
52 1
        return $this->captcha->validate($this);
53
    }
54
55
56
    public function baseHtml(): string
57
    {
58
        return $this->renderHtml();
59
    }
60
61 1
    public function getCaptcha(): CaptchaInterface
62
    {
63 1
        return $this->captcha;
64
    }
65
}
66