Completed
Push — master ( 0f407e...32a4d0 )
by Mehmet
04:33
created

DataTypeAbstract::checkValidOptions()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Selami\Entity\DataType;
5
6
use InvalidArgumentException;
7
8
abstract class DataTypeAbstract
9
{
10
    const INVALID_OPTIONS = 'Option: %s is invalid. You should remove it or check for typo.';
11
    /**
12
     * @var string
13
     */
14
    protected $key;
15
    /**
16
     * @var mixed
17
     */
18
    protected $datum;
19
    /**
20
     * @var array
21
     */
22
    protected $options = [];
23
24
    protected $errorMessageTemplate;
25
26
    protected function checkValidOptions(array $options)
27
    {
28
        $validOptions = array_keys($this::$defaults);
29
        foreach ($options as $optionKey => $optionValue) {
30
            if (!in_array($optionKey, $validOptions, true)) {
31
                throw new InvalidArgumentException(sprintf(self::INVALID_OPTIONS, $optionKey));
32
            }
33
        }
34
    }
35
36
    protected function throwException()
37
    {
38
        $message = sprintf(
39
            $this->errorMessageTemplate,
40
            $this->datum,
41
            $this->key
42
        );
43
        throw new InvalidArgumentException($message);
44
    }
45
}
46