Passed
Push — master ( c03b7d...d95c98 )
by Sébastien
01:47
created

FFMpegProgress   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 4
eloc 14
dl 0
loc 28
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getProgress() 0 22 3
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 2
    public function __construct()
13
    {
14 2
    }
15
16 2
    public function getProgress(string $line): ?array
17
    {
18 2
        $line = str_replace(' ', '', $line);
19
20 2
        $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 2
        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 1
        return null;
38
    }
39
}
40