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

WatermarkFilter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 35
rs 10
c 3
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A normalizePath() 0 3 2
A getCommands() 0 11 1
A normalizeWindowsPath() 0 6 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() ? static::normalizeWindowsPath($path) : $path;
38
    }
39
40
    public static function normalizeWindowsPath(string $path): string
41
    {
42
        $path = str_replace('/', '\\', $path);
43
        $path = str_replace(':', '\\:', $path);
44
45
        return $path;
46
    }
47
}
48