Passed
Push — master ( c37170...fb5355 )
by Amin
02:31
created

Cloud   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A uploadDirectory() 0 8 3
A download() 0 6 2
A transfer() 0 7 3
1
<?php
2
3
/**
4
 * This file is part of the PHP-FFmpeg-video-streaming package.
5
 *
6
 * (c) Amin Yazdanpanah <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
13
namespace Streaming\Clouds;
14
15
16
use Streaming\Exception\InvalidArgumentException;
17
use Streaming\File;
18
19
class Cloud
20
{
21
    /**
22
     * @param array $clouds
23
     * @param string $tmp_dir
24
     */
25
    public static function uploadDirectory(array $clouds, string $tmp_dir): void
26
    {
27
        if (!is_array(current($clouds))) {
28
            $clouds = [$clouds];
29
        }
30
31
        foreach ($clouds as $cloud) {
32
            static::transfer($cloud, __FUNCTION__, $tmp_dir);
33
        }
34
    }
35
36
    /**
37
     * @param array $cloud
38
     * @param string|null $save_to
39
     * @return array
40
     */
41
    public static function download(array $cloud, string $save_to = null): array
42
    {
43
        list($save_to, $is_tmp) = $save_to ? [$save_to, false] : [File::tmpFile(), true];
44
        static::transfer($cloud, __FUNCTION__, $save_to);
45
46
        return [$save_to, $is_tmp];
47
    }
48
49
    /**
50
     * @param $cloud_c
51
     * @param $method
52
     * @param $path
53
     */
54
    private static function transfer(array $cloud_c, string $method, string $path): void
55
    {
56
        extract($cloud_c);
57
        if (isset($cloud) && $cloud instanceof CloudInterface) {
58
            call_user_func_array([$cloud, $method], [$path, $options ?? []]);
59
        } else {
60
            throw new InvalidArgumentException('The cloud key must be instance of the CloudInterface');
61
        }
62
    }
63
}