Passed
Pull Request — master (#86)
by Felipe
11:59 queued 07:50
created

index.php (26 issues)

1
<?php
2
3
/**
4
 * Single entrypoint of the app
5
 */
6
require_once './src/lib.inc.php';
7
8
$app->get('/status', function ($request, $response, $args) {
0 ignored issues
show
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

8
$app->get('/status', function ($request, $response, /** @scrutinizer ignore-unused */ $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...
9
    return $response
10
        ->withHeader('Content-type', 'application/json')
11
        ->withJson(['version' => $this->version]);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
12
});
13
14
$app->post('/redirect[/{subject}]', function ($request, $response, $args) {
0 ignored issues
show
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

14
$app->post('/redirect[/{subject}]', function ($request, $response, /** @scrutinizer ignore-unused */ $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...
15
    $body         = $response->getBody();
16
    $query_string = $request->getUri()->getQuery();
0 ignored issues
show
The assignment to $query_string is dead and can be removed.
Loading history...
17
    $misc         = $this->misc;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
18
19
    $loginShared   = $request->getParsedBodyParam('loginShared');
20
    $loginServer   = $request->getParsedBodyParam('loginServer');
21
    $loginUsername = $request->getParsedBodyParam('loginUsername');
22
    $loginPassword = $request->getParsedBodyParam('loginPassword_' . md5($loginServer));
23
24
    // If login action is set, then set session variables
25
    if (boolval($loginServer) && boolval($loginUsername) && $loginPassword !== null) {
26
        $_server_info = $this->misc->getServerInfo($loginServer);
27
28
        $_server_info['username'] = $loginUsername;
29
        $_server_info['password'] = $loginPassword;
30
31
        $this->misc->setServerInfo(null, $_server_info, $loginServer);
32
33
        $data = $misc->getDatabaseAccessor();
34
35
        if ($data === null) {
36
            $login_controller = new \PHPPgAdmin\Controller\LoginController($this, true);
37
            $body->write($login_controller->doLoginForm($misc->getErrorMsg()));
38
            return $response;
39
        }
40
        // Check for shared credentials
41
        if ($loginShared !== null) {
42
            $_SESSION['sharedUsername'] = $loginUsername;
43
            $_SESSION['sharedPassword'] = $loginPassword;
44
        }
45
46
        $misc->setReloadBrowser(true);
47
        $all_db_controller = new \PHPPgAdmin\Controller\AlldbController($this);
48
        return $all_db_controller->render();
49
    } else {
50
        $_server_info = $this->misc->getServerInfo();
51
52
        if (!isset($_server_info['username'])) {
53
            $destinationurl = $this->utils->getDestinationWithLastTab($subject);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $subject seems to be never defined.
Loading history...
54
            return $response->withStatus(302)->withHeader('Location', $destinationurl);
55
        }
56
    }
57
});
58
59
$app->get('/redirect[/{subject}]', function ($request, $response, $args) {
60
    $subject        = (isset($args['subject'])) ? $args['subject'] : 'root';
61
    $destinationurl = $this->utils->getDestinationWithLastTab($subject);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
62
    return $response->withStatus(302)->withHeader('Location', $destinationurl);
63
});
64
65
$app->get('/src/views/browser', function ($request, $response, $args) {
0 ignored issues
show
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

65
$app->get('/src/views/browser', function ($request, /** @scrutinizer ignore-unused */ $response, $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...
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

65
$app->get('/src/views/browser', function ($request, $response, /** @scrutinizer ignore-unused */ $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...
The parameter $request 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

65
$app->get('/src/views/browser', function (/** @scrutinizer ignore-unused */ $request, $response, $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...
66
    $controller = new \PHPPgAdmin\Controller\BrowserController($this, true);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
67
    return $controller->render();
1 ignored issue
show
Are you sure the usage of $controller->render() targeting PHPPgAdmin\Controller\BrowserController::render() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
68
});
69
70
$app->get('/src/views/login', function ($request, $response, $args) {
0 ignored issues
show
The parameter $request 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

70
$app->get('/src/views/login', function (/** @scrutinizer ignore-unused */ $request, $response, $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...
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

70
$app->get('/src/views/login', function ($request, $response, /** @scrutinizer ignore-unused */ $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...
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

70
$app->get('/src/views/login', function ($request, /** @scrutinizer ignore-unused */ $response, $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...
71
    $controller = new \PHPPgAdmin\Controller\LoginController($this, true);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
72
    return $controller->render();
73
});
74
75
$app->get('/src/views/servers', function ($request, $response, $args) {
0 ignored issues
show
The parameter $request 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

75
$app->get('/src/views/servers', function (/** @scrutinizer ignore-unused */ $request, $response, $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...
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

75
$app->get('/src/views/servers', function ($request, $response, /** @scrutinizer ignore-unused */ $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...
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

75
$app->get('/src/views/servers', function ($request, /** @scrutinizer ignore-unused */ $response, $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...
76
    $controller = new \PHPPgAdmin\Controller\ServersController($this, true);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
77
    return $controller->render();
78
});
79
80
$app->get('/src/views/intro', function ($request, $response, $args) {
0 ignored issues
show
The parameter $request 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

80
$app->get('/src/views/intro', function (/** @scrutinizer ignore-unused */ $request, $response, $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...
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

80
$app->get('/src/views/intro', function ($request, /** @scrutinizer ignore-unused */ $response, $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...
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

80
$app->get('/src/views/intro', function ($request, $response, /** @scrutinizer ignore-unused */ $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...
81
    $controller = new \PHPPgAdmin\Controller\IntroController($this, true);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
82
    return $controller->render();
83
});
84
85
$app->map(['GET', 'POST'], '/src/views/{subject}', function ($request, $response, $args) {
86
    if ($this->misc->getServerId() === null) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
87
        return $response->withStatus(302)->withHeader('Location', SUBFOLDER . '/src/views/servers');
88
    }
89
    $_server_info = $this->misc->getServerInfo();
90
91
    if (!isset($_server_info['username'])) {
92
        $destinationurl = SUBFOLDER . '/src/views/login?server=' . $this->misc->getServerId();
93
        return $response->withStatus(302)->withHeader('Location', $destinationurl);
94
    }
95
96
    $subject = $args['subject'];
97
98
    $className  = '\PHPPgAdmin\Controller\\' . ucfirst($subject) . 'Controller';
99
    $controller = new $className($this);
100
    return $controller->render();
101
});
102
103
$app->get('/[{subject}]', function ($request, $response, $args) {
104
    $subject      = (isset($args['subject'])) ? $args['subject'] : 'intro';
105
    $_server_info = $this->misc->getServerInfo();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $this seems to be never defined.
Loading history...
106
    $query_string = $request->getUri()->getQuery();
107
    $server_id    = $request->getQueryParam('server');
108
109
    if (!isset($_server_info['username']) && ($subject === 'server' || $subject === 'root')) {
110
        $subject = 'login';
111
    }
112
113
    if ($subject === 'login' && $server_id === null) {
114
        $subject = 'servers';
115
    }
116
117
    $viewVars = [
118
        'url'            => '/src/views/' . $subject . ($query_string ? '?' . $query_string : ''),
119
        'headertemplate' => 'header.twig',
120
    ];
121
122
    return $this->view->render($response, 'iframe_view.twig', $viewVars);
123
});
124
125
// Run app
126
$app->run();
127