Passed
Push — master ( 3c333b...51dbda )
by Alec
01:37
created

AbstractFormatter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Accessories\Contracts;
4
5
use function AlecRabbit\typeOf;
6
7
abstract class AbstractFormatter implements FormatterInterface
8
{
9
    /** @var int */
10
    protected $options = 0;
11
12
    /**
13
     * @param mixed $options
14
     */
15 9
    public function __construct($options = null)
16
    {
17 9
        $this->assertOptions($options);
18 7
    }
19
20
    /**
21
     * @param mixed $options
22
     */
23 9
    protected function assertOptions($options): void
24
    {
25 9
        if (null !== $options && !is_int($options)) {
26 2
            throw new \RuntimeException(
27 2
                'Options for ' . __CLASS__ . ' constructor should be int, "' . typeOf($options) . '" given.'
28
            );
29
        }
30 7
    }
31
}
32