Streamer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 8
c 0
b 0
f 0
dl 0
loc 28
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setSong() 0 10 3
A __construct() 0 4 1
1
<?php
2
3
namespace App\Services\Streamers;
4
5
use App\Models\Song;
6
7
class Streamer
8
{
9
    /**
10
     * @var Song|string
11
     */
12
    protected $song;
13
14
    /**
15
     * @var string
16
     */
17
    protected $contentType;
18
19 11
    public function __construct()
20
    {
21
        // Turn off error reporting to make sure our stream isn't interfered.
22 11
        @error_reporting(0);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition for error_reporting(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

22
        /** @scrutinizer ignore-unhandled */ @error_reporting(0);

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
23 11
    }
24
25 6
    public function setSong(Song $song): void
26
    {
27 6
        $this->song = $song;
28
29 6
        abort_unless($this->song->s3_params || file_exists($this->song->path), 404);
30
31
        // Hard code the content type instead of relying on PHP's fileinfo()
32
        // or even Symfony's MIMETypeGuesser, since they appear to be wrong sometimes.
33 6
        if (!$this->song->s3_params) {
34 5
            $this->contentType = 'audio/'.pathinfo($this->song->path, PATHINFO_EXTENSION);
35
        }
36 6
    }
37
}
38