PathHelper   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 77
Duplicated Lines 31.17 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 34.48%

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 0
dl 24
loc 77
ccs 10
cts 29
cp 0.3448
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A generateRoutes() 6 19 4
A getRoutesJs() 0 9 1
A getScriptTags() 9 9 2
A getStyleTags() 9 9 2

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 Liip\MonitorBundle\Helper;
4
5
class PathHelper
6
{
7
    protected $assetsHelper;
8
    protected $routerHelper;
9
10 1
    public function __construct($assetsHelper, $routerHelper)
11
    {
12 1
        $this->assetsHelper = $assetsHelper;
13 1
        $this->routerHelper = $routerHelper;
14 1
    }
15
16
    /**
17
     * @return array
18
     */
19 1
    public function generateRoutes(array $routes)
20
    {
21 1
        $ret = [];
22
23 1
        if (!method_exists($this->routerHelper, 'path')) {
24
            // symfony 2.7 and lower don't have the path method, BC layer
25 1 View Code Duplication
            foreach ($routes as $route => $params) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
26 1
                $ret[] = sprintf('api.%s = "%s";', $route, $this->routerHelper->generate($route, $params));
27
            }
28
29 1
            return $ret;
30
        }
31
32 View Code Duplication
        foreach ($routes as $route => $params) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
33
            $ret[] = sprintf('api.%s = "%s";', $route, $this->routerHelper->path($route, $params));
34
        }
35
36
        return $ret;
37
    }
38
39
    /**
40
     * @return string
41
     */
42
    public function getRoutesJs(array $routes)
43
    {
44
        $script = '<script type="text/javascript" charset="utf-8">';
45
        $script .= "var api = {};\n";
46
        $script .= implode("\n", $this->generateRoutes($routes));
47
        $script .= '</script>';
48
49
        return $script;
50
    }
51
52
    /**
53
     * @param string[] $paths
54
     *
55
     * @return string
56
     */
57 View Code Duplication
    public function getScriptTags(array $paths)
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...
58
    {
59
        $ret = '';
60
        foreach ($paths as $path) {
61
            $ret .= sprintf('<script type="text/javascript" charset="utf-8" src="%s"></script>%s', $this->assetsHelper->getUrl($path), "\n");
62
        }
63
64
        return $ret;
65
    }
66
67
    /**
68
     * @param string[] $paths
69
     *
70
     * @return string
71
     */
72 View Code Duplication
    public function getStyleTags(array $paths)
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...
73
    {
74
        $ret = '';
75
        foreach ($paths as $path) {
76
            $ret .= sprintf('<link rel="stylesheet" href="%s" type="text/css">%s', $this->assetsHelper->getUrl($path), "\n");
77
        }
78
79
        return $ret;
80
    }
81
}
82