Test Failed
Push — develop ( 981a06...fd5434 )
by Felipe
04:08
created

PopulateRequestResponse   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 36
dl 0
loc 70
rs 10
c 2
b 0
f 1
wmc 9

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 66 9
1
<?php
2
3
namespace PHPPgAdmin\Middleware;
4
5
/**
6
 * Set the requestobj and responseobj properties of the container
7
 * as the value of $request and $response, which already contain the route.
8
 */
9
class PopulateRequestResponse extends Middleware
10
{
11
    use \PHPPgAdmin\Traits\HelperTrait;
12
13
    public function __invoke(
14
        \Psr\Http\Message\ServerRequestInterface $request,
15
        \Psr\Http\Message\ResponseInterface $response,
16
        $next
17
    ) {
18
        $container                = $this->container;
19
        $container['requestobj']  = $request;
20
        $container['responseobj'] = $response;
21
22
        $container['server']   = $request->getParam('server');
0 ignored issues
show
Bug introduced by
The method getParam() does not exist on Psr\Http\Message\ServerRequestInterface. It seems like you code against a sub-type of Psr\Http\Message\ServerRequestInterface such as Slim\Http\Request. ( Ignorable by Annotation )

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

22
        /** @scrutinizer ignore-call */ 
23
        $container['server']   = $request->getParam('server');
Loading history...
23
        $container['database'] = $request->getParam('database');
24
        $container['schema']   = $request->getParam('schema');
25
        $misc                  = $container->get('misc');
26
27
        $misc->setHREF();
28
        $misc->setForm();
29
30
        $container->view->offsetSet('METHOD', $request->getMethod());
31
        if ($request->getAttribute('route')) {
32
            $container->view->offsetSet('subject', $request->getAttribute('route')->getArgument('subject'));
33
        }
34
35
        $query_string = $request->getUri()->getQuery();
36
        $container->view->offsetSet('query_string', $query_string);
37
        $path = (SUBFOLDER ? (SUBFOLDER . '/') : '') . $request->getUri()->getPath() . ($query_string ? '?' . $query_string : '');
38
        $container->view->offsetSet('path', $path);
39
40
        $params = $request->getParams();
0 ignored issues
show
Bug introduced by
The method getParams() does not exist on Psr\Http\Message\ServerRequestInterface. It seems like you code against a sub-type of Psr\Http\Message\ServerRequestInterface such as Slim\Http\Request. ( Ignorable by Annotation )

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

40
        /** @scrutinizer ignore-call */ 
41
        $params = $request->getParams();
Loading history...
41
42
        $viewparams = [];
43
44
        foreach ($params as $key => $value) {
45
            if (is_scalar($value)) {
46
                $viewparams[$key] = $value;
47
            }
48
        }
49
50
        if (isset($_COOKIE['IN_TEST'])) {
51
            $in_test = (string) $_COOKIE['IN_TEST'];
52
        } else {
53
            $in_test = '0';
54
        }
55
56
        // remove tabs and linebreaks from query
57
        if (isset($params['query'])) {
58
            $viewparams['query'] = str_replace(["\r", "\n", "\t"], ' ', $params['query']);
59
        }
60
        $container->view->offsetSet('params', $viewparams);
61
        $container->view->offsetSet('in_test', $in_test);
62
63
        if (count($container['errors']) > 0) {
64
            return ($container->haltHandler)($container->requestobj, $container->responseobj, $container['errors'], 412);
65
        }
66
67
        $messages = $container->flash->getMessages();
0 ignored issues
show
Unused Code introduced by
The assignment to $messages is dead and can be removed.
Loading history...
68
        /*if (!empty($messages)) {
69
        foreach ($messages as $key => $message) {
70
        $this->prtrace('Flash: ' . $key . ' =  ' . json_encode($message));
71
        }
72
        }*/
73
74
        // First execute anything else
75
        $response = $next($request, $response);
76
77
        // Any other request, pass on current response
78
        return $response;
79
    }
80
}
81