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

RegexConfig   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getObject() 0 4 1
A getArray() 0 8 1
A config() 0 9 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Everlution\Navigation\Factory\Build\Hydrator\Match;
6
7
use Everlution\Navigation\Voter\Regex\RegexMatch;
8
9
/**
10
 * Class RegexConfig.
11
 * @author Ivan Barlog <[email protected]>
12
 */
13
class RegexConfig extends MatchConfig
14
{
15
    const OPTION_PATTERN = 'pattern';
16
    const OPTION_MODIFIERS = 'modifiers';
17
18
    /**
19
     * @param string $className
20
     * @param array $arguments
21
     * @return RegexMatch
22
     */
23
    protected function getObject(string $className, array $arguments)
24
    {
25
        return new $className($arguments[self::OPTION_PATTERN], $arguments[self::OPTION_MODIFIERS]);
26
    }
27
28
    /**
29
     * @param RegexMatch $item
30
     * @return array
31
     */
32
    protected function getArray($item): array
33
    {
34
        return [
35
            self::OPTION_CLASS => get_class($item),
36
            self::OPTION_PATTERN => $item->getPattern(),
37
            self::OPTION_MODIFIERS => $item->getModifiers(),
38
        ];
39
    }
40
41
    protected function config()
42
    {
43
        $this->resolver->setRequired(self::OPTION_PATTERN);
44
        $this->resolver->setDefault(self::OPTION_MODIFIERS, '');
45
        $this->resolver->setAllowedTypes(self::OPTION_PATTERN, 'string');
46
        $this->resolver->setAllowedTypes(self::OPTION_MODIFIERS, 'string');
47
48
        $this->supportedClasses[] = RegexMatch::class;
49
    }
50
}
51