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 |
||
13 | class MultiDomainAdminTwigExtension extends AbstractExtension |
||
14 | { |
||
15 | /** |
||
16 | * @var DomainConfigurationInterface |
||
17 | */ |
||
18 | private $domainConfiguration; |
||
19 | |||
20 | public function __construct(DomainConfigurationInterface $domainConfiguration) |
||
24 | |||
25 | /** |
||
26 | * Get Twig functions defined in this extension. |
||
27 | * |
||
28 | * @return array |
||
|
|||
29 | */ |
||
30 | View Code Duplication | public function getFunctions() |
|
39 | |||
40 | /** |
||
41 | * Render multidomain switcher widget. |
||
42 | * |
||
43 | * @param Environment $env |
||
44 | * @param string $route The route |
||
45 | * @param array $parameters The route parameters |
||
46 | * |
||
47 | * @return string |
||
48 | */ |
||
49 | public function renderWidget(Environment $env, $route, array $parameters = []) |
||
50 | { |
||
51 | $template = $env->load( |
||
52 | '@KunstmaanAdmin/MultiDomainAdminTwigExtension/widget.html.twig' |
||
53 | ); |
||
54 | |||
55 | return $template->render( |
||
56 | \array_merge( |
||
57 | $parameters, [ |
||
58 | 'hosts' => $this->getAdminDomainHosts(), |
||
59 | 'route' => $route, |
||
60 | ] |
||
61 | ) |
||
62 | ); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Check if site is multiDomain |
||
67 | * |
||
68 | * @return bool |
||
69 | */ |
||
70 | public function isMultiDomainSite() |
||
74 | |||
75 | /** |
||
76 | * @return array|null |
||
77 | */ |
||
78 | public function getSwitchedHost() |
||
82 | |||
83 | /** |
||
84 | * @return bool |
||
85 | */ |
||
86 | public function switchedHostIsCurrent() |
||
92 | |||
93 | /** |
||
94 | * @return array |
||
95 | */ |
||
96 | public function getAdminDomainHosts() |
||
100 | } |
||
101 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.