1 | <?php |
||
2 | |||
3 | declare(strict_types = 1); |
||
4 | |||
5 | namespace App\Http; |
||
6 | |||
7 | use DarkMatter\Http\Response; |
||
8 | use DarkMatter\Payload\Payload; |
||
9 | use DarkMatter\Payload\Status; |
||
10 | use DarkMatter\Responder\HtmlResponder; |
||
11 | use DarkMatter\Components\PhtmlRenderer\Factory as RendererFactory; |
||
0 ignored issues
–
show
|
|||
12 | |||
13 | /** |
||
14 | * @property string $view |
||
15 | */ |
||
16 | |||
17 | class PayloadResponder extends HtmlResponder |
||
18 | { |
||
19 | /** |
||
20 | * @var \DarkMatter\Components\PhtmlRenderer\PhtmlRenderer $renderer |
||
0 ignored issues
–
show
The type
DarkMatter\Components\PhtmlRenderer\PhtmlRenderer was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
21 | */ |
||
22 | protected $renderer; |
||
23 | |||
24 | public function __construct(array $config) |
||
25 | { |
||
26 | $this->renderer = (new RendererFactory($config))->makeRenderer(); |
||
27 | parent::__construct($config); |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Generates a payload response. |
||
32 | * |
||
33 | * @param Payload $payload |
||
34 | * @return Response |
||
35 | */ |
||
36 | public function __invoke(Payload $payload): Response |
||
37 | { |
||
38 | $body = $this->renderer->render('logs', [ |
||
0 ignored issues
–
show
|
|||
39 | 'logs' => $data['logs'] ?? [], |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
40 | 'sources' => $data['sources'] ?? [], |
||
41 | 'levels' => $data['levels'] ?? [], |
||
42 | 'filters' => $data['filters'] ?? [] |
||
43 | ]); |
||
44 | |||
45 | ///return $this->found(['body' => $body]); |
||
46 | //exit; |
||
47 | // payload |
||
48 | $payloadResult = $payload->getResult(); |
||
49 | |||
50 | if ($payload->getStatus() === Status::FOUND) { |
||
51 | return $this->found($payloadResult); |
||
52 | } |
||
53 | |||
54 | return $this->error([$payloadResult['error'] ?? 'Unknown Error']); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Respond with an not found message. |
||
59 | * |
||
60 | * @return Response |
||
61 | */ |
||
62 | public function notFound(): Response |
||
63 | { |
||
64 | echo 'own notfound method'; |
||
65 | exit; |
||
0 ignored issues
–
show
In this branch, the function will implicitly return
null which is incompatible with the type-hinted return DarkMatter\Http\Response . Consider adding a return statement or allowing null as return value.
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: interface ReturnsInt {
public function returnsIntHinted(): int;
}
class MyClass implements ReturnsInt {
public function returnsIntHinted(): int
{
if (foo()) {
return 123;
}
// here: null is implicitly returned
}
}
![]() |
|||
66 | $this->response->setStatus(404); |
||
0 ignored issues
–
show
$this->response->setStatus(404) is not reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last ![]() |
|||
67 | $this->response->setBody('<html><title>404 Not found</title>404 Not found</html>'); |
||
68 | return $this->response; |
||
69 | } |
||
70 | |||
71 | |||
72 | |||
73 | |||
74 | |||
75 | |||
76 | } |
||
77 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths