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\PrefixedNavigationItem as Prefixed; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class PrefixedNavigationItem. |
12
|
|
|
* @author Ivan Barlog <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class PrefixedNavigationItem extends NavigationItemConfig |
15
|
|
|
{ |
16
|
|
|
const OPTION_PREFIX = 'prefix'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param string $className |
20
|
|
|
* @param array $arguments |
21
|
|
|
* @return Prefixed |
22
|
|
|
*/ |
23
|
|
|
protected function getObject(string $className, array $arguments) |
24
|
|
|
{ |
25
|
|
|
return new $className( |
26
|
|
|
$arguments[self::OPTION_IDENTIFIER], |
27
|
|
|
$arguments[self::OPTION_LABEL], |
28
|
|
|
$arguments[self::OPTION_PREFIX] |
29
|
|
|
); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param Prefixed $item |
34
|
|
|
* @return array |
35
|
|
|
*/ |
36
|
|
View Code Duplication |
protected function getArray($item): array |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
return [ |
39
|
|
|
self::OPTION_CLASS => get_class($item), |
40
|
|
|
self::OPTION_LABEL => $item->getLabel(), |
41
|
|
|
self::OPTION_IDENTIFIER => $item->getUri(), |
42
|
|
|
self::OPTION_PREFIX => $item->getPrefix(), |
43
|
|
|
self::OPTION_CHILDREN => [], |
44
|
|
|
]; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
protected function config() |
48
|
|
|
{ |
49
|
|
|
$this->resolver->setRequired([self::OPTION_PREFIX]); |
50
|
|
|
$this->resolver->setAllowedTypes(self::OPTION_PREFIX, 'string'); |
51
|
|
|
|
52
|
|
|
$this->supportedClasses[] = Prefixed::class; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
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.