Test Failed
Pull Request — develop (#380)
by Felipe
03:42
created

UrlDecorator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 36
rs 10
c 1
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A value() 0 25 4
1
<?php
2
3
/**
4
 * PHPPgAdmin 6.1.3
5
 */
6
7
namespace PHPPgAdmin\Decorators;
8
9
class UrlDecorator extends Decorator
10
{
11
    public function __construct($base, $queryVars = null)
12
    {
13
        $this->base = $base;
14
15
        if (null !== $queryVars) {
16
            $this->queryVars = $queryVars;
17
        }
18
    }
19
20
    public function value($fields)
21
    {
22
        $url = Decorator::get_sanitized_value($this->base, $fields);
23
24
        if (false === $url) {
25
            return '';
26
        }
27
28
        if (!empty($this->queryVars)) {
29
            $queryVars = Decorator::get_sanitized_value($this->queryVars, $fields);
30
31
            $sep = '?';
32
            \ksort($queryVars);
33
34
            foreach ($queryVars as $var => $value) {
35
                $url .= $sep . Decorator::value_url($var, $fields) . '=' . Decorator::value_url($value, $fields);
36
                $sep = '&';
37
            }
38
        }
39
40
        
41
            $url = \str_replace('//', '/', \containerInstance()->subFolder . '/' . $url);
42
        
43
44
        return $url;
45
    }
46
}
47