Code Duplication    Length = 45-45 lines in 2 locations

src/Factory/Build/Hydrator/RegexNavigationItem.php 1 location

@@ 14-58 (lines=45) @@
11
 * Class RegexNavigationItem.
12
 * @author Ivan Barlog <[email protected]>
13
 */
14
class RegexNavigationItem extends NavigationItemConfig
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

src/Factory/Build/Hydrator/RouteNavigationItem.php 1 location

@@ 14-58 (lines=45) @@
11
 * Class RouteNavigationItem.
12
 * @author Ivan Barlog <[email protected]>
13
 */
14
class RouteNavigationItem extends NavigationItemConfig
15
{
16
    const OPTION_ROUTE = 'route';
17
    const OPTION_PARAMETERS = 'parameters';
18
19
    /**
20
     * @param string $className
21
     * @param array $arguments
22
     * @return Routable
23
     */
24
    protected function getObject(string $className, array $arguments)
25
    {
26
        return new $className(
27
            $arguments[self::OPTION_LABEL],
28
            $arguments[self::OPTION_ROUTE],
29
            $arguments[self::OPTION_PARAMETERS]
30
        );
31
    }
32
33
    /**
34
     * @param Routable $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_ROUTE => $item->getRoute(),
43
            self::OPTION_PARAMETERS => $item->getParameters(),
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_ROUTE]);
52
        $this->resolver->setDefault(self::OPTION_PARAMETERS, []);
53
        $this->resolver->setAllowedTypes(self::OPTION_ROUTE, 'string');
54
        $this->resolver->setAllowedTypes(self::OPTION_PARAMETERS, 'array');
55
56
        $this->supportedClasses[] = Routable::class;
57
    }
58
}
59