Completed
Push — master ( 36af8e...9a1b95 )
by Sebastian
01:54
created

call_user_func_array()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 42
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 26
nc 1
nop 2
dl 0
loc 42
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of SebastianFeldmann\Ftp.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace SebastianFeldmann\Ftp;
11
12
/**
13
 * Mock internal ftp_connect.
14
 *
15
 * @param  string $host
16
 * @param  string $port
17
 * @return array
18
 */
19
function ftp_connect($host, $port)
20
{
21
    return ['host' => $host, 'port' => $port];
22
}
23
24
/**
25
 * Mock internal ftp_login.
26
 *
27
 * @param  array  $connection
28
 * @param  string $user
29
 * @param  string $password
30
 * @return bool
31
 * @throws \Exception
32
 */
33
function ftp_login($connection, $user, $password)
34
{
35
    if ($connection['host'] != 'example.com') {
36
        throw new \Exception('invalid connection');
37
    }
38
    if ($connection['port'] != 21) {
39
        throw new \Exception('invalid connection');
40
    }
41
    if (empty($user)) {
42
        throw new \Exception('invalid user');
43
    }
44
    if (empty($password)) {
45
        throw new \Exception('invalid password');
46
    }
47
    return true;
48
}
49
50
/**
51
 * Mock internal call_user_func_array.
52
 *
53
 * @param  string $name
54
 * @param  array  $args
55
 * @return bool
56
 */
57
function call_user_func_array($name, $args)
58
{
59
    static $iterations;
60
61
    $iteration = $iterations[$name] ?? 0;
62
    $iterations[$name]++;
63
64
    $return = [
65
        'ftp_nlist' => [
66
            ['foo.txt', 'bar.txt', 'fiz', 'baz'],
67
        ],
68
        'ftp_pwd'   => [
69
            '/root',
70
        ],
71
        'ftp_chdir' => [
72
            false,
73
            false,
74
            true,
75
            true,
76
            true,
77
            true,
78
        ],
79
        'ftp_mdtm' => [
80
            '20180101123055',
81
            '20180101123056',
82
            '20180101123057',
83
            '20180101123058'
84
        ],
85
        'ftp_size' => [
86
            100,
87
            200,
88
            1,
89
            1,
90
            1,
91
            1,
92
        ],
93
        'ftp_put' => [
94
            true,
95
        ],
96
    ];
97
98
    return $return[$name][$iteration] ?? true;
99
}
100