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

src/Iterators/IntSequenceIterator.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\Sequence\Iterators;
6
7
use Smoren\Sequence\Interfaces\SequenceIteratorInterface;
8
use Smoren\Sequence\Structs\IntSequence;
9
use Smoren\Sequence\Traits\SequenceIteratorTrait;
10
11
/**
12
 * @implements SequenceIteratorInterface<int>
13
 */
14
class IntSequenceIterator implements SequenceIteratorInterface
15
{
16
    /**
17
     * @use SequenceIteratorTrait<int>
18
     */
19
    use SequenceIteratorTrait;
20
21
    /**
22
     * @var IntSequence
23
     */
24
    protected IntSequence $sequence;
25
    /**
26
     * @var int
27
     */
28
    protected int $currentIndex;
29
30
    /**
31
     * @param IntSequence $range
32
     */
33 7
    public function __construct(IntSequence $range)
34
    {
35 7
        $this->sequence = $range;
36 7
        $this->currentIndex = 0;
37
    }
38
39
    /**
40
     * {@inheritDoc}
41
     * @return int
42
     */
43 7
    public function current(): int
44
    {
45 7
        return $this->sequence[$this->currentIndex];
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->sequence[$this->currentIndex] returns the type integer which is incompatible with the return type mandated by Smoren\Sequence\Interfac...torInterface::current() 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...
46
    }
47
}
48