Test Failed
Pull Request — develop (#380)
by Felipe
04:11
created

dump()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * PHPPgAdmin 6.1.3
5
 */
6
7
foreach (['logs', 'sessions', 'twigcache'] as $tempFolder) {
8
    if (!\is_writable(\sprintf('%s/temp/%s', \dirname(__DIR__), $tempFolder))) {
9
        die(\sprintf('The folder temp/%s must be writable', $tempFolder));
10
    }
11
}
12
13
require_once \dirname(__DIR__) . '/vendor/autoload.php';
14
15
\defined('BASE_PATH') || \define('BASE_PATH', \dirname(__DIR__));
16
17
\defined('THEME_PATH') || \define('THEME_PATH', \dirname(__DIR__) . '/assets/themes');
18
// Enforce PHP environment
19
\ini_set('arg_separator.output', '&amp;');
20
\defined('ADODB_ERROR_HANDLER_TYPE') || \define('ADODB_ERROR_HANDLER_TYPE', \E_USER_ERROR);
21
\defined('ADODB_ERROR_HANDLER') || \define('ADODB_ERROR_HANDLER', '\PHPPgAdmin\ADOdbException::adodb_throw');
22
23
$shouldSetSession = (\defined('PHP_SESSION_ACTIVE') ? \PHP_SESSION_ACTIVE !== \session_status() : !\session_id())
24
    && !\headers_sent()
25
    && !\ini_get('session.auto_start');
26
27
if ($shouldSetSession && \PHP_SAPI !== 'cli') {
28
    \session_set_cookie_params(0, '/', $_SERVER['HTTP_HOST'], isset($_SERVER['HTTPS']));
29
    \session_name('PPA_ID');
30
    \session_start();
31
}
32
33
\defined('ADODB_ASSOC_CASE') || \define('ADODB_ASSOC_CASE', ADODB_ASSOC_CASE_NATIVE);
34
35
$app = getAppInstance();
36
$container = $app->getContainer();
37
38
// If no dump function has been globally declared at this point
39
// we fill the gap with an empty one to avoid errors 
40
if(!function_exists('dump')) {
41
    function dump(...$args):void {
0 ignored issues
show
Unused Code introduced by
The parameter $args 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

41
    function dump(/** @scrutinizer ignore-unused */ ...$args):void {

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...
42
        // do nothing
43
    }
44
}
45
46
// Set the requestobj and responseobj properties of the container
47
// as the value of $request and $response, which already contain the route
48
$app->add(new \PHPPgAdmin\Middleware\PopulateRequestResponse($container));
49
50
if (!isset($msg)) {
51
    $msg = '';
52
}
53
$container['msg'] = $msg;
54
//ddd($container->misc);
55
56
$app->get('/status', function (
57
    \Slim\Http\Request $request,
58
    \Slim\Http\Response $response,
59
    array $args
0 ignored issues
show
Unused Code introduced by
The parameter $args 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

59
    /** @scrutinizer ignore-unused */ array $args

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...
60
) {
61
    return $response
62
        ->withHeader('Content-type', 'application/json')
63
        ->withJson(
64
            $this->get('settings')['debug'] ? $this->get('settings')->all() : ['version' => $this->version]
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
65
        );
66
});
67
68
$app->post('/login', function (
69
    \Slim\Http\Request $request,
70
    \Slim\Http\Response $response,
71
    array $args
0 ignored issues
show
Unused Code introduced by
The parameter $args 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

71
    /** @scrutinizer ignore-unused */ array $args

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...
72
) {
73
    $body = $response->getBody();
74
    $misc = $this->misc;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
75
76
    $loginShared = $request->getParsedBodyParam('loginShared');
77
    $loginServer = $request->getParsedBodyParam('loginServer');
78
    $loginUsername = $request->getParsedBodyParam('loginUsername');
79
    $loginPassword = $request->getParsedBodyParam('loginPassword_' . \md5($loginServer));
80
81
    // If login action is set, then set session variables
82
    if ((bool) $loginServer && (bool) $loginUsername && null !== $loginPassword) {
83
        $_server_info = $this->misc->getServerInfo($loginServer);
84
85
        $_server_info['username'] = $loginUsername;
86
        $_server_info['password'] = $loginPassword;
87
88
        $this->misc->setServerInfo(null, $_server_info, $loginServer);
89
90
        $data = $misc->getDatabaseAccessor();
91
92
        if (null === $data) {
93
            //ddd($misc->getErrorMsg());
94
            $login_controller = new \PHPPgAdmin\Controller\LoginController($this, true);
0 ignored issues
show
Unused Code introduced by
The call to PHPPgAdmin\Controller\Lo...ntroller::__construct() has too many arguments starting with true. ( Ignorable by Annotation )

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

94
            $login_controller = /** @scrutinizer ignore-call */ new \PHPPgAdmin\Controller\LoginController($this, true);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
95
            $body->write($login_controller->doLoginForm($misc->getErrorMsg()));
96
97
            return $response;
98
        }
99
        // Check for shared credentials
100
        if (null !== $loginShared) {
101
            $_SESSION['sharedUsername'] = $loginUsername;
102
            $_SESSION['sharedPassword'] = $loginPassword;
103
        }
104
105
        $this->view->setReloadBrowser(true);
106
        $this->addFlash(true, 'reload_browser');
107
108
        $destinationurl = $this->getDestinationWithLastTab('alldb');
109
110
        return $response->withStatus(302)->withHeader('Location', $destinationurl);
111
    }
112
    $_server_info = $this->misc->getServerInfo();
113
114
    if (!isset($_server_info['username'])) {
115
        $destinationurl = $this->getDestinationWithLastTab('server');
116
117
        return $response->withStatus(302)->withHeader('Location', $destinationurl);
118
    }
119
});
120
121
$app->get('/redirect[/{subject}]', function (
122
    \Slim\Http\Request $request,
123
    \Slim\Http\Response $response,
124
    array $args
125
) {
126
    $subject = (isset($args['subject'])) ? $args['subject'] : 'root';
127
    $destinationurl = $this->getDestinationWithLastTab($subject);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
128
    $cleanDestination=($this->subFolder.'/'. $destinationurl);
129
    
130
     return $response->withStatus(302)->withHeader('Location',$cleanDestination);
131
});
132
133
ini_set('display_errors','on');
134
$app->get('/{subject:servers|intro|browser}[/{server_id}]', function (
135
    \Slim\Http\Request $request,
136
    \Slim\Http\Response $response,
137
    array $args
138
) {
139
    $subject = $args['subject'] ?? 'intro';
140
    $this->view->offsetSet('includeJsTree',true);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
141
    $className = '\PHPPgAdmin\Controller\\' . \ucfirst($subject) . 'Controller';
142
    $controller = new $className($this);
143
    return $controller->render();
144
 
145
    
146
});
147
148
149
$app->map(['GET', 'POST'], '/src/views/{subject}', function (
150
    \Slim\Http\Request $request,
151
    \Slim\Http\Response $response,
152
    array $args
153
) {
154
    $subject = $args['subject'];
155
    $nextPath=$this->subFolder.'/'. $subject;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
156
    $query_string = $request->getUri()->getQuery();
157
return $response->withStatus(302)->withHeader('Location',$nextPath.($query_string? '?'.$query_string:'')); 
158
});
159
160
$app->get('/{subject:\w+}[/{server_id}]', function (
161
    \Slim\Http\Request $request,
162
    \Slim\Http\Response $response,
163
    array $args
164
) {
165
    $subject = $args['subject'] ?? 'intro';
166
    $server_id = $args['server_id'] ?? $request->getQueryParam('server');
167
    $_server_info = $this->misc->getServerInfo();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
168
    if (!isset($_server_info['username'])) {
169
        $subject = 'login';
170
    }
171
172
    if ('login' === $subject && null === $server_id) {
173
        $subject = 'servers';
174
    }
175
    $query_string = $request->getUri()->getQuery();
0 ignored issues
show
Unused Code introduced by
The assignment to $query_string is dead and can be removed.
Loading history...
176
    $this->view->offsetSet('includeJsTree',true);
177
    $className = $this->view->getControllerClassName($subject);
178
    $controller = new $className($this);
179
    return $controller->render();
180
181
});
182
183
$app->get('/', function (
184
    \Slim\Http\Request $request,
185
    \Slim\Http\Response $response,
0 ignored issues
show
Unused Code introduced by
The parameter $response 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

185
    /** @scrutinizer ignore-unused */ \Slim\Http\Response $response,

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...
186
    array $args
0 ignored issues
show
Unused Code introduced by
The parameter $args 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

186
    /** @scrutinizer ignore-unused */ array $args

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...
187
) {
188
    $subject = 'intro';
189
    $query_string = $request->getUri()->getQuery();
0 ignored issues
show
Unused Code introduced by
The assignment to $query_string is dead and can be removed.
Loading history...
190
    $className = $this->view->getControllerClassName($subject);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
191
    $controller = new $className($this);
192
    return $controller->render();
193
});
194
195
$app->get('[/{path:.*}]', function (
196
    \Slim\Http\Request $request,
197
    \Slim\Http\Response $response,
198
    array $args
199
) {
200
    return $response->write(sprintf("We couldn't find a route matching %s", $args['path'] ? $args['path'] : 'index'));
201
});
202
203
// Run app
204
$app->run();
205