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

DataTypeAbstract   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 38
rs 10
c 1
b 0
f 1
wmc 4
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A checkValidOptions() 0 9 3
A throwException() 0 9 1
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