Completed
Pull Request — master (#6)
by Michal
02:06
created

SortedSetBehavior::zrange()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 8
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 4
crap 2
1
<?php
2
3
namespace RedisProxy;
4
5
trait SortedSetBehavior
6
{
7
    /**
8
     * Add one or more members to a sorted set, or update its score if it already exists
9
     * @param string $key
10
     * @param array $dictionary (score1, member1[, score2, member2]) or associative array: [member1 => score1, member2 => score2]
11
     * @return int
12
     */
13 20
    public function zadd($key, ...$dictionary)
14
    {
15 20
        $this->init();
0 ignored issues
show
Bug introduced by
It seems like init() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
16 20
        if (is_array($dictionary[0])) {
17 12
            $return = 0;
18 12
            foreach ($dictionary[0] as $member => $score) {
19 12
                $res = $this->zadd($key, $score, $member);
20 12
                $return += $res;
21
            }
22 12
            return $return;
23
        }
24 20
        return $this->driver->zadd($key, ...$dictionary);
0 ignored issues
show
Bug introduced by
The property driver does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25
    }
26
27
    /**
28
     * Return a range of members in a sorted set, by index
29
     * @param string $key
30
     * @param int $start
31
     * @param int $stop
32
     * @param boolean $withscores
33
     * @return array
34
     */
35 4 View Code Duplication
    public function zrange($key, $start, $stop, $withscores = false)
36
    {
37 4
        $this->init();
0 ignored issues
show
Bug introduced by
It seems like init() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
38 4
        if ($this->actualDriver() === self::DRIVER_PREDIS) {
0 ignored issues
show
Bug introduced by
It seems like actualDriver() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
39 2
            return $this->driver->zrange($key, $start, $stop, ['WITHSCORES' => $withscores]);
40
        }
41 2
        return $this->driver->zrange($key, $start, $stop, $withscores);
42
    }
43
44
    /**
45
     * Return a range of members in a sorted set, by index, with scores ordered from high to low
46
     * @param string $key
47
     * @param int $start
48
     * @param int $stop
49
     * @param boolean $withscores
50
     * @return array
51
     */
52 4 View Code Duplication
    public function zrevrange($key, $start, $stop, $withscores = false)
53
    {
54 4
        $this->init();
0 ignored issues
show
Bug introduced by
It seems like init() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
55 4
        if ($this->actualDriver() === self::DRIVER_PREDIS) {
0 ignored issues
show
Bug introduced by
It seems like actualDriver() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
56 2
            return $this->driver->zrevrange($key, $start, $stop, ['WITHSCORES' => $withscores]);
57
        }
58 2
        return $this->driver->zrevrange($key, $start, $stop, $withscores);
59
    }
60
}
61