RedisSetMemberForm::addFieldsToForm()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 7
cp 0
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace UniMan\Drivers\Redis\Forms;
4
5
use UniMan\Core\Forms\ItemForm\ItemFormInterface;
6
use Nette\Application\UI\Form;
7
use Nette\Utils\ArrayHash;
8
use RedisProxy\RedisProxy;
9
10
class RedisSetMemberForm implements ItemFormInterface
11
{
12
    private $connection;
13
14
    private $key;
15
16
    private $member;
17
18
    public function __construct(RedisProxy $connection, $key, $member)
19
    {
20
        $this->connection = $connection;
21
        $this->key = $key;
22
        $this->member = $member;
23
    }
24
25
    public function addFieldsToForm(Form $form)
26
    {
27
        $form->addText('member', 'redis.member_form.member.label')
28
            ->setRequired('redis.member_form.member.required');
0 ignored issues
show
Documentation introduced by
'redis.member_form.member.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...
29
30
        if ($this->member) {
31
            $form->setDefaults([
32
                'member' => $this->member,
33
            ]);
34
        }
35
    }
36
37
    public function submit(Form $form, ArrayHash $values)
38
    {
39
        if ($this->member && !$this->connection->srem($this->key, $this->member)) {
40
            $form->addError($form->getTranslator()->translate('redis.member_form.message.cannot_be_removed'));
41
            return;
42
        }
43
        $this->connection->sadd($this->key, $values['member']);
44
    }
45
}
46