WatermarkFilter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 13
dl 0
loc 53
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A normalizePath() 0 5 2
A normalizeWindowsPath() 0 7 1
A __construct() 0 5 1
A getCommands() 0 7 1
1
<?php
2
3
namespace ProtoneMedia\LaravelFFMpeg\Filters;
4
5
use FFMpeg\Filters\Video\WatermarkFilter as FFMpegWatermarkFilter;
6
7
class WatermarkFilter extends FFMpegWatermarkFilter
8
{
9
    protected $path;
10
11
    public function __construct($watermarkPath, array $coordinates = [], $priority = 0)
12
    {
13
        parent::__construct($watermarkPath, $coordinates, $priority);
14
15
        $this->path = $watermarkPath;
16
    }
17
18
    /**
19
     * Gets the commands from the base filter and normalizes the path.
20
     *
21
     * @return array
22
     */
23
    protected function getCommands()
24
    {
25
        $commands = parent::getCommands();
26
27
        $commands[1] = str_replace($this->path, static::normalizePath($this->path), $commands[1]);
28
29
        return $commands;
30
    }
31
32
    /**
33
     * Normalizes the path when running on Windows.
34
     *
35
     * @param string $path
36
     * @return string
37
     */
38
    public static function normalizePath(string $path): string
39
    {
40
        $path = windows_os() ? static::normalizeWindowsPath($path) : $path;
41
42
        return "'{$path}'";
43
    }
44
45
    /**
46
     * Replaces the slashes and escapes the colon. For some
47
     * reason, this filter doesn't work on Windows with
48
     * absolute paths that contain forward slashes.
49
     *
50
     * @param string $path
51
     * @return string
52
     */
53
    public static function normalizeWindowsPath(string $path): string
54
    {
55
        $path = str_replace('/', '\\', $path);
56
        $path = str_replace('\\', '\\\\', $path);
57
        $path = str_replace(':', '\\:', $path);
58
59
        return $path;
60
    }
61
}
62