PathHelper::getRoutesJs()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 6
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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