Failed Conditions
Push — master ( df4f19...50f2bb )
by Sébastien
02:46 queued 13s
created

ProbeService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\MediaTools\Video;
6
7
use Soluble\MediaTools\Config\FFMpegConfig;
8
use Soluble\MediaTools\Config\FFProbeConfig;
9
use Soluble\MediaTools\Util\Assert\PathAssertionsTrait;
10
use Soluble\MediaTools\VideoInfo;
11
12
class ProbeService implements ProbeServiceInterface
13
{
14
    use PathAssertionsTrait;
15
16
    /** @var FFProbeConfig */
17
    protected $ffprobeConfig;
18
19
    /** @var FFMpegConfig */
20
    protected $ffmpegConfig;
21
22
    public function __construct(FFProbeConfig $ffProbeConfig, FFMpegConfig $ffmpegConfig)
23
    {
24
        $this->ffprobeConfig = $ffProbeConfig;
25
        $this->ffmpegConfig  = $ffmpegConfig;
26
        $this->ffprobeConfig->getProcess()->ensureBinaryExists();
27
    }
28
29
    public function getMediaInfo(string $file): VideoInfo
30
    {
31
        $this->ensureFileExists($file);
32
        $process = $this->ffprobeConfig->getProcess();
33
        $cmd     = $process->buildCommand([
34
            '-v quiet',
35
            '-print_format json',
36
            '-show_format',
37
            '-show_streams',
38
            sprintf('-i "%s"', $file),
39
        ]);
40
41
        try {
42
            $jsonOutput = $process->runCommand($cmd);
43
        } catch (\Throwable $e) {
44
            //$msg = $e->getMessage();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
            throw $e;
46
        }
47
48
        return VideoInfo::createFromFFProbeJson($file, $jsonOutput);
49
    }
50
}
51