Completed
Push — master ( fc4224...debade )
by Sébastien
04:20
created

VideoInfoService::getMediaInfo()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2.0145

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 20
ccs 11
cts 13
cp 0.8462
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0145
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\MediaTools;
6
7
use Soluble\MediaTools\Config\FFProbeConfig;
8
use Soluble\MediaTools\Exception\FileNotFoundException;
9
use Soluble\MediaTools\Util\Assert\PathAssertionsTrait;
10
use Soluble\MediaTools\Video\InfoServiceInterface;
11
12
class VideoInfoService implements InfoServiceInterface
13
{
14
    use PathAssertionsTrait;
15
16
    /** @var FFProbeConfig */
17
    protected $ffprobeConfig;
18
19 2
    public function __construct(FFProbeConfig $ffProbeConfig)
20
    {
21 2
        $this->ffprobeConfig = $ffProbeConfig;
22 2
    }
23
24
    /**
25
     * @param string $file
26
     *
27
     * @return VideoInfo
28
     *
29
     * @throws FileNotFoundException
30
     * @throws \Throwable
31
     */
32 2
    public function getMediaInfo(string $file): VideoInfo
33
    {
34 2
        $this->ensureFileExists($file);
35 1
        $process = $this->ffprobeConfig->getProcess();
36 1
        $cmd     = $process->buildCommand([
37 1
            '-v quiet',
38 1
            '-print_format json',
39 1
            '-show_format',
40 1
            '-show_streams',
41 1
            sprintf('-i "%s"', $file),
42
        ]);
43
44
        try {
45 1
            $jsonOutput = $process->runCommand($cmd);
46
        } catch (\Throwable $e) {
47
            //$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...
48
            throw $e;
49
        }
50
51 1
        return VideoInfo::createFromFFProbeJson($file, $jsonOutput);
52
    }
53
}
54