Passed
Pull Request — master (#262)
by Pascal
11:01 queued 07:29
created

InteractsWithInputPath::mergeBeforePathInput()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 5
rs 10
1
<?php
2
3
namespace ProtoneMedia\LaravelFFMpeg\FFMpeg;
4
5
trait InteractsWithInputPath
6
{
7
    /**
8
     * Searches in the $input array for the key bu the $path, and then
9
     * prepend the $values in front of that key.
10
     *
11
     * @param array $input
12
     * @param string $path
13
     * @param array $values
14
     * @return array
15
     */
16
    protected static function mergeBeforePathInput(array $input, string $path, array $values = []): array
17
    {
18
        $key = array_search($path, $input) - 1;
19
20
        return static::mergeBeforeKey($input, $key, $values);
21
    }
22
23
    /**
24
     * Prepend the given $values in front of the $key in $input.
25
     *
26
     * @param array $input
27
     * @param integer $key
28
     * @param array $values
29
     * @return array
30
     */
31
    protected static function mergeBeforeKey(array $input, int $key, array $values = []): array
32
    {
33
        return array_merge(
34
            array_slice($input, 0, $key),
35
            $values,
36
            array_slice($input, $key)
37
        );
38
    }
39
}
40