Passed
Push — master ( e4531b...a6f95b )
by Smoren
02:40
created

Exponential::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 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
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
/**
8
 * @extends StepSequence<int|float>
9
 * {@inheritDoc}
10
 */
11
class Exponential extends StepSequence
12
{
13
    /**
14
     * @param int $index
15
     * @return float|int
16
     */
17 3
    public function getValueByIndex(int $index)
18
    {
19 3
        return $this->start * ($this->step ** $index);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->start * $this->step ** $index returns the type integer which is incompatible with the return type mandated by Smoren\Sequence\Interfac...face::getValueByIndex() 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...
20
    }
21
22
    /**
23
     * @param int $previousValue
24
     * @return int|float
25
     */
26 3
    public function getNextValue($previousValue)
27
    {
28 3
        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...
29
    }
30
}
31