Emitter   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
eloc 15
dl 0
loc 36
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
__construct() 0 27 ?
emit() 0 3 ?
A hp$0 ➔ __construct() 0 3 3
A hp$0 ➔ emit() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Conia\Chuck\Http;
6
7
use Laminas\HttpHandlerRunner\Emitter\EmitterInterface;
8
use Laminas\HttpHandlerRunner\Emitter\EmitterStack;
9
use Laminas\HttpHandlerRunner\Emitter\SapiEmitter;
10
use Laminas\HttpHandlerRunner\Emitter\SapiStreamEmitter;
11
use Psr\Http\Message\ResponseInterface;
12
13
class Emitter implements EmitterInterface
14
{
15
    protected EmitterStack $stack;
16
17 14
    public function __construct(int $maxBufferLength = 8192)
18
    {
19 14
        $sapiStreamEmitter = new SapiStreamEmitter($maxBufferLength);
20 14
        $conditionalEmitter = new class ($sapiStreamEmitter) implements EmitterInterface {
21
            private $emitter;
22
23
            public function __construct(EmitterInterface $emitter)
24
            {
25 14
                $this->emitter = $emitter;
26
            }
27
28
            public function emit(ResponseInterface $response): bool
29
            {
30
                if (
31 14
                    !$response->hasHeader('Content-Disposition')
32 14
                    && !$response->hasHeader('Content-Range')
33
                ) {
34 13
                    return false;
35
                }
36
37 1
                return $this->emitter->emit($response);
38
            }
39 14
        };
40
41 14
        $this->stack = new EmitterStack();
42 14
        $this->stack->push(new SapiEmitter());
43 14
        $this->stack->push($conditionalEmitter);
44
    }
45
46 14
    public function emit(ResponseInterface $response): bool
47
    {
48 14
        return $this->stack->emit($response);
49
    }
50
}
51