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

StyleRenderer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 17
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A render() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
6
namespace AlecRabbit\Spinner\Extras\Render;
7
8
use AlecRabbit\Spinner\Exception\InvalidArgumentException;
9
use AlecRabbit\Spinner\Extras\Contract\IStyleToAnsiStringConverter;
10
use AlecRabbit\Spinner\Extras\Contract\Style\IStyle;
11
use AlecRabbit\Spinner\Extras\Render\Contract\IStyleRenderer;
12
13
final class StyleRenderer implements IStyleRenderer
14
{
15
    public function __construct(
16
        protected IStyleToAnsiStringConverter $converter,
17
    ) {
18
    }
19
20
    /**
21
     * @throws InvalidArgumentException
22
     */
23
    public function render(IStyle $style): string
24
    {
25
        if ($style->isEmpty()) {
26
            throw new InvalidArgumentException('Style is empty.');
27
        }
28
29
        return $this->converter->convert($style);
30
    }
31
}
32