Passed
Pull Request — master (#265)
by Pascal
02:26
created

WatermarkFilter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 11
c 3
b 0
f 0
dl 0
loc 27
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A normalizePath() 0 3 2
A getCommands() 0 11 1
1
<?php
2
3
namespace ProtoneMedia\LaravelFFMpeg\Filters;
4
5
use FFMpeg\Filters\Video\WatermarkFilter as FFMpegWatermarkFilter;
6
7
/**
8
 * Partly based on this PR:
9
 * https://github.com/PHP-FFMpeg/PHP-FFMpeg/pull/754/files
10
 */
11
class WatermarkFilter extends FFMpegWatermarkFilter
12
{
13
    protected $path;
14
15
    public function __construct($watermarkPath, array $coordinates = [], $priority = 0)
16
    {
17
        parent::__construct($watermarkPath, $coordinates, $priority);
18
19
        $this->path = $watermarkPath;
20
    }
21
22
    protected function getCommands()
23
    {
24
        $commands = parent::getCommands();
25
26
        $commands[1] = str_replace(
27
            $this->path,
28
            static::normalizePath($this->path),
29
            $commands[1]
30
        );
31
32
        return $commands;
33
    }
34
35
    public static function normalizePath(string $path): string
36
    {
37
        return  windows_os() ? str_replace('/', '\\', $path) : $path;
38
    }
39
}
40