Completed
Pull Request — master (#5)
by Nikola
01:17
created

AbstractHttpEmitter::sendHeaders()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 2
nop 0
crap 12
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WeCodeIn\ErrorHandling\Emitter;
6
7
use Throwable;
8
9
abstract class AbstractHttpEmitter extends AbstractEmitter
10
{
11
    public function __invoke(Throwable $throwable) : Throwable
12
    {
13
        $this->sendHeaders();
14
15
        return parent::__invoke($throwable);
16
    }
17
18
    protected function sendHeaders() : void
19
    {
20
        if (!isset($_SERVER["REQUEST_URI"]) || headers_sent()) {
21
            return;
22
        }
23
24
        http_response_code(500);
25
26
        header("Content-Type: {$this->getContentType()}");
27
    }
28
29
    abstract protected function getContentType() : string;
30
}
31