Passed
Push — master ( 6993a9...874a26 )
by Sébastien
03:13 queued 17s
created

StreamableH264Preset::getParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 8
ccs 6
cts 6
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\MediaTools\Preset\MP4;
6
7
use Soluble\MediaTools\Preset\PresetInterface;
8
use Soluble\MediaTools\Video\VideoAnalyzerInterface;
9
use Soluble\MediaTools\Video\VideoConverterInterface;
10
use Soluble\MediaTools\Video\VideoConvertParams;
11
use Soluble\MediaTools\Video\VideoInfoReaderInterface;
12
13
class StreamableH264Preset implements PresetInterface
14
{
15
    /** @var VideoInfoReaderInterface */
16
    private $reader;
17
18
    /** @var VideoConverterInterface */
19
    private $converter;
20
21
    /** @var VideoAnalyzerInterface */
22
    private $analyzer;
23
24 1
    public function __construct(VideoInfoReaderInterface $reader, VideoConverterInterface $converter, VideoAnalyzerInterface $analyzer)
25
    {
26 1
        $this->converter = $converter;
27 1
        $this->reader    = $reader;
28 1
        $this->analyzer  = $analyzer;
29 1
    }
30
31 1
    public function convert(string $file, ?int $width = null, ?int $height = null): void
32
    {
33 1
        $info = $this->reader->getInfo($file);
34
35 1
        $vStream = $info->getVideoStreams()->getFirst();
36 1
        $aStream = $info->getAudioStreams()->getFirst();
0 ignored issues
show
Unused Code introduced by
The assignment to $aStream is dead and can be removed.
Loading history...
37
38 1
        $width  = $width ?? $vStream->getWidth();
39 1
        $height = $height ?? $vStream->getHeight();
40
41 1
        $params = $this->getParams($width, $height);
42
43 1
        $outputFile = sprintf('%s/%s.new.mp4', sys_get_temp_dir(), basename($file));
44
45
        $cb = function ($stderr, $stdin): void {
0 ignored issues
show
Unused Code introduced by
The parameter $stdin is not used and could be removed. ( Ignorable by Annotation )

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

45
        $cb = function ($stderr, /** @scrutinizer ignore-unused */ $stdin): void {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $stderr is not used and could be removed. ( Ignorable by Annotation )

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

45
        $cb = function (/** @scrutinizer ignore-unused */ $stderr, $stdin): void {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
46 1
            echo '.';
47 1
        };
48
49 1
        $this->converter->convert($file, $outputFile, $params, $cb);
50 1
    }
51
52 1
    public function getParams(int $width, int $height): VideoConvertParams
0 ignored issues
show
Unused Code introduced by
The parameter $height is not used and could be removed. ( Ignorable by Annotation )

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

52
    public function getParams(int $width, /** @scrutinizer ignore-unused */ int $height): VideoConvertParams

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $width is not used and could be removed. ( Ignorable by Annotation )

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

52
    public function getParams(/** @scrutinizer ignore-unused */ int $width, int $height): VideoConvertParams

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
53
    {
54 1
        $params = (new VideoConvertParams())
55 1
            ->withVideoCodec('libx264')
56 1
            ->withStreamable(true)
57 1
            ->withCrf(24);
58
59 1
        return $params;
60
    }
61
}
62