Streamer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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