Passed
Push — release ( e4b72f...07d039 )
by Henry
09:15 queued 06:21
created

src/Responders/MediaBuilder.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * This file is part of the Divergence package.
4
 *
5
 * (c) Henry Paradiz <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Divergence\Responders;
12
13
use GuzzleHttp\Psr7\Utils;
14
use Psr\Http\Message\StreamInterface;
15
16
class MediaBuilder extends ResponseBuilder
17
{
18
    private ?int $start;
19
    private ?int $end;
20
    private ?int $length;
21
22 5
    public function setRange($start, $end, $length)
23
    {
24 5
        $this->start = $start;
25 5
        $this->end = $end;
26 5
        $this->length = $length;
27
    }
28
29 12
    public function setContentType(string $contentType): void
30
    {
31 12
        $this->contentType = $contentType;
32
    }
33
34 10
    public function getBody(): StreamInterface
35
    {
36 10
        if (isset($this->start)) {
37 5
            $fp = fopen($this->template, 'r');
38 5
            fseek($fp, $this->start);
0 ignored issues
show
It seems like $this->start can also be of type null; however, parameter $offset of fseek() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

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

38
            fseek($fp, /** @scrutinizer ignore-type */ $this->start);
Loading history...
39 5
            $stream = Utils::streamFor($fp);
40 5
            return Utils::streamFor($stream->getContents());
41
        }
42 5
        return Utils::streamFor(fopen($this->template, 'r'));
43
    }
44
}
45