Passed
Push — master ( 20e747...679572 )
by Ivan
01:59
created

RegexNavigationItem   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getObject() 8 8 1
A getArray() 10 10 1
A config() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Everlution\Navigation\Factory\Build\Hydrator;
6
7
use Everlution\Navigation\Factory\Build\NavigationItemConfig;
8
use Everlution\Navigation\RegexNavigationItem as RegexItem;
9
10
/**
11
 * Class RegexNavigationItem.
12
 * @author Ivan Barlog <[email protected]>
13
 */
14 View Code Duplication
class RegexNavigationItem extends NavigationItemConfig
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
{
16
    const OPTION_REGEX_PATTERN = 'regexPattern';
17
    const OPTION_REGEX_MODIFIERS = 'regexModifiers';
18
19
    /**
20
     * @param string $className
21
     * @param array $arguments
22
     * @return RegexItem
23
     */
24
    protected function getObject(string $className, array $arguments)
25
    {
26
        return new $className(
27
            $arguments[self::OPTION_LABEL],
28
            $arguments[self::OPTION_REGEX_PATTERN],
29
            $arguments[self::OPTION_REGEX_MODIFIERS]
30
        );
31
    }
32
33
    /**
34
     * @param RegexItem $item
35
     * @return array
36
     */
37
    protected function getArray($item): array
38
    {
39
        return [
40
            self::OPTION_CLASS => get_class($item),
41
            self::OPTION_LABEL => $item->getLabel(),
42
            self::OPTION_REGEX_PATTERN => $item->getRegexPattern(),
43
            self::OPTION_REGEX_MODIFIERS => $item->getRegexModifiers(),
44
            self::OPTION_CHILDREN => [],
45
        ];
46
    }
47
48
    protected function config()
49
    {
50
        $this->resolver->remove(self::OPTION_IDENTIFIER);
51
        $this->resolver->setRequired([self::OPTION_REGEX_PATTERN]);
52
        $this->resolver->setDefault(self::OPTION_REGEX_MODIFIERS, '');
53
        $this->resolver->setAllowedTypes(self::OPTION_REGEX_PATTERN, 'string');
54
        $this->resolver->setAllowedTypes(self::OPTION_REGEX_MODIFIERS, 'string');
55
56
        $this->supportedClasses[] = RegexItem::class;
57
    }
58
}
59