GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Branch improve_design (cc6cfc)
by Yong
07:29
created

inDir()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 6
nc 5
nop 2
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace AlibabaCloud\Client;
4
5
use AlibabaCloud\Client\Exception\ClientException;
6
use Closure;
7
use League\CLImate\CLImate;
8
use Stringy\Stringy;
9
10
/*
11
|--------------------------------------------------------------------------
12
| Global Functions for Alibaba Cloud
13
|--------------------------------------------------------------------------
14
|
15
| Some common global functions are defined here.
16
| This file will be automatically loaded.
17
|
18
*/
19
20
/**
21
 * @param      $filename
22
 * @param bool $throwException
23
 *
24
 * @return bool
25
 * @throws ClientException
26
 */
27
function inOpenBasedir($filename, $throwException = false)
28
{
29
    $open_basedir = ini_get('open_basedir');
30
    if (!$open_basedir) {
31
        return true;
32
    }
33
34
    $dirs = explode(PATH_SEPARATOR, $open_basedir);
35
    if (empty($dirs)) {
36
        return true;
37
    }
38
39
    if (inDir($filename, $dirs)) {
40
        return true;
41
    }
42
43
    if ($throwException === false) {
44
        return false;
45
    }
46
47
    throw new ClientException(
48
        'open_basedir restriction in effect. '
49
        . "File($filename) is not within the allowed path(s): ($open_basedir)",
50
        'SDK.InvalidPath'
51
    );
52
}
53
54
/**
55
 * @param string $filename
56
 * @param array  $dirs
57
 *
58
 * @return bool
59
 */
60
function inDir($filename, array $dirs)
61
{
62
    foreach ($dirs as $dir) {
63
        if (!Stringy::create($dir)->endsWith(DIRECTORY_SEPARATOR)) {
64
            $dir .= DIRECTORY_SEPARATOR;
65
        }
66
        if (false !== strpos($filename, $dir)) {
67
            return true;
68
        }
69
    }
70
71
    return false;
72
}
73
74
/**
75
 * @return bool
76
 */
77
function isWindows()
78
{
79
    return PATH_SEPARATOR === ';';
80
}
81
82
/**
83
 * @return CLImate
84
 */
85
function cliMate()
86
{
87
    return new CLImate();
88
}
89
90
/**
91
 * @param string      $string
92
 * @param string|null $flank
93
 * @param string|null $char
94
 * @param int|null    $length
95
 *
96
 * @return void
97
 */
98
function backgroundRed($string, $flank = null, $char = null, $length = null)
99
{
100
    cliMate()->br();
101
    if ($flank !== null) {
102
        cliMate()->backgroundRed()->flank($flank, $char, $length);
103
        cliMate()->br();
104
    }
105
    cliMate()->backgroundRed($string);
106
    cliMate()->br();
107
}
108
109
/**
110
 * @param string      $string
111
 * @param string|null $flank
112
 * @param string|null $char
113
 * @param int|null    $length
114
 *
115
 * @return void
116
 */
117
function backgroundGreen($string, $flank = null, $char = null, $length = null)
118
{
119
    cliMate()->br();
120
    if ($flank !== null) {
121
        cliMate()->backgroundGreen()->flank($flank, $char, $length);
122
    }
123
    cliMate()->backgroundGreen($string);
124
    cliMate()->br();
125
}
126
127
/**
128
 * @param string      $string
129
 * @param string|null $flank
130
 * @param string|null $char
131
 * @param int|null    $length
132
 *
133
 * @return void
134
 */
135
function backgroundBlue($string, $flank = null, $char = null, $length = null)
136
{
137
    cliMate()->br();
138
    if ($flank !== null) {
139
        cliMate()->backgroundBlue()->flank($flank, $char, $length);
140
    }
141
    cliMate()->backgroundBlue($string);
142
    cliMate()->br();
143
}
144
145
/**
146
 * @param string      $string
147
 * @param string|null $flank
148
 * @param string|null $char
149
 * @param int|null    $length
150
 *
151
 * @return void
152
 */
153
function backgroundMagenta($string, $flank = null, $char = null, $length = null)
154
{
155
    cliMate()->br();
156
    if ($flank !== null) {
157
        cliMate()->backgroundMagenta()->flank($flank, $char, $length);
158
    }
159
    cliMate()->backgroundMagenta($string);
160
    cliMate()->br();
161
}
162
163
/**
164
 * @param array $array
165
 */
166
function json(array $array)
167
{
168
    cliMate()->br();
169
    cliMate()->backgroundGreen()->json($array);
170
    cliMate()->br();
171
}
172
173
/**
174
 * @param array $array
175
 *
176
 * @return void
177
 */
178
function redTable($array)
179
{
180
    /**
181
     * @noinspection PhpUndefinedMethodInspection
182
     */
183
    cliMate()->redTable($array);
184
}
185
186
/**
187
 * @param mixed  $result
188
 * @param string $title
189
 *
190
 * @return void
191
 */
192
function block($result, $title)
193
{
194
    cliMate()->backgroundGreen()->flank($title, '--', 20);
195
    dump($result);
196
}
197
198
/**
199
 * @param array $arrays
200
 *
201
 * @return array
202
 */
203
function arrayMerge(array $arrays)
204
{
205
    $result = [];
206
    foreach ($arrays as $array) {
207
        foreach ($array as $key => $value) {
208
            if (is_int($key)) {
209
                $result[] = $value;
210
                continue;
211
            }
212
213
            if (isset($result[$key]) && is_array($result[$key])) {
214
                $result[$key] = arrayMerge(
215
                    [$result[$key], $value]
216
                );
217
                continue;
218
            }
219
220
            $result[$key] = $value;
221
        }
222
    }
223
224
    return $result;
225
}
226
227
/**
228
 * Gets the value of an environment variable.
229
 *
230
 * @param  string $key
231
 * @param  mixed  $default
232
 *
233
 * @return mixed
234
 */
235
function env($key, $default = null)
236
{
237
    $value = getenv($key);
238
239
    if ($value === false) {
240
        return value($default);
241
    }
242
243
    if (envSubstr($value)) {
244
        return substr($value, 1, -1);
245
    }
246
247
    return envConversion($value);
248
}
249
250
/**
251
 * @param $value
252
 *
253
 * @return bool|string|null
254
 */
255
function envConversion($value)
256
{
257
    switch (strtolower($value)) {
258
        case 'true':
259
        case '(true)':
260
            $value = true;
261
            break;
262
        case 'false':
263
        case '(false)':
264
            $value = false;
265
            break;
266
        case 'empty':
267
        case '(empty)':
268
            $value = '';
269
            break;
270
        case 'null':
271
        case '(null)':
272
            $value = null;
273
            break;
274
    }
275
276
    return $value;
277
}
278
279
/**
280
 * @param $key
281
 *
282
 * @return bool|mixed
283
 * @throws ClientException
284
 */
285
function envNotEmpty($key)
286
{
287
    $value = env($key, false);
288
    if ($value !== false && !$value) {
289
        throw new ClientException(
290
            "Environment variable '$key' cannot be empty",
291
            \ALIBABA_CLOUD_INVALID_ARGUMENT
292
        );
293
    }
294
    if ($value) {
295
        return $value;
296
    }
297
298
    return false;
299
}
300
301
/**
302
 * @param $value
303
 *
304
 * @return bool
305
 */
306
function envSubstr($value)
307
{
308
    return ($valueLength = strlen($value)) > 1 && strpos($value, '"') === 0 && $value[$valueLength - 1] === '"';
309
}
310
311
/**
312
 * Return the default value of the given value.
313
 *
314
 * @param  mixed $value
315
 *
316
 * @return mixed
317
 */
318
function value($value)
319
{
320
    return $value instanceof Closure ? $value() : $value;
321
}
322