Completed
Branch master (856cc5)
by Mihail
07:21 queued 04:29
created

CaptchaField   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
c 1
b 1
f 0
lcom 1
cbo 3
dl 0
loc 43
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A make() 0 20 2
1
<?php
2
namespace Ffcms\Core\Helper\HTML\Form;
3
4
5
use Ffcms\Core\App;
6
use Ffcms\Core\Helper\HTML\System\NativeGenerator;
7
8
class CaptchaField extends NativeGenerator implements iField
9
{
10
    private $properties;
11
    private $name;
12
    
13
    /**
14
     * CaptchaField constructor. Pass attributes inside model.
15
     * @param array $properties
16
     * @param string $name
17
     * @param string|null $value
18
     */
19
    public function __construct($properties, $name, $value = null)
20
    {
21
        $this->properties = $properties;
22
        $this->name = $name;
23
    }
24
25
    /**
26
     * Build captcha response
27
     * {@inheritDoc}
28
     * @see \Ffcms\Core\Helper\HTML\Form\iField::make()
29
     */
30
    public function make()
31
    {
32
        // if captcha is 'full-type' based just return rendered output
33
        if (App::$Captcha->isFull()) {
34
            return App::$Captcha->get();
35
        }
36
        // get image link
37
        $image = App::$Captcha->get();
38
        // build image tag
39
        $response = self::buildSingleTag('img', [
40
            'id' => 'src-secure-image',
41
            'src' => $image,
42
            'alt' => 'secure captcha image',
43
            'onClick' => 'this.src=\'' . $image . '&rnd=\'+Math.random()'
44
        ]);
45
        // render response tag with image
46
        $this->properties['type'] = 'text';
47
        $response .= self::buildSingleTag('input', $this->properties);
48
        return $response;
49
    }
50
}