Failed Conditions
Push — master ( 25914a...598820 )
by Sébastien
02:52
created

ScaleFilter::getFFmpegCLIValue()   C

Complexity

Conditions 14
Paths 1

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 14

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 21
ccs 18
cts 18
cp 1
rs 6.2666
c 0
b 0
f 0
cc 14
nc 1
nop 0
crap 14

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\MediaTools\Video\Filter;
6
7
use Soluble\MediaTools\Video\Exception\ParamValidationException;
8
use Soluble\MediaTools\Video\Filter\Type\FFMpegVideoFilterInterface;
9
10
class ScaleFilter implements FFMpegVideoFilterInterface
11
{
12
    public const OPTION_ASPECT_RATIO_INCREASE = 'increase';
13
    public const OPTION_ASPECT_RATIO_DECREASE = 'decrease';
14
    public const OPTION_ASPECT_RATIO_DISABLE  = 'disable';
15
16
    /**
17
     * Built-in aspect ratios.
18
     *
19
     * @var string[]
20
     */
21
    public const ASPECT_RATIO_MODES = [
22
        self::OPTION_ASPECT_RATIO_INCREASE,
23
        self::OPTION_ASPECT_RATIO_DECREASE,
24
        self::OPTION_ASPECT_RATIO_DISABLE,
25
    ];
26
27
    /** @var int|string|null */
28
    protected $height;
29
30
    /** @var int|string|null */
31
    protected $width;
32
33
    /** @var string|null */
34
    protected $forceOriginalAspectRatio;
35
36
    /** @var string|null */
37
    protected $eval;
38
39
    /** @var int|null */
40
    protected $interl;
41
42
    /** @var string|null */
43
    protected $flags;
44
45
    /** @var float|null */
46
    protected $param0;
47
48
    /** @var float|null */
49
    protected $param1;
50
51
    /** @var string|null */
52
    protected $size;
53
54
    /** @var string|null */
55
    protected $inColorMatrix;
56
57
    /** @var string|null */
58
    protected $outColorMatrix;
59
60
    /** @var string|null */
61
    protected $inRange;
62
63
    /** @var string|null */
64
    protected $outRange;
65
66
    /**
67
     * Scale filter.
68
     *
69
     * @see https://trac.ffmpeg.org/wiki/Scaling
70
     * @see https://ffmpeg.org/ffmpeg-filters.html#scale-1
71
     *
72
     * @param string|int|null $width                    Set the output video width expression. Default value is the input width.
73
     * @param string|int|null $height                   Set the output video height expression. Default value is the input height.
74
     * @param string|null     $forceOriginalAspectRatio enable decreasing or increasing output video width or height if necessary to keep the original aspect ratio
75
     * @param string|null     $eval                     Specify when to evaluate width and height expression: 'init' or 'frame'
76
     * @param int|null        $interl                   Set the interlacing mode. It accepts the following values: ‘1’ Force interlaced aware scaling. ‘0’ Do not apply interlaced scaling. ‘-1’ Select interlaced aware scaling depending on whether the source frames are flagged as interlaced or not.
77
     * @param string|null     $flags                    Set libswscale scaling flags
78
     * @param float|null      $param0                   Set libswscale input parameters for scaling algorithms that need them
79
     * @param float|null      $param1                   Set libswscale input parameters for scaling algorithms that need them
80
     * @param string|null     $size                     set the video size
81
     * @param string|null     $inColorMatrix            set input YCbCr color space type
82
     * @param string|null     $outColorMatrix           set output YCbCr color space type
83
     * @param string|null     $inRange                  set intput YCbCr sample range
84
     * @param string|null     $outRange                 set output YCbCr sample range
85
     */
86 5
    public function __construct(
87
        $width = null,
88
        $height = null,
89
        string $forceOriginalAspectRatio = null,
90
        string $eval = null,
91
        int $interl = null,
92
        string $flags = null,
93
        float $param0 = null,
94
        float $param1 = null,
95
        string $size = null,
96
        string $inColorMatrix = null,
97
        string $outColorMatrix = null,
98
        string $inRange = null,
99
        string $outRange = null
100
    ) {
101 5
        if ($forceOriginalAspectRatio !== null &&
102 5
           !in_array($forceOriginalAspectRatio, self::ASPECT_RATIO_MODES, true)) {
103 1
            throw new ParamValidationException(sprintf(
104 1
                'Unsupported forceOriginalAspectRatio param: \'%s\'. Must be %s.',
105 1
                $forceOriginalAspectRatio,
106 1
                implode(' | ', self::ASPECT_RATIO_MODES)
107
            ));
108
        }
109 4
        $this->forceOriginalAspectRatio = $forceOriginalAspectRatio;
110
111 4
        $this->width          = $width;
112 4
        $this->height         = $height;
113 4
        $this->eval           = $eval;
114 4
        $this->interl         = $interl;
115 4
        $this->flags          = $flags;
116 4
        $this->param0         = $param0;
117 4
        $this->param1         = $param1;
118 4
        $this->size           = $size;
119 4
        $this->inColorMatrix  = $inColorMatrix;
120 4
        $this->outColorMatrix = $outColorMatrix;
121 4
        $this->inRange        = $inRange;
122 4
        $this->outRange       = $outRange;
123 4
    }
124
125 4
    public function getFFmpegCLIValue(): string
126
    {
127 4
        $args = array_filter([
128 4
            ($this->width !== null) ? "w={$this->width}" : false,
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $this instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
129 4
            ($this->height !== null) ? "h={$this->height}" : false,
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $this instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
130 4
            ($this->forceOriginalAspectRatio !== null) ? "force_original_aspect_ratio={$this->forceOriginalAspectRatio}" : false,
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $this instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
131 4
            ($this->eval !== null) ? "eval={$this->eval}" : false,
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $this instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
132 4
            ($this->interl !== null) ? "interl={$this->interl}" : false,
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $this instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
133 4
            ($this->flags !== null) ? "flags={$this->flags}" : false,
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $this instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
134 4
            ($this->param0 !== null) ? "param0={$this->param0}" : false,
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $this instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
135 4
            ($this->param1 !== null) ? "param1={$this->param1}" : false,
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $this instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
136 4
            ($this->size !== null) ? "size={$this->size}" : false,
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $this instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
137 4
            ($this->inColorMatrix !== null) ? "in_color_matrix={$this->inColorMatrix}" : false,
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $this instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
138 4
            ($this->outColorMatrix !== null) ? "out_color_matrix={$this->outColorMatrix}" : false,
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $this instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
139 4
            ($this->inRange !== null) ? "in_range={$this->inRange}" : false,
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $this instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
140 4
            ($this->outRange !== null) ? "out_range={$this->outRange}" : false,
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $this instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
141
        ]);
142
143 4
        return sprintf(
144 4
            'scale=%s',
145 4
            implode(':', $args)
146
        );
147
    }
148
}
149