Completed
Pull Request — master (#19)
by Michal
08:13
created

RedisCreateSetForm::addFieldsToForm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Adminerng\Drivers\Redis\Forms;
4
5
use Adminerng\Core\Forms\TableForm\TableFormInterface;
6
use Nette\Application\UI\Form;
7
use Nette\Utils\ArrayHash;
8
use RedisProxy\RedisProxy;
9
10
class RedisCreateSetForm 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.set_form.key.label')
22 2
            ->setRequired('redis.set_form.key.required');
0 ignored issues
show
Documentation introduced by
'redis.set_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('members', 'redis.set_form.members.label')
24 2
            ->setRequired('redis.set_form.members.required')
0 ignored issues
show
Documentation introduced by
'redis.set_form.members.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
            ->setOption('description', 'redis.set_form.members.description');
26 2
    }
27
28 2
    public function submit(Form $form, ArrayHash $values)
29
    {
30 2
        $key = $values['key'];
31 2
        $members = array_map('trim', explode(',', $values['members']));
32 2
        call_user_func_array([$this->connection, 'sadd'], array_merge([$key], $members));
33 2
    }
34
}
35