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

UrlDecorator::value()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 12
nc 3
nop 1
dl 0
loc 25
rs 9.8666
c 1
b 0
f 0
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