Passed
Push — master ( de3d61...be839c )
by Alec
13:42 queued 13s
created

StyleFrameRevolverFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 40
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createStyleRevolver() 0 11 1
A getTolerance() 0 4 1
A bakePattern() 0 9 2
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
6
namespace AlecRabbit\Spinner\Core\Factory;
7
8
use AlecRabbit\Spinner\Contract\Option\OptionStyleMode;
9
use AlecRabbit\Spinner\Contract\Pattern\IPattern;
10
use AlecRabbit\Spinner\Core\Factory\Contract\IFrameCollectionFactory;
11
use AlecRabbit\Spinner\Core\Factory\Contract\IIntervalFactory;
12
use AlecRabbit\Spinner\Core\Factory\Contract\IStyleFrameRevolverFactory;
13
use AlecRabbit\Spinner\Core\Pattern\BakedPattern;
0 ignored issues
show
Bug introduced by
The type AlecRabbit\Spinner\Core\Pattern\BakedPattern 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...
14
use AlecRabbit\Spinner\Core\Pattern\Contract\IBakedPattern;
15
use AlecRabbit\Spinner\Core\Pattern\Contract\IStylePattern;
16
use AlecRabbit\Spinner\Core\Pattern\NoStylePattern;
17
use AlecRabbit\Spinner\Core\Revolver\Contract\IFrameRevolver;
18
use AlecRabbit\Spinner\Core\Revolver\Contract\IFrameRevolverBuilder;
19
use AlecRabbit\Spinner\Core\Revolver\Contract\IRevolver;
20
21
final class StyleFrameRevolverFactory implements IStyleFrameRevolverFactory
22
{
23
    public function __construct(
24
        protected IFrameRevolverBuilder $frameRevolverBuilder,
25
        protected IFrameCollectionFactory $frameCollectionFactory,
26
        protected IIntervalFactory $intervalFactory,
27
        protected OptionStyleMode $styleMode,
28
    ) {
29
    }
30
31
    public function createStyleRevolver(IStylePattern $stylePattern): IFrameRevolver
32
    {
33
        $bakedPattern = $this->bakePattern($stylePattern);
34
        return
35
            $this->frameRevolverBuilder
36
                ->withFrameCollection($bakedPattern->getFrameCollection())
37
                ->withInterval($bakedPattern->getInterval())
38
                ->withTolerance(
39
                    $this->getTolerance()
40
                )
41
                ->build()
42
        ;
43
    }
44
45
    private function bakePattern(IPattern $pattern): IBakedPattern
46
    {
47
        if (OptionStyleMode::NONE === $this->styleMode) {
48
            $pattern = new NoStylePattern();
49
        }
50
        return
51
            new BakedPattern(
52
                frames: $this->frameCollectionFactory->create($pattern->getEntries($this->styleMode)),
0 ignored issues
show
Bug introduced by
The method getEntries() does not exist on AlecRabbit\Spinner\Contract\Pattern\IPattern. It seems like you code against a sub-type of AlecRabbit\Spinner\Contract\Pattern\IPattern such as AlecRabbit\Spinner\Core\...\Contract\IStylePattern or AlecRabbit\Spinner\Core\...n\Contract\ICharPattern or AlecRabbit\Spinner\Extra...re\A\AProceduralPattern or AlecRabbit\Spinner\Core\Pattern\A\AStylePattern or AlecRabbit\Spinner\Core\Pattern\A\ACharPattern or AlecRabbit\Spinner\Core\...n\Style\A\AStylePattern or AlecRabbit\Spinner\Core\Pattern\NoStylePattern or AlecRabbit\Spinner\Core\Pattern\NoCharPattern. ( Ignorable by Annotation )

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

52
                frames: $this->frameCollectionFactory->create($pattern->/** @scrutinizer ignore-call */ getEntries($this->styleMode)),
Loading history...
53
                interval: $this->intervalFactory->createNormalized($pattern->getInterval()),
54
            );
55
    }
56
57
    private function getTolerance(): int
58
    {
59
        // TODO (2023-04-26 14:21) [Alec Rabbit]: make it configurable [fd86d318-9069-47e2-b60d-a68f537be4a3]
60
        return IRevolver::TOLERANCE;
61
    }
62
}
63