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

AReversiblePattern   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
c 2
b 0
f 0
dl 0
loc 23
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPattern() 0 6 2
A reversedPattern() 0 6 1
A __construct() 0 5 1
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