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

WatermarkFilter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A windowsPath() 0 3 1
A getCommands() 0 15 2
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
        if (!windows_os()) {
27
            return $commands;
28
        }
29
30
        $commands[1] = str_replace(
31
            $this->path,
32
            static::windowsPath($this->path),
33
            $commands[1]
34
        );
35
36
        return $commands;
37
    }
38
39
    private static function windowsPath(string $path): string
40
    {
41
        return str_replace('/', '\\', $path);
42
    }
43
}
44