Failed Conditions
Push — master ( 1f1533...4e2f19 )
by Sébastien
02:05
created

ScaleFilter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 21
dl 0
loc 55
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFFmpegCLIValue() 0 16 2
A __construct() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\MediaTools\Video\Filter;
6
7
use Soluble\MediaTools\Video\Filter\Type\FFMpegVideoFilterInterface;
8
9
class ScaleFilter implements FFMpegVideoFilterInterface
10
{
11
    public const OPTION_ASPECT_RATIO_INCREASE   = 'increase';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 1 space but found 3 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
12
    public const OPTION_ASPECT_RATIO_DECREASE   = 'decrease';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 1 space but found 3 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
13
14
    /**
15
     * Built-in aspect ratios.
16
     *
17
     * @var string[]
18
     */
19
    public const ASPECT_RATIO_MODES = [
20
        self::OPTION_ASPECT_RATIO_INCREASE,
21
        self::OPTION_ASPECT_RATIO_DECREASE,
22
    ];
23
24
    /** @var int|string */
25
    protected $height;
26
27
    /** @var int|string */
28
    protected $width;
29
30
    /** @var string|null */
31
    protected $aspect_ratio_mode;
32
33
    /**
34
     * Scale filter.
35
     *
36
     * @see https://trac.ffmpeg.org/wiki/Scaling
37
     *
38
     * @param string|int $width  as an int or any ffmpeg supported placeholder: iw*.5
39
     * @param string|int $height as an int or any ffmpeg supported placeholder: ih*2.3
40
     */
41 3
    public function __construct($width, $height, ?string $aspect_ratio_mode = null)
42
    {
43 3
        $this->width             = $width;
44 3
        $this->height            = $height;
45 3
        $this->aspect_ratio_mode = $aspect_ratio_mode;
46 3
    }
47
48 3
    public function getFFmpegCLIValue(): string
49
    {
50 3
        $scaleArg = sprintf(
51 3
            'scale=w=%s:h=%s',
52 3
            $this->width,
53 3
            $this->height
54
        );
55
56 3
        if ($this->aspect_ratio_mode !== null) {
57 2
            $scaleArg .= sprintf(
58 2
                ':force_original_aspect_ratio=%s',
59 2
                $this->aspect_ratio_mode
60
            );
61
        }
62
63 3
        return $scaleArg;
64
    }
65
}
66