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 |
||
10 | class MultiDomainAdminTwigExtension extends Twig_Extension |
||
|
|||
11 | { |
||
12 | /** |
||
13 | * @var DomainConfigurationInterface |
||
14 | */ |
||
15 | private $domainConfiguration; |
||
16 | |||
17 | public function __construct(DomainConfigurationInterface $domainConfiguration) |
||
21 | |||
22 | /** |
||
23 | * Get Twig functions defined in this extension. |
||
24 | * |
||
25 | * @return array |
||
26 | */ |
||
27 | View Code Duplication | public function getFunctions() |
|
28 | { |
||
29 | return [ |
||
30 | new Twig_SimpleFunction('multidomain_widget', [$this, 'renderWidget'], ['needs_environment' => true, 'is_safe' => ['html']]), |
||
31 | new Twig_SimpleFunction('is_multidomain_site', [$this, 'isMultiDomainSite']), |
||
32 | new Twig_SimpleFunction('get_switched_host', [$this, 'getSwitchedHost']), |
||
33 | new Twig_SimpleFunction('switched_host_is_current', [$this, 'switchedHostIsCurrent']), |
||
34 | ]; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Render multidomain switcher widget. |
||
39 | * |
||
40 | * @param Twig_Environment $env |
||
41 | * @param string $route The route |
||
42 | * @param array $parameters The route parameters |
||
43 | * |
||
44 | * @return string |
||
45 | */ |
||
46 | View Code Duplication | public function renderWidget(Twig_Environment $env, $route, array $parameters = []) |
|
47 | { |
||
48 | $template = $env->loadTemplate( |
||
49 | '@KunstmaanAdmin/MultiDomainAdminTwigExtension/widget.html.twig' |
||
50 | ); |
||
51 | |||
52 | return $template->render( |
||
53 | \array_merge( |
||
54 | $parameters, [ |
||
55 | 'hosts' => $this->getAdminDomainHosts(), |
||
56 | 'route' => $route, |
||
57 | ] |
||
58 | ) |
||
59 | ); |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Check if site is multiDomain |
||
64 | * |
||
65 | * @return bool |
||
66 | */ |
||
67 | public function isMultiDomainSite() |
||
68 | { |
||
69 | return $this->domainConfiguration->isMultiDomainHost(); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * @return array|null |
||
74 | */ |
||
75 | public function getSwitchedHost() |
||
76 | { |
||
77 | return $this->domainConfiguration->getHostSwitched(); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @return bool |
||
82 | */ |
||
83 | public function switchedHostIsCurrent() |
||
84 | { |
||
85 | $hostInfo = $this->getSwitchedHost(); |
||
86 | |||
87 | return $this->domainConfiguration->getHost() === $hostInfo['host']; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @return array |
||
92 | */ |
||
93 | public function getAdminDomainHosts() |
||
97 | } |
||
98 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.