Test Setup Failed
Branch master (86cd0f)
by Phan
05:16
created

PHPStreamer::stream()   B

Complexity

Conditions 6
Paths 16

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 0
cts 10
cp 0
rs 8.9457
c 0
b 0
f 0
cc 6
nc 16
nop 0
crap 42
1
<?php
2
3
namespace App\Services\Streamers;
4
5
use DaveRandom\Resume\FileResource;
6
use DaveRandom\Resume\InvalidRangeHeaderException;
7
use DaveRandom\Resume\NonExistentFileException;
8
use DaveRandom\Resume\RangeSet;
9
use DaveRandom\Resume\Resource;
10
use DaveRandom\Resume\ResourceServlet;
11
use DaveRandom\Resume\SendFileFailureException;
12
use DaveRandom\Resume\UnreadableFileException;
13
use DaveRandom\Resume\UnsatisfiableRangeException;
14
use function DaveRandom\Resume\get_request_header;
15
16
class PHPStreamer extends Streamer implements DirectStreamerInterface
17
{
18
    public function stream()
19
    {
20
        try {
21
            $rangeSet = RangeSet::createFromHeader(get_request_header('Range'));
22
            /** @var resource $resource */
23
            $resource = new FileResource($this->song->path, 'application/octet-stream');
24
            (new ResourceServlet($resource))->sendResource($rangeSet);
0 ignored issues
show
Documentation introduced by
$resource is of type resource, but the function expects a object<DaveRandom\Resume\Resource>.

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);
Loading history...
25
        } catch (InvalidRangeHeaderException $e) {
26
            abort(400);
27
        } catch (UnsatisfiableRangeException $e) {
28
            abort(416);
29
        } catch (NonExistentFileException $e) {
30
            abort(404);
31
        } catch (UnreadableFileException $e) {
32
            abort(500);
33
        } catch (SendFileFailureException $e) {
34
            abort_unless(headers_sent(), 500);
35
            echo "An error occurred while attempting to send the requested resource: {$e->getMessage()}";
36
        }
37
38
        exit;
39
    }
40
}
41