Passed
Push — develop ( 9a0eb6...39df77 )
by Felipe
05:13
created

ContainerUtils::prtrace()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
1
<?php
2
3
/**
4
 * PHPPgAdmin v6.0.0-beta.43
5
 */
6
7
namespace PHPPgAdmin;
8
9
/**
10
 * @file
11
 * A class that adds convenience methods to the container
12
 */
13
14
/**
15
 * A class that adds convenience methods to the container.
16
 *
17
 * @package PHPPgAdmin
18
 */
19
class ContainerUtils
20
{
21
    use \PHPPgAdmin\Traits\HelperTrait;
1 ignored issue
show
introduced by
The trait PHPPgAdmin\Traits\HelperTrait requires some properties which are not provided by PHPPgAdmin\ContainerUtils: $responseobj, $requestobj
Loading history...
22
23
    private $container;
0 ignored issues
show
Coding Style introduced by
Private member variable "container" must be prefixed with an underscore
Loading history...
24
25
    public function __construct($container)
26
    {
27
        $this->container = $container;
28
    }
29
30
    public function getRedirectUrl($subject = '')
0 ignored issues
show
Unused Code introduced by
The parameter $subject is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

30
    public function getRedirectUrl(/** @scrutinizer ignore-unused */ $subject = '')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
    {
32
        $query_string = $this->container->requestobj->getUri()->getQuery();
33
34
        // but if server_id isn't set, then you will be redirected to intro
35
        if ($this->container->requestobj->getQueryParam('server') === null) {
36
            $destinationurl = \SUBFOLDER . '/src/views/intro';
37
        } else {
38
            $destinationurl = \SUBFOLDER . '/src/views/login' . ($query_string ? '?' . $query_string : '');
39
        }
40
41
        return $destinationurl;
42
    }
43
44
    public function getDestinationWithLastTab($subject)
45
    {
46
        $_server_info = $this->container->misc->getServerInfo();
47
        //$this->prtrace('$_server_info', $_server_info);
48
        // If username isn't set in server_info, you should login
49
        if (!isset($_server_info['username'])) {
50
            $destinationurl = $this->getRedirectUrl();
51
        } else {
52
            $url = $this->container->misc->getLastTabURL($subject);
53
            //$this->prtrace('getLastTabURL for ' . $subject, $url);
54
            // Load query vars into superglobal arrays
55
            if (isset($url['urlvars'])) {
56
                $urlvars = [];
57
                foreach ($url['urlvars'] as $key => $urlvar) {
58
                    //$this->prtrace($key, $urlvar);
59
                    $urlvars[$key] = \PHPPgAdmin\Decorators\Decorator::get_sanitized_value($urlvar, $_REQUEST);
60
                }
61
                $_REQUEST = array_merge($_REQUEST, $urlvars);
62
                $_GET     = array_merge($_GET, $urlvars);
63
            }
64
65
            $actionurl      = \PHPPgAdmin\Decorators\Decorator::actionurl($url['url'], $_GET);
66
            $destinationurl = $actionurl->value($_GET);
67
        }
68
        $destinationurl = str_replace('views/?', "views/{$subject}?", $destinationurl);
69
        //$this->prtrace('destinationurl for ' . $subject, $destinationurl);
70
        return $destinationurl;
71
    }
72
73
    public function addError($errormsg)
74
    {
75
        $errors   = $this->container->get('errors');
76
        $errors[] = $errormsg;
77
        $this->container->offsetSet('errors', $errors);
78
79
        return $this->container;
80
    }
81
82
}
83