TokenField::createValidators()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace mindplay\kissform\Fields;
4
5
use mindplay\kissform\Facets\TokenServiceInterface;
6
use mindplay\kissform\Field;
7
use mindplay\kissform\InputModel;
8
use mindplay\kissform\InputRenderer;
9
use mindplay\kissform\Validators\CheckToken;
10
11
class TokenField extends Field
12
{
13
    /**
14
     * @var string
15
     */
16
    const TOKEN_UUID = 'c020b766-cddd-4f7a-ba75-4da76f861a62';
17
    
18
    /**
19
     * @var TokenServiceInterface
20
     */
21
    private $service;
22
23
    /**
24
     * @param string                $name token name (unique to the form or controller)
25
     * @param TokenServiceInterface $service
26
     */
27 1
    public function __construct($name, TokenServiceInterface $service)
28
    {
29 1
        parent::__construct(self::TOKEN_UUID . '-' . sha1($name));
30
        
31 1
        $this->service = $service;
32 1
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 1 View Code Duplication
    public function renderInput(InputRenderer $renderer, InputModel $model, array $attr)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
    {
39 1
        return $renderer->tag(
40 1
            'input',
41
            $attr + [
42 1
                'type'  => 'hidden',
43 1
                'name'  => $renderer->getName($this),
44 1
                'value' => $this->service->createToken($this->getName()),
45
            ]
46
        );
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 1
    public function createValidators()
53
    {
54 1
        return [new CheckToken($this->service)];
55
    }
56
}
57