OptionsConfigurator   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 49
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
configureOptions() 0 1 ?
A offsetExists() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 0 8 2
A offsetUnset() 0 4 1
A getIterator() 0 4 1
A toArray() 0 4 1
1
<?php
2
3
namespace XHGui\Options;
4
5
use ArrayAccess;
6
use ArrayIterator;
7
use IteratorAggregate;
8
use Symfony\Component\OptionsResolver\OptionsResolver;
9
10
/**
11
 * @see https://symfony.com/doc/3.3/components/options_resolver.html
12
 */
13
abstract class OptionsConfigurator implements ArrayAccess, IteratorAggregate
14
{
15
    /** @var array */
16
    protected $options;
17
18
    public function __construct(array $options = [])
19
    {
20
        $resolver = new OptionsResolver();
21
        $this->configureOptions($resolver);
22
23
        $this->options = $resolver->resolve($options);
24
    }
25
26
    abstract protected function configureOptions(OptionsResolver $resolver);
27
28
    public function offsetExists($offset): bool
29
    {
30
        return array_key_exists($offset, $this->options);
31
    }
32
33
    public function offsetGet($offset)
34
    {
35
        return $this->options[$offset];
36
    }
37
38
    public function offsetSet($offset, $value): void
39
    {
40
        if (null === $offset) {
41
            $this->options[] = $value;
42
        } else {
43
            $this->options[$offset] = $value;
44
        }
45
    }
46
47
    public function offsetUnset($offset): void
48
    {
49
        unset($this->options[$offset]);
50
    }
51
52
    public function getIterator(): ArrayIterator
53
    {
54
        return new ArrayIterator($this->options);
55
    }
56
57
    public function toArray(): array
58
    {
59
        return $this->options;
60
    }
61
}
62