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

AbstractFormatter::assertData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
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