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

PHPStreamer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 25
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B stream() 0 22 6
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