Completed
Push — master ( ba8ed9...770316 )
by Jeroen
06:11
created

MultiDomainAdminTwigExtension   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 88
Duplicated Lines 28.41 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 25
loc 88
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getAdminDomainHosts() 0 4 1
A isMultiDomainSite() 0 4 1
A getSwitchedHost() 0 4 1
A getFunctions() 9 9 1
A renderWidget() 15 15 1
A switchedHostIsCurrent() 0 6 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
namespace Kunstmaan\AdminBundle\Twig;
4
5
use Kunstmaan\AdminBundle\Helper\DomainConfigurationInterface;
6
use Twig_Environment;
7
use Twig_Extension;
8
use Twig_SimpleFunction;
9
10
class MultiDomainAdminTwigExtension extends Twig_Extension
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Extension has been deprecated with message: since Twig 2.7, use "Twig\Extension\AbstractExtension" instead

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.

Loading history...
11
{
12
    /**
13
     * @var DomainConfigurationInterface
14
     */
15
    private $domainConfiguration;
16
17
    public function __construct(DomainConfigurationInterface $domainConfiguration)
18
    {
19
        $this->domainConfiguration = $domainConfiguration;
20
    }
21
22
    /**
23
     * Get Twig functions defined in this extension.
24
     *
25
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use Twig_SimpleFunction[].

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.

Loading history...
26
     */
27 View Code Duplication
    public function getFunctions()
0 ignored issues
show
Duplication introduced by
This method 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...
28
    {
29
        return [
30
            new Twig_SimpleFunction('multidomain_widget', [$this, 'renderWidget'], ['needs_environment' => true, 'is_safe' => ['html']]),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

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.

Loading history...
31
            new Twig_SimpleFunction('is_multidomain_site', [$this, 'isMultiDomainSite']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

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.

Loading history...
32
            new Twig_SimpleFunction('get_switched_host', [$this, 'getSwitchedHost']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

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.

Loading history...
33
            new Twig_SimpleFunction('switched_host_is_current', [$this, 'switchedHostIsCurrent']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

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.

Loading history...
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 = [])
0 ignored issues
show
Duplication introduced by
This method 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...
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()
94
    {
95
        return $this->domainConfiguration->getHosts();
96
    }
97
}
98