UrlModifyFunction   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 20%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 5
dl 0
loc 29
ccs 2
cts 10
cp 0.2
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 15 3
A get() 0 4 1
1
<?php
2
3
namespace BZIon\Twig;
4
5
class UrlModifyFunction
6
{
7
    /**
8
     * Modify the current page URL
9
     *
10
     * @param  array  $parameters An array of parameters to add/modify in the request
11
     * @return string The HTML link
12
     */
13
    public function __invoke(array $parameters)
14
    {
15
        $attributes = \Service::getRequest()->attributes;
16
        $query = \Service::getRequest()->query;
17
18
        $parameters = $parameters + $attributes->get('_route_params') + $query->all();
19
20
        foreach ($parameters as $key => $value) {
21
            if (empty($value)) {
22
                unset($parameters[$key]);
23
            }
24
        }
25
26
        return \Service::getGenerator()->generate($attributes->get('_route'), $parameters);
27
    }
28
29 1
    public static function get()
30
    {
31 1
        return new \Twig_SimpleFunction('url_modify', new self());
32
    }
33
}
34