Test Failed
Push — master ( 3eb0e4...9196b6 )
by Ivan
02:13
created

Config::resolve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Everlution\Navigation\Factory\Build;
6
7
use Symfony\Component\OptionsResolver\OptionsResolver;
8
9
/**
10
 * Class NavigationItemConfig.
11
 * @author Ivan Barlog <[email protected]>
12
 */
13
abstract class Config
14
{
15
    const OPTION_CLASS = 'class';
16
17
    /** @var OptionsResolver */
18
    protected $resolver;
19
    /** @var array */
20
    protected $supportedClasses = [];
21
22
    public function __construct()
23
    {
24
        $this->resolver = new OptionsResolver();
25
26
        $this->resolver->setRequired([self::OPTION_CLASS]);
27
        $this->resolver->setAllowedTypes(self::OPTION_CLASS, 'string');
28
29
        $this->config();
30
    }
31
32
    /**
33
     * @param string $className
34
     * @param array $arguments
35
     * @return mixed
36
     */
37
    abstract protected function getObject(string $className, array $arguments);
38
39
    /**
40
     * @param $object
41
     * @return array
42
     */
43
    abstract protected function getArray($object): array;
44
45
    /**
46
     * @param array $config
47
     * @return array
48
     */
49
    protected function resolve(array $config): array
50
    {
51
        return $this->resolver->resolve($config);
52
    }
53
54
    /**
55
     * @param string $class
56
     */
57
    protected function checkIfSupport(string $class)
58
    {
59
        if (false === in_array($class, $this->supportedClasses)) {
60
            throw new UnsupportedItemClassException($class, $this->supportedClasses);
61
        }
62
    }
63
64
    /**
65
     * Specifies additional options
66
     * This method is called after initial OptionsResolver setup
67
     * Use OptionsResolver within this method
68
     *
69
     * @return void
70
     */
71
    abstract protected function config();
72
73
    /**
74
     * @param array $config
75
     * @return string
76
     */
77
    protected function popClassName(array $config): string
78
    {
79
        $class = $config[self::OPTION_CLASS];
80
        unset($config[self::OPTION_CLASS]);
81
82
        return $class;
83
    }
84
}
85