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

RedisCreateHashForm::addFieldsToForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 8
cts 8
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 1
crap 1
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