Passed
Push — master ( 823aee...b9b37f )
by Alec
13:15 queued 12s
created

AReversiblePattern::getPattern()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
// 10.03.23
5
6
namespace AlecRabbit\Spinner\Core\Pattern\A;
7
8
use ArrayObject;
9
use Traversable;
10
11
abstract class AReversiblePattern extends APattern
12
{
13
    public function __construct(
14
        ?int $interval = null,
15
        protected bool $reversed = false
16
    ) {
17
        parent::__construct($interval);
18
    }
19
20
    public function getPattern(): Traversable
21
    {
22
        return
23
            $this->reversed
24
                ? $this->reversedPattern()
25
                : $this->pattern();
26
    }
27
28
    protected function reversedPattern(): Traversable
29
    {
30
        return
31
            new ArrayObject(
32
                array_reverse(
33
                    iterator_to_array($this->pattern())
34
                )
35
            );
36
    }
37
}
38