miladrahimi /
phprouter
| 1 | <?php |
||
| 2 | |||
| 3 | namespace MiladRahimi\PhpRouter\Publisher; |
||
| 4 | |||
| 5 | use Psr\Http\Message\ResponseInterface; |
||
| 6 | |||
| 7 | /** |
||
| 8 | * It publishes responses provided by controllers and middleware as HTTP responses |
||
| 9 | */ |
||
| 10 | class HttpPublisher implements Publisher |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @inheritdoc |
||
| 14 | */ |
||
| 15 | public function publish($response): void |
||
| 16 | { |
||
| 17 | $output = fopen('php://output', 'a'); |
||
| 18 | |||
| 19 | if ($response instanceof ResponseInterface) { |
||
| 20 | http_response_code($response->getStatusCode()); |
||
| 21 | |||
| 22 | foreach ($response->getHeaders() as $name => $values) { |
||
| 23 | @header($name . ': ' . $response->getHeaderLine($name)); |
||
|
0 ignored issues
–
show
Are you sure the usage of
header($name . ': ' . $r...->getHeaderLine($name)) is correct as it 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 The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||
| 24 | } |
||
| 25 | |||
| 26 | fwrite($output, $response->getBody()); |
||
| 27 | } elseif (is_scalar($response)) { |
||
| 28 | fwrite($output, $response); |
||
| 29 | } elseif ($response === null) { |
||
| 30 | fwrite($output, ''); |
||
| 31 | } else { |
||
| 32 | fwrite($output, json_encode($response)); |
||
| 33 | } |
||
| 34 | |||
| 35 | fclose($output); |
||
| 36 | } |
||
| 37 | } |
||
| 38 |
If you suppress an error, we recommend checking for the error condition explicitly: