Issues (19)

src/Structs/Exponential.php (4 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\Sequence\Structs;
6
7
/**
8
 * Exponential sequence.
9
 *
10
 * @template T of int|float
11
 * @extends StepSequence<T>
12
 */
13
class Exponential extends StepSequence
14
{
15
    /**
16
     * Exponential constructor.
17
     *
18
     * @param T $start start of the sequence
19
     * @param int<0, max>|null $size size of the sequence (infinite if null)
20
     * @param T $step sequence step
0 ignored issues
show
The type Smoren\Sequence\Structs\T was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
     */
22 48
    public function __construct($start, ?int $size, $step)
23
    {
24 48
        parent::__construct($start, $size, $step);
25
    }
26
27
    /**
28
     * {@inheritDoc}
29
     */
30 32
    public function getValueByIndex(int $index)
31
    {
32 32
        if ((float)$this->step === 0.0 && $index < 0) {
0 ignored issues
show
The condition (double)$this->step === 0.0 is always false.
Loading history...
33 5
            throw new \DivisionByZeroError();
34
        }
35
36 32
        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...
37
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42 29
    public function getNextValue($previousValue)
43
    {
44 29
        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...
45
    }
46
}
47