Completed
Push — master ( 5354de...c65a1a )
by Alec
03:20 queued 50s
created

AbstractFormatter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 5
dl 0
loc 21
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A assertData() 0 4 2
A __construct() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Traits\ForReports\Core;
4
5
use AlecRabbit\Traits\ForReports\Contracts\FormatterInterface;
6
7
abstract class AbstractFormatter implements FormatterInterface
8
{
9
    /** @var int */
10
    protected $options = 0;
11
12
    /** {@inheritDoc} */
13
    public function __construct(?int $options = null)
14
    {
15
        $this->options = $options ?? 0;
16
    }
17
18
    abstract public function process(Formattable $data): string;
19
20
    /**
21
     * @param Formattable $data
22
     * @param string $class
23
     */
24
    protected function assertData(Formattable $data, string $class): void
25
    {
26
        if (!$data instanceof $class) {
27
            throw new \InvalidArgumentException($class . ' expected, ' . get_class($data) . ' given');
28
        }
29
    }
30
}
31