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

WatermarkFilter::windowsPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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($this->path, static::windowsPath($this->path), $commands[1]);
31
32
        return $commands;
33
    }
34
35
    private static function windowsPath(string $path): string
36
    {
37
        return '"' . str_replace('/', '\\', $path) . '"';
38
    }
39
}
40