Completed
Push — master ( 94616b...d1942c )
by Sébastien
03:09
created

ProbeService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 27.78%

Importance

Changes 0
Metric Value
wmc 3
eloc 20
dl 0
loc 37
c 0
b 0
f 0
ccs 5
cts 18
cp 0.2778
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMediaInfo() 0 20 2
A __construct() 0 5 1
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 5
    public function __construct(FFProbeConfig $ffProbeConfig, FFMpegConfig $ffmpegConfig)
23
    {
24 5
        $this->ffprobeConfig = $ffProbeConfig;
25 5
        $this->ffmpegConfig  = $ffmpegConfig;
26 5
        $this->ffprobeConfig->getProcess()->ensureBinaryExists();
27 5
    }
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