Passed
Push — master ( 71496d...2fe95c )
by Alec
02:26
created

AbstractJuggler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
c 1
b 0
f 0
dl 0
loc 49
ccs 11
cts 11
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A calcFormatErasingShift() 0 3 1
A getFrameErasingLength() 0 3 1
A getStyledFrame() 0 4 1
A init() 0 5 1
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Spinner\Core\Jugglers;
4
5
use AlecRabbit\Accessories\Circular;
6
use AlecRabbit\Spinner\Core\Coloring\Scott;
7
use AlecRabbit\Spinner\Core\Jugglers\Contracts\JugglerInterface;
8
use AlecRabbit\Spinner\Settings\Contracts\Defaults;
9
10
abstract class AbstractJuggler implements JugglerInterface
11
{
12
    /** @var string */
13
    protected $spacer = Defaults::ONE_SPACE_SYMBOL;
14
15
    /** @var int */
16
    protected $currentFrameErasingLength;
17
    /** @var Circular */
18
    protected $style;
19
    /** @var int */
20
    protected $formatErasingShift;
21
22
    /** {@inheritDoc} */
23 23
    public function getFrameErasingLength(): int
24
    {
25 23
        return $this->currentFrameErasingLength;
26
    }
27
28
    /** {@inheritDoc} */
29 23
    public function getStyledFrame(): string
30
    {
31
        return
32 23
            sprintf((string)$this->style->value(), $this->getCurrentFrame()) . $this->spacer;
33
    }
34
35
36
    /**
37
     * @param string $format
38
     * @return int
39
     */
40 24
    protected function calcFormatErasingShift(string $format): int
41
    {
42 24
        return strlen(sprintf($format, ''));
43
    }
44
45
    /**
46
     * @param Scott $style
47
     */
48 24
    protected function init(Scott $style): void
49
    {
50 24
        $this->style = $style->getStyle();
51 24
        $this->formatErasingShift = $this->calcFormatErasingShift($style->getFormat());
52 24
        $this->spacer = $style->getSpacer();
53 24
    }
54
55
    /**
56
     * @return string
57
     */
58
    abstract protected function getCurrentFrame():string;
59
}
60