Completed
Pull Request — master (#21)
by Michal
02:30
created

RedisCreateHashForm   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 28
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addFieldsToForm() 0 9 1
A submit() 0 8 2
1
<?php
2
3
namespace UniMan\Drivers\Redis\Forms;
4
5
use UniMan\Core\Forms\TableForm\TableFormInterface;
6
use Nette\Application\UI\Form;
7
use Nette\Utils\ArrayHash;
8
use RedisProxy\RedisProxy;
9
10
class RedisCreateHashForm implements TableFormInterface
11
{
12
    private $connection;
13
14 2
    public function __construct(RedisProxy $connection)
15
    {
16 2
        $this->connection = $connection;
17 2
    }
18
19 2
    public function addFieldsToForm(Form $form)
20
    {
21 2
        $form->addText('key', 'redis.hash_form.key.label')
22 2
            ->setRequired('redis.hash_form.key.required');
0 ignored issues
show
Documentation introduced by
'redis.hash_form.key.required' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
23 2
        $form->addText('field', 'redis.hash_form.field.label')
24 2
            ->setRequired('redis.hash_form.field.required');
0 ignored issues
show
Documentation introduced by
'redis.hash_form.field.required' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
25 2
        $form->addText('value', 'redis.hash_form.value.label')
26 2
            ->setRequired('redis.hash_form.value.required');
0 ignored issues
show
Documentation introduced by
'redis.hash_form.value.required' is of type string, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
27 2
    }
28
29 2
    public function submit(Form $form, ArrayHash $values)
30
    {
31 2
        if ($this->connection->hlen($values['key']) > 0) {
32 2
            $form->addError('Key "' . $values['key'] . '" already exists');
33 2
            return;
34
        }
35 2
        $this->connection->hset($values['key'], $values['field'], $values['value']);
36 2
    }
37
}
38