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

FloatSequence::getNextValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\Sequence\Structs;
6
7
use Smoren\Sequence\Iterators\FloatSequenceIterator;
8
use Smoren\Sequence\Traits\SequenceTrait;
9
use Smoren\Sequence\Interfaces\SequenceInterface;
10
11
/**
12
 * @implements SequenceInterface<float>
13
 */
14
abstract class FloatSequence implements SequenceInterface
15
{
16
    use SequenceTrait;
17
18
    /**
19
     * @var float
20
     */
21
    protected float $start;
22
    /**
23
     * @var int<0, max>|null
24
     */
25
    protected ?int $size;
26
    /**
27
     * @var float
28
     */
29
    protected float $step;
30
31
    /**
32
     * @param float $start
33
     * @param int<0, max>|null $size
34
     * @param float $step
35
     */
36 6
    public function __construct(float $start, ?int $size, float $step = 1)
37
    {
38 6
        $this->start = $start;
39 6
        $this->size = $size;
40 6
        $this->step = $step;
41
    }
42
43
    /**
44
     * @param int $index
45
     * @return float
46
     */
47
    abstract public function getValueByIndex(int $index): float;
48
49
    /**
50
     * @return float
51
     */
52
    public function getStartValue(): float
53
    {
54
        return $this->getValueByIndex(0);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getValueByIndex(0) returns the type double 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...
55
    }
56
57
    /**
58
     * @param float $previousValue
59
     * @return float
60
     */
61 2
    public function getNextValue($previousValue): float
62
    {
63 2
        return $previousValue + $this->step;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $previousValue + $this->step returns the type double 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...
64
    }
65
66
    /**
67
     * {@inheritDoc}
68
     * @return float
69
     */
70 6
    public function offsetGet($offset): float
71
    {
72 6
        return $this->_offsetGet($offset);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->_offsetGet($offset) returns the type double which is incompatible with the return type mandated by Smoren\Sequence\Interfac...eInterface::offsetGet() 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...
73
    }
74
75
    /**
76
     * {@inheritDoc}
77
     */
78 5
    public function getIterator(): FloatSequenceIterator
79
    {
80 5
        return new FloatSequenceIterator($this);
81
    }
82
}
83