This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Psr7Middlewares\Middleware; |
||
4 | |||
5 | use Psr7Middlewares\Utils; |
||
6 | use Psr\Http\Message\ServerRequestInterface; |
||
7 | use Psr\Http\Message\ResponseInterface; |
||
8 | use Whoops\Run; |
||
9 | use Whoops\Handler\PrettyPageHandler; |
||
10 | use Whoops\Handler\PlainTextHandler; |
||
11 | use Whoops\Handler\JsonResponseHandler; |
||
12 | use Whoops\Handler\XmlResponseHandler; |
||
13 | |||
14 | /** |
||
15 | * Middleware to use whoops as error handler. |
||
16 | */ |
||
17 | class Whoops |
||
18 | { |
||
19 | use Utils\StreamTrait; |
||
20 | |||
21 | /** |
||
22 | * @var Run|null The provided instance of Whoops |
||
23 | */ |
||
24 | private $whoops; |
||
25 | |||
26 | /** |
||
27 | * @var bool Whether catch errors or not |
||
28 | */ |
||
29 | private $catchErrors = true; |
||
30 | |||
31 | /** |
||
32 | * Set the whoops instance. |
||
33 | * |
||
34 | * @param Run|null $whoops |
||
35 | */ |
||
36 | public function __construct(Run $whoops = null) |
||
37 | { |
||
38 | $this->whoops = $whoops; |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Whether catch errors or not. |
||
43 | * |
||
44 | * @param bool $catchErrors |
||
45 | * |
||
46 | * @return self |
||
47 | */ |
||
48 | public function catchErrors($catchErrors = true) |
||
49 | { |
||
50 | $this->catchErrors = (bool) $catchErrors; |
||
51 | |||
52 | return $this; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Execute the middleware. |
||
57 | * |
||
58 | * @param ServerRequestInterface $request |
||
59 | * @param ResponseInterface $response |
||
60 | * @param callable $next |
||
61 | * |
||
62 | * @return ResponseInterface |
||
63 | */ |
||
64 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
65 | { |
||
66 | ob_start(); |
||
67 | $level = ob_get_level(); |
||
68 | |||
69 | $method = Run::EXCEPTION_HANDLER; |
||
70 | $whoops = $this->getWhoopsInstance($request); |
||
71 | |||
72 | $whoops->allowQuit(false); |
||
73 | $whoops->writeToOutput(false); |
||
74 | $whoops->sendHttpCode(false); |
||
75 | |||
76 | //Catch errors means register whoops globally |
||
77 | if ($this->catchErrors) { |
||
78 | $whoops->register(); |
||
79 | } |
||
80 | |||
81 | try { |
||
82 | $response = $next($request, $response); |
||
83 | } catch (\Throwable $exception) { |
||
0 ignored issues
–
show
|
|||
84 | $body = self::createStream($response->getBody()); |
||
85 | $body->write($whoops->$method($exception)); |
||
86 | $response = $response->withStatus(500)->withBody($body); |
||
87 | } catch (\Exception $exception) { |
||
88 | $body = self::createStream($response->getBody()); |
||
89 | $body->write($whoops->$method($exception)); |
||
90 | $response = $response->withStatus(500)->withBody($body); |
||
91 | } finally { |
||
92 | Utils\Helpers::getOutput($level); |
||
93 | } |
||
94 | |||
95 | if ($this->catchErrors) { |
||
96 | $whoops->unregister(); |
||
97 | } |
||
98 | |||
99 | return $response; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Returns the whoops instance or create one. |
||
104 | * |
||
105 | * @param ServerRequestInterface $request |
||
106 | * |
||
107 | * @return Run |
||
108 | */ |
||
109 | private function getWhoopsInstance(ServerRequestInterface $request) |
||
110 | { |
||
111 | if ($this->whoops) { |
||
112 | return $this->whoops; |
||
113 | } |
||
114 | |||
115 | $whoops = new Run(); |
||
116 | |||
117 | if (php_sapi_name() === 'cli') { |
||
118 | $whoops->pushHandler(new PlainTextHandler()); |
||
0 ignored issues
–
show
new \Whoops\Handler\PlainTextHandler() is of type object<Whoops\Handler\PlainTextHandler> , but the function expects a callable .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
119 | |||
120 | return $whoops; |
||
121 | } |
||
122 | |||
123 | $format = FormatNegotiator::getFormat($request); |
||
124 | |||
125 | switch ($format) { |
||
126 | case 'json': |
||
127 | $whoops->pushHandler(new JsonResponseHandler()); |
||
0 ignored issues
–
show
new \Whoops\Handler\JsonResponseHandler() is of type object<Whoops\Handler\JsonResponseHandler> , but the function expects a callable .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
128 | break; |
||
129 | |||
130 | case 'html': |
||
131 | $whoops->pushHandler(new PrettyPageHandler()); |
||
0 ignored issues
–
show
new \Whoops\Handler\PrettyPageHandler() is of type object<Whoops\Handler\PrettyPageHandler> , but the function expects a callable .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
132 | break; |
||
133 | |||
134 | case 'xml': |
||
135 | $whoops->pushHandler(new XmlResponseHandler()); |
||
0 ignored issues
–
show
new \Whoops\Handler\XmlResponseHandler() is of type object<Whoops\Handler\XmlResponseHandler> , but the function expects a callable .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
136 | break; |
||
137 | |||
138 | case 'txt': |
||
139 | case 'css': |
||
140 | case 'js': |
||
141 | $whoops->pushHandler(new PlainTextHandler()); |
||
0 ignored issues
–
show
new \Whoops\Handler\PlainTextHandler() is of type object<Whoops\Handler\PlainTextHandler> , but the function expects a callable .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
142 | break; |
||
143 | |||
144 | default: |
||
145 | if (empty($format)) { |
||
146 | $whoops->pushHandler(new PrettyPageHandler()); |
||
0 ignored issues
–
show
new \Whoops\Handler\PrettyPageHandler() is of type object<Whoops\Handler\PrettyPageHandler> , but the function expects a callable .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
147 | } else { |
||
148 | $whoops->pushHandler(new PlainTextHandler()); |
||
0 ignored issues
–
show
new \Whoops\Handler\PlainTextHandler() is of type object<Whoops\Handler\PlainTextHandler> , but the function expects a callable .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
149 | } |
||
150 | |||
151 | break; |
||
152 | } |
||
153 | |||
154 | return $whoops; |
||
155 | } |
||
156 | } |
||
157 |
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.