Passed
Push — master ( 8dfa4a...e4531b )
by Smoren
02:19
created

IntRange   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 5
c 1
b 0
f 0
dl 0
loc 28
ccs 6
cts 6
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getValueByIndex() 0 3 1
A getNextValue() 0 3 1
A getStartValue() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\Sequence\Structs;
6
7
use Smoren\Sequence\Traits\SequenceTrait;
8
9
/**
10
 * {@inheritDoc}
11
 */
12
class IntRange extends IntSequence
13
{
14
    use SequenceTrait;
15
16
    /**
17
     * @param int $index
18
     * @return int
19
     */
20 7
    public function getValueByIndex(int $index): int
21
    {
22 7
        return $this->start + $index * $this->step;
23
    }
24
25
    /**
26
     * @return int
27
     */
28 4
    public function getStartValue(): int
29
    {
30 4
        return $this->getValueByIndex(0);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueByIndex(0) returns the type integer which is incompatible with the return type mandated by Smoren\Sequence\Interfac...erface::getStartValue() of Smoren\Sequence\Interfaces\T.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
31
    }
32
33
    /**
34
     * @param int $previousValue
35
     * @return int
36
     */
37 4
    public function getNextValue($previousValue): int
38
    {
39 4
        return $previousValue + $this->step;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $previousValue + $this->step returns the type integer which is incompatible with the return type mandated by Smoren\Sequence\Interfac...terface::getNextValue() of Smoren\Sequence\Interfaces\T.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
40
    }
41
}
42