Passed
Push — master ( ff4791...e25d55 )
by Sébastien
07:48
created

FFMpegProgress::getProgress()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.1406

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 22
ccs 9
cts 12
cp 0.75
rs 9.8333
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3.1406
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\MediaTools\Cli\Util;
6
7
use Soluble\MediaTools\Common\Exception\InvalidArgumentException;
8
use Soluble\MediaTools\Video\SeekTime;
9
10
class FFMpegProgress
11
{
12 1
    public function __construct()
13
    {
14 1
    }
15
16 1
    public function getProgress(string $line): ?array
17
    {
18 1
        $line = str_replace(' ', '', $line);
19
20 1
        $result = preg_match('/frame=(?P<frame>\d+)(.*)size=(?P<size>\d+(KB|MB|B))(.*)time=(?P<time>([0-9\.:]+))(.*)speed=(?P<speed>([0-9\.]+))x/i', $line, $matches);
21
22 1
        if ($result === 1) {
23
            try {
24 1
                $time = SeekTime::convertHMSmToSeconds($matches['time']);
25
            } catch (InvalidArgumentException $e) {
26
                $time = 0;
27
            }
28
29
            return [
30 1
                'frame' => (int) $matches['frame'],
31 1
                'size'  => $matches['size'],
32 1
                'time'  => $time,
33 1
                'speed' => (float) $matches['speed'],
34
            ];
35
        }
36
37
        return null;
38
    }
39
}
40