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

VideoInfoService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 3
eloc 17
dl 0
loc 40
ccs 14
cts 16
cp 0.875
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getMediaInfo() 0 20 2
A __construct() 0 3 1
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