Passed
Branch 3.x (80fbf8)
by Enjoys
01:46
created

Captcha::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * The MIT License
5
 *
6
 * Copyright 2020 Enjoys.
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated documentation files (the "Software"), to deal
10
 * in the Software without restriction, including without limitation the rights
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 * copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 * THE SOFTWARE.
25
 */
26
27
declare(strict_types=1);
28
29
namespace Enjoys\Forms\Elements;
30
31
use Enjoys\Forms\Element;
32
use Enjoys\Forms\Exception\ExceptionElement;
33
use Enjoys\Forms\DefaultsHandler;
34
35
/**
36
 * Description of Captcha
37
 *
38
 * @author Enjoys
39
 */
40
class Captcha extends Element
41
{
42
    use \Enjoys\Forms\Traits\Description;
43
    use \Enjoys\Forms\Traits\Rules;
44
45
    private $captcha;
46
47
    public function __construct(\Enjoys\Forms\Captcha\CaptchaInterface $captcha, string $message = null)
48
    {
49
        parent::__construct(\uniqid('captcha'));
50
        
51
        $this->captcha = $captcha;
52
        $this->captcha->setRequest($this->getRequest());
0 ignored issues
show
Bug introduced by
The method setRequest() does not exist on Enjoys\Forms\Captcha\CaptchaInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Enjoys\Forms\Captcha\CaptchaInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
        $this->captcha->/** @scrutinizer ignore-call */ 
53
                        setRequest($this->getRequest());
Loading history...
53
        
54
        
55
        $this->setName($this->captcha->getName());
56
        $this->addRule(\Enjoys\Forms\Rules::CAPTCHA, $this->captcha->getRuleMessage());
0 ignored issues
show
Bug introduced by
The method getRuleMessage() does not exist on Enjoys\Forms\Captcha\CaptchaInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Enjoys\Forms\Captcha\CaptchaInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
        $this->addRule(\Enjoys\Forms\Rules::CAPTCHA, $this->captcha->/** @scrutinizer ignore-call */ getRuleMessage());
Loading history...
57
    }
58
59
    public function renderHtml()
60
    {
61
        return $this->captcha->renderHtml($this);
62
    }
63
64
    public function validate()
65
    {
66
        return $this->captcha->validate($this);
67
    }
68
69
    public function baseHtml(): ?string
70
    {
71
        return $this->renderHtml();
72
    }
73
}
74