Passed
Push — master ( 4a1742...ff2740 )
by Alec
03:07 queued 34s
created

ACharPalette::getSequence()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Spinner\Core\Palette\A;
6
7
use AlecRabbit\Spinner\Core\Contract\ICharFrame;
8
use AlecRabbit\Spinner\Core\Palette\Contract\ICharPalette;
9
use AlecRabbit\Spinner\Core\Palette\Contract\IPaletteMode;
10
use AlecRabbit\Spinner\Core\Palette\Contract\IPaletteOptions;
11
use AlecRabbit\Spinner\Core\Palette\PaletteOptions;
0 ignored issues
show
Bug introduced by
The type AlecRabbit\Spinner\Core\Palette\PaletteOptions 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...
12
use Traversable;
13
14
abstract class ACharPalette extends APalette implements ICharPalette
15
{
16
    /**
17
     * @return Traversable<ICharFrame>
18
     */
19
    protected function getEntries(?IPaletteMode $mode = null): Traversable
20
    {
21
        /** @var string $element */
22
        foreach ($this->getSequence() as $element) {
23
            yield $this->createFrame($element);
0 ignored issues
show
Bug introduced by
$element of type Traversable|array is incompatible with the type string expected by parameter $element of AlecRabbit\Spinner\Core\...rPalette::createFrame(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
            yield $this->createFrame(/** @scrutinizer ignore-type */ $element);
Loading history...
24
        }
25
    }
26
27
    protected function getSequence(): Traversable
28
    {
29
        $sequence = $this->sequence();
30
31
        if ($this->options->getReversed()) {
32
            $sequence = array_reverse(iterator_to_array($sequence));
33
        }
34
35
        yield from $sequence;
36
    }
37
38
    /**
39
     * @return Traversable<string>
40
     */
41
    abstract protected function sequence(): Traversable;
42
43
    abstract protected function createFrame(string $element): ICharFrame;
44
45
    protected function getOptions(?IPaletteMode $mode = null): IPaletteOptions
46
    {
47
        $this->options =
48
            new PaletteOptions(
49
                interval: $this->options->getInterval() ?? $this->getInterval(),
50
                reversed: $this->options->getReversed(),
51
            );
52
53
        return parent::getOptions($mode);
54
    }
55
56
    protected function getInterval(): ?int
57
    {
58
        return 100;
59
    }
60
}
61