RedisSortedSetMemberForm   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 39
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A addFieldsToForm() 0 15 2
A submit() 0 7 2
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 RedisSortedSetMemberForm 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.sorted_set_member_form.member.label')
28
            ->setRequired('redis.sorted_set_member_form.member.required');
0 ignored issues
show
Documentation introduced by
'redis.sorted_set_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
        $form->addText('score', 'redis.sorted_set_member_form.score.label')
31
            ->setRequired('redis.sorted_set_member_form.score.required');
0 ignored issues
show
Documentation introduced by
'redis.sorted_set_member_form.score.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...
32
33
        if ($this->member !== null) {
34
            $form->setDefaults([
35
                'member' => $this->member,
36
                'score' => $this->connection->zscore($this->key, $this->member),
37
            ]);
38
        }
39
    }
40
41
    public function submit(Form $form, ArrayHash $values)
42
    {
43
        if ($this->member !== $values->member) {
44
            $this->connection->zrem($this->key, $this->member);
45
        }
46
        $this->connection->zadd($this->key, [$values->member => str_replace(',', '.', $values->score)]);
47
    }
48
}
49