Passed
Branch master (a0cc06)
by Dāvis
17:06
created

Uri::redirect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sludio\HelperBundle\Openidconnect\Provider;
4
5
use Sludio\HelperBundle\Openidconnect\Component\Uriable;
6
use Symfony\Component\HttpFoundation\RedirectResponse;
7
8
class Uri implements Uriable
9
{
10
    private $url;
11
    private $base;
12
13
    protected $params;
14
    protected $urlParams;
15
16
    public function __construct(array $options, array $additional = [])
17
    {
18
        $this->base = rtrim($additional['base_uri'], '/').'/';
19
        unset($additional['base_uri']);
20
21
        $this->params = !empty($options['params']) ? $options['params'] : [];
22
        $this->urlParams = !empty($options['url_params']) ? array_merge($options['url_params'], $additional) : $additional;
23
    }
24
25
    public function redirect()
26
    {
27
        return new RedirectResponse($this->getUrl());
28
    }
29
30
    private function buildUrl()
31
    {
32
        $url = $this->base;
33
        if (!empty($this->params)) {
34
            $url .= implode('/', $this->params);
35
        }
36
        if (!empty($this->urlParams)) {
37
            $params = http_build_query($this->urlParams);
38
            $url .= '?'.$params;
39
        }
40
        $url = urldecode($url);
41
        $this->setUrl($url);
42
    }
43
44
    /**
45
     * Get the value of Url
46
     *
47
     * @return mixed
48
     */
49
    public function getUrl()
50
    {
51
        $this->buildUrl();
52
53
        return $this->url;
54
    }
55
56
    /**
57
     * Set the value of Url
58
     *
59
     * @param mixed url
0 ignored issues
show
Bug introduced by
The type Sludio\HelperBundle\Openidconnect\Provider\url was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
60
     *
61
     * @return self
62
     */
63
    public function setUrl($url)
64
    {
65
        $this->url = $url;
66
67
        return $this;
68
    }
69
70
    public function addParam($value)
71
    {
72
        $this->params[] = $value;
73
    }
74
75
    public function addUrlParam($name, $value)
76
    {
77
        $this->urlParams[$name] = $value;
78
    }
79
}
80