Passed
Push — master ( adb06a...c828b5 )
by frey
39s
created

Cosapi::upload()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 13

Duplication

Lines 7
Ratio 31.82 %

Code Coverage

Tests 5
CRAP Score 4.4609

Importance

Changes 0
Metric Value
dl 7
loc 22
ccs 5
cts 11
cp 0.4545
rs 9.2
c 0
b 0
f 0
cc 3
eloc 13
nc 3
nop 6
crap 4.4609
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 7 and the first side effect is on line 5.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Freyo\Flysystem\QcloudCOSv4\Client;
4
5
date_default_timezone_set('PRC');
6
7
class Cosapi
8
{
9
    //计算sign签名的时间参数
10
    const EXPIRED_SECONDS = 180;
11
    //1M
12
    const SLICE_SIZE_1M = 1048576;
13
    //20M 大于20M的文件需要进行分片传输
14
    const MAX_UNSLICE_FILE_SIZE = 20971520;
15
    //失败尝试次数
16
    const MAX_RETRY_TIMES = 3;
17
18
    //HTTP请求超时时间
19
    private static $timeout = 60;
20
    private static $region = 'gz'; // default region is guangzou
21
22
    /**
23
     * 设置HTTP请求超时时间.
24
     *
25
     * @param int $timeout 超时时长
26
     */
27
    public static function setTimeout($timeout = 60)
28
    {
29
        if (!is_int($timeout) || $timeout < 0) {
30
            return false;
31
        }
32
33
        self::$timeout = $timeout;
34
35
        return true;
36
    }
37
38
    public static function setRegion($region)
39
    {
40
        self::$region = $region;
41
    }
42
43
    /**
44
     * 上传文件,自动判断文件大小,如果小于20M则使用普通文件上传,大于20M则使用分片上传.
45
     *
46
     * @param string $bucket     bucket名称
47
     * @param string $srcPath    本地文件路径
48
     * @param string $dstPath    上传的文件路径
49
     * @param string $bizAttr    文件属性
50
     * @param string $slicesize  分片大小(512k,1m,2m,3m),默认:1m
0 ignored issues
show
Documentation introduced by
There is no parameter named $slicesize. Did you maybe mean $sliceSize?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
51
     * @param string $insertOnly 同名文件是否覆盖
52
     *
53
     * @return [type] [description]
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
54
     */
55 2
    public static function upload(
56
        $bucket, $srcPath, $dstPath, $bizAttr = null, $sliceSize = null, $insertOnly = null)
57
    {
58 2 View Code Duplication
        if (!file_exists($srcPath)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
            return [
60
                'code'    => ErrorCode::COSAPI_PARAMS_ERROR,
61
                'message' => 'file '.$srcPath.' not exists',
62
                'data'    => [],
63
            ];
64
        }
65
66 2
        $dstPath = self::normalizerPath($dstPath, false);
67
68
        //文件大于20M则使用分片传输
69 2
        if (filesize($srcPath) < self::MAX_UNSLICE_FILE_SIZE) {
70 2
            return self::uploadFile($bucket, $srcPath, $dstPath, $bizAttr, $insertOnly);
71
        } else {
72
            $sliceSize = self::getSliceSize($sliceSize);
73
74
            return self::uploadBySlicing($bucket, $srcPath, $dstPath, $bizAttr, $sliceSize, $insertOnly);
75
        }
76
    }
77
78
    /*
79
     * 创建目录
80
     * @param  string  $bucket bucket名称
81
     * @param  string  $folder       目录路径
82
     * @param  string  $bizAttr    目录属性
83
     */
84 1
    public static function createFolder($bucket, $folder, $bizAttr = null)
85
    {
86 1
        if (!self::isValidPath($folder)) {
87
            return [
88
                'code'    => ErrorCode::COSAPI_PARAMS_ERROR,
89
                'message' => 'folder '.$folder.' is not a valid folder name',
90
                'data'    => [],
91
            ];
92
        }
93
94 1
        $folder = self::normalizerPath($folder, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a false|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
95 1
        $folder = self::cosUrlEncode($folder);
96 1
        $expired = time() + self::EXPIRED_SECONDS;
97 1
        $url = self::generateResUrl($bucket, $folder);
98 1
        $signature = Auth::createReusableSignature($expired, $bucket);
99
100
        $data = [
101 1
            'op'       => 'create',
102 1
            'biz_attr' => (isset($bizAttr) ? $bizAttr : ''),
103 1
        ];
104
105 1
        $data = json_encode($data);
106
107
        $req = [
108 1
            'url'     => $url,
109 1
            'method'  => 'post',
110 1
            'timeout' => self::$timeout,
111 1
            'data'    => $data,
112
            'header'  => [
113 1
                'Authorization: '.$signature,
114 1
                'Content-Type: application/json',
115 1
            ],
116 1
        ];
117
118 1
        return self::sendRequest($req);
0 ignored issues
show
Documentation introduced by
$req is of type array<string,string|inte...",\"1\":\"string\"}>"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
119
    }
120
121
    /*
122
     * 目录列表
123
     * @param  string  $bucket bucket名称
124
     * @param  string  $path     目录路径,sdk会补齐末尾的 '/'
0 ignored issues
show
Bug introduced by
There is no parameter named $path. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
125
     * @param  int     $num      拉取的总数
126
     * @param  string  $pattern  eListBoth,ListDirOnly,eListFileOnly  默认both
127
     * @param  int     $order    默认正序(=0), 填1为反序,
128
     * @param  string  $offset   透传字段,用于翻页,前端不需理解,需要往前/往后翻页则透传回来
0 ignored issues
show
Bug introduced by
There is no parameter named $offset. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
129
     */
130 1 View Code Duplication
    public static function listFolder(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
131
        $bucket, $folder, $num = 20,
132
        $pattern = 'eListBoth', $order = 0,
133
        $context = null)
134
    {
135 1
        $folder = self::normalizerPath($folder, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a false|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
136
137 1
        return self::listBase($bucket, $folder, $num, $pattern, $order, $context);
138
    }
139
140
    /*
141
     * 目录列表(前缀搜索)
142
     * @param  string  $bucket bucket名称
143
     * @param  string  $prefix   列出含此前缀的所有文件
144
     * @param  int     $num      拉取的总数
145
     * @param  string  $pattern  eListBoth(默认),ListDirOnly,eListFileOnly
146
     * @param  int     $order    默认正序(=0), 填1为反序,
147
     * @param  string  $offset   透传字段,用于翻页,前端不需理解,需要往前/往后翻页则透传回来
0 ignored issues
show
Bug introduced by
There is no parameter named $offset. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
148
     */
149 View Code Duplication
    public static function prefixSearch(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
150
        $bucket, $prefix, $num = 20,
151
        $pattern = 'eListBoth', $order = 0,
152
        $context = null)
153
    {
154
        $path = self::normalizerPath($prefix);
0 ignored issues
show
Unused Code introduced by
$path is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
155
156
        return self::listBase($bucket, $prefix, $num, $pattern, $order, $context);
157
    }
158
159
    /*
160
     * 目录更新
161
     * @param  string  $bucket bucket名称
162
     * @param  string  $folder      文件夹路径,SDK会补齐末尾的 '/'
163
     * @param  string  $bizAttr   目录属性
164
     */
165
    public static function updateFolder($bucket, $folder, $bizAttr = null)
166
    {
167
        $folder = self::normalizerPath($folder, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a false|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
168
169
        return self::updateBase($bucket, $folder, $bizAttr);
170
    }
171
172
    /*
173
      * 查询目录信息
174
      * @param  string  $bucket bucket名称
175
      * @param  string  $folder       目录路径
176
      */
177
    public static function statFolder($bucket, $folder)
178
    {
179
        $folder = self::normalizerPath($folder, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a false|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
180
181
        return self::statBase($bucket, $folder);
182
    }
183
184
    /*
185
     * 删除目录
186
     * @param  string  $bucket bucket名称
187
     * @param  string  $folder       目录路径
188
     *  注意不能删除bucket下根目录/
189
     */
190 1 View Code Duplication
    public static function delFolder($bucket, $folder)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
191
    {
192 1
        if (empty($bucket) || empty($folder)) {
193
            return [
194
                'code'    => ErrorCode::COSAPI_PARAMS_ERROR,
195
                'message' => 'bucket or path is empty', ];
196
        }
197
198 1
        $folder = self::normalizerPath($folder, true);
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a false|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
199
200 1
        return self::delBase($bucket, $folder);
201
    }
202
203
    /*
204
     * 更新文件
205
     * @param  string  $bucket  bucket名称
206
     * @param  string  $path        文件路径
207
     * @param  string  $authority:  eInvalid(继承Bucket的读写权限)/eWRPrivate(私有读写)/eWPrivateRPublic(公有读私有写)
0 ignored issues
show
Documentation introduced by
There is no parameter named $authority:. Did you maybe mean $authority?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
208
     * @param  array   $customer_headers_array 携带的用户自定义头域,包括
209
     * 'Cache-Control' => '*'
210
     * 'Content-Type' => '*'
211
     * 'Content-Disposition' => '*'
212
     * 'Content-Language' => '*'
213
     * 'x-cos-meta-自定义内容' => '*'
214
     */
215 1
    public static function update($bucket, $path,
216
                                  $bizAttr = null, $authority = null, $customer_headers_array = null)
217
    {
218 1
        $path = self::normalizerPath($path);
219
220 1
        return self::updateBase($bucket, $path, $bizAttr, $authority, $customer_headers_array);
221
    }
222
223
    /*
224
     * 查询文件信息
225
     * @param  string  $bucket  bucket名称
226
     * @param  string  $path        文件路径
227
     */
228 6
    public static function stat($bucket, $path)
229
    {
230 6
        $path = self::normalizerPath($path);
231
232 6
        return self::statBase($bucket, $path);
233
    }
234
235
    /*
236
     * 删除文件
237
     * @param  string  $bucket
238
     * @param  string  $path      文件路径
239
     */
240 1 View Code Duplication
    public static function delFile($bucket, $path)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
241
    {
242 1
        if (empty($bucket) || empty($path)) {
243
            return [
244
                'code'    => ErrorCode::COSAPI_PARAMS_ERROR,
245
                'message' => 'path is empty', ];
246
        }
247
248 1
        $path = self::normalizerPath($path);
249
250 1
        return self::delBase($bucket, $path);
251
    }
252
253
    /**
254
     * 内部方法, 上传文件.
255
     *
256
     * @param string $bucket     bucket名称
257
     * @param string $srcPath    本地文件路径
258
     * @param string $dstPath    上传的文件路径
259
     * @param string $bizAttr    文件属性
260
     * @param int    $insertOnly 是否覆盖同名文件:0 覆盖,1:不覆盖
261
     *
262
     * @return [type] [description]
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
263
     */
264 2
    private static function uploadFile($bucket, $srcPath, $dstPath, $bizAttr = null, $insertOnly = null)
265
    {
266 2
        $srcPath = realpath($srcPath);
267 2
        $dstPath = self::cosUrlEncode($dstPath);
268
269 2 View Code Duplication
        if (filesize($srcPath) >= self::MAX_UNSLICE_FILE_SIZE) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
270
            return [
271
                'code'    => ErrorCode::COSAPI_PARAMS_ERROR,
272
                'message' => 'file '.$srcPath.' larger then 20M, please use uploadBySlicing interface',
273
                'data'    => [],
274
            ];
275
        }
276
277 2
        $expired = time() + self::EXPIRED_SECONDS;
278 2
        $url = self::generateResUrl($bucket, $dstPath);
279 2
        $signature = Auth::createReusableSignature($expired, $bucket);
280 2
        $fileSha = hash_file('sha1', $srcPath);
281
282
        $data = [
283 2
            'op'       => 'upload',
284 2
            'sha'      => $fileSha,
285 2
            'biz_attr' => (isset($bizAttr) ? $bizAttr : ''),
286 2
        ];
287
288 2
        $data['filecontent'] = file_get_contents($srcPath);
289
290 2
        if (isset($insertOnly) && strlen($insertOnly) > 0) {
291 2
            $data['insertOnly'] = (($insertOnly == 0 || $insertOnly == '0') ? 0 : 1);
292 2
        }
293
294
        $req = [
295 2
            'url'     => $url,
296 2
            'method'  => 'post',
297 2
            'timeout' => self::$timeout,
298 2
            'data'    => $data,
299
            'header'  => [
300 2
                'Authorization: '.$signature,
301 2
            ],
302 2
        ];
303
304 2
        return self::sendRequest($req);
0 ignored issues
show
Documentation introduced by
$req is of type array<string,string|inte...,{\"0\":\"string\"}>"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
305
    }
306
307
    /**
308
     * 内部方法,上传文件.
309
     *
310
     * @param string $bucket     bucket名称
311
     * @param string $srcPath    本地文件路径
0 ignored issues
show
Bug introduced by
There is no parameter named $srcPath. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
312
     * @param string $dstPath    上传的文件路径
0 ignored issues
show
Bug introduced by
There is no parameter named $dstPath. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
313
     * @param string $bizAttr    文件属性
314
     * @param string $sliceSize  分片大小
315
     * @param int    $insertOnly 是否覆盖同名文件:0 覆盖,1:不覆盖
316
     *
317
     * @return [type] [description]
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
318
     */
319
    private static function uploadBySlicing(
320
        $bucket, $srcFpath, $dstFpath, $bizAttr = null, $sliceSize = null, $insertOnly = null)
321
    {
322
        $srcFpath = realpath($srcFpath);
323
        $fileSize = filesize($srcFpath);
324
        $dstFpath = self::cosUrlEncode($dstFpath);
325
        $url = self::generateResUrl($bucket, $dstFpath);
326
        $sliceCount = ceil($fileSize / $sliceSize);
327
        // expiration seconds for one slice mutiply by slice count
328
        // will be the expired seconds for whole file
329
        $expiration = time() + (self::EXPIRED_SECONDS * $sliceCount);
330
        if ($expiration >= (time() + 10 * 24 * 60 * 60)) {
331
            $expiration = time() + 10 * 24 * 60 * 60;
332
        }
333
        $signature = Auth::createReusableSignature($expiration, $bucket);
334
335
        $sliceUploading = new SliceUploading(self::$timeout * 1000, self::MAX_RETRY_TIMES);
336
        for ($tryCount = 0; $tryCount < self::MAX_RETRY_TIMES; ++$tryCount) {
337
            if ($sliceUploading->initUploading(
338
                $signature,
339
                $srcFpath,
340
                $url,
341
                $fileSize, $sliceSize, $bizAttr, $insertOnly)
342
            ) {
343
                break;
344
            }
345
346
            $errorCode = $sliceUploading->getLastErrorCode();
347
            if ($errorCode === -4019) {
348
                // Delete broken file and retry again on _ERROR_FILE_NOT_FINISH_UPLOAD error.
349
                self::delFile($bucket, $dstFpath);
350
                continue;
351
            }
352
353 View Code Duplication
            if ($tryCount === self::MAX_RETRY_TIMES - 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
354
                return [
355
                    'code'       => $sliceUploading->getLastErrorCode(),
356
                    'message'    => $sliceUploading->getLastErrorMessage(),
357
                    'request_id' => $sliceUploading->getRequestId(),
358
                ];
359
            }
360
        }
361
362 View Code Duplication
        if (!$sliceUploading->performUploading()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
363
            return [
364
                'code'       => $sliceUploading->getLastErrorCode(),
365
                'message'    => $sliceUploading->getLastErrorMessage(),
366
                'request_id' => $sliceUploading->getRequestId(),
367
            ];
368
        }
369
370 View Code Duplication
        if (!$sliceUploading->finishUploading()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
371
            return [
372
                'code'       => $sliceUploading->getLastErrorCode(),
373
                'message'    => $sliceUploading->getLastErrorMessage(),
374
                'request_id' => $sliceUploading->getRequestId(),
375
            ];
376
        }
377
378
        return [
379
            'code'       => 0,
380
            'message'    => 'success',
381
            'request_id' => $sliceUploading->getRequestId(),
382
            'data'       => [
383
                'access_url'    => $sliceUploading->getAccessUrl(),
384
                'resource_path' => $sliceUploading->getResourcePath(),
385
                'source_url'    => $sliceUploading->getSourceUrl(),
386
            ],
387
        ];
388
    }
389
390
    /*
391
     * 内部公共函数
392
     * @param  string  $bucket bucket名称
393
     * @param  string  $path       文件夹路径
394
     * @param  int     $num        拉取的总数
395
     * @param  string  $pattern    eListBoth(默认),ListDirOnly,eListFileOnly
396
     * @param  int     $order      默认正序(=0), 填1为反序,
397
     * @param  string  $context    在翻页查询时候用到
398
     */
399 1
    private static function listBase(
400
        $bucket, $path, $num = 20, $pattern = 'eListBoth', $order = 0, $context = null)
401
    {
402 1
        $path = self::cosUrlEncode($path);
403 1
        $expired = time() + self::EXPIRED_SECONDS;
404 1
        $url = self::generateResUrl($bucket, $path);
405 1
        $signature = Auth::createReusableSignature($expired, $bucket);
406
407
        $data = [
408 1
            'op' => 'list',
409 1
        ];
410
411 1
        if (self::isPatternValid($pattern) == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
412
            return [
413
                'code'    => ErrorCode::COSAPI_PARAMS_ERROR,
414
                'message' => 'parameter pattern invalid',
415
            ];
416
        }
417 1
        $data['pattern'] = $pattern;
418
419 1 View Code Duplication
        if ($order != 0 && $order != 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
420
            return [
421
                'code'    => ErrorCode::COSAPI_PARAMS_ERROR,
422
                'message' => 'parameter order invalid',
423
            ];
424
        }
425 1
        $data['order'] = $order;
426
427 1 View Code Duplication
        if ($num < 0 || $num > 199) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
428
            return [
429
                'code'    => ErrorCode::COSAPI_PARAMS_ERROR,
430
                'message' => 'parameter num invalid, num need less then 200',
431
            ];
432
        }
433 1
        $data['num'] = $num;
434
435 1
        if (isset($context)) {
436
            $data['context'] = $context;
437
        }
438
439 1
        $url = $url.'?'.http_build_query($data);
440
441
        $req = [
442 1
            'url'     => $url,
443 1
            'method'  => 'get',
444 1
            'timeout' => self::$timeout,
445
            'header'  => [
446 1
                'Authorization: '.$signature,
447 1
            ],
448 1
        ];
449
450 1
        return self::sendRequest($req);
0 ignored issues
show
Documentation introduced by
$req is of type array<string,string|inte...,{\"0\":\"string\"}>"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
451
    }
452
453
    /*
454
     * 内部公共方法(更新文件和更新文件夹)
455
     * @param  string  $bucket  bucket名称
456
     * @param  string  $path        路径
457
     * @param  string  $bizAttr     文件/目录属性
458
     * @param  string  $authority:  eInvalid/eWRPrivate(私有)/eWPrivateRPublic(公有读写)
0 ignored issues
show
Documentation introduced by
There is no parameter named $authority:. Did you maybe mean $authority?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
459
     * @param  array   $customer_headers_array 携带的用户自定义头域,包括
0 ignored issues
show
Documentation introduced by
There is no parameter named $customer_headers_array. Did you maybe mean $custom_headers_array?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
460
     * 'Cache-Control' => '*'
461
     * 'Content-Type' => '*'
462
     * 'Content-Disposition' => '*'
463
     * 'Content-Language' => '*'
464
     * 'x-cos-meta-自定义内容' => '*'
465
     */
466 1
    private static function updateBase(
467
        $bucket, $path, $bizAttr = null, $authority = null, $custom_headers_array = null)
468
    {
469 1
        $path = self::cosUrlEncode($path);
470 1
        $expired = time() + self::EXPIRED_SECONDS;
0 ignored issues
show
Unused Code introduced by
$expired is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
471 1
        $url = self::generateResUrl($bucket, $path);
472 1
        $signature = Auth::createNonreusableSignature($bucket, $path);
473
474 1
        $data = ['op' => 'update'];
475
476 1
        if (isset($bizAttr)) {
477
            $data['biz_attr'] = $bizAttr;
478
        }
479
480 1
        if (isset($authority) && strlen($authority) > 0) {
481 1
            if (self::isAuthorityValid($authority) == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
482
                return [
483
                    'code'    => ErrorCode::COSAPI_PARAMS_ERROR,
484
                    'message' => 'parameter authority invalid', ];
485
            }
486
487 1
            $data['authority'] = $authority;
488 1
        }
489
490 1
        if (isset($custom_headers_array)) {
491
            $data['custom_headers'] = [];
492
            self::add_customer_header($data['custom_headers'], $custom_headers_array);
493
        }
494
495 1
        $data = json_encode($data);
496
497
        $req = [
498 1
            'url'     => $url,
499 1
            'method'  => 'post',
500 1
            'timeout' => self::$timeout,
501 1
            'data'    => $data,
502
            'header'  => [
503 1
                'Authorization: '.$signature,
504 1
                'Content-Type: application/json',
505 1
            ],
506 1
        ];
507
508 1
        return self::sendRequest($req);
0 ignored issues
show
Documentation introduced by
$req is of type array<string,string|inte...",\"1\":\"string\"}>"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
509
    }
510
511
    /*
512
     * 内部方法
513
     * @param  string  $bucket  bucket名称
514
     * @param  string  $path        文件/目录路径
515
     */
516 6
    private static function statBase($bucket, $path)
517
    {
518 6
        $path = self::cosUrlEncode($path);
519 6
        $expired = time() + self::EXPIRED_SECONDS;
520 6
        $url = self::generateResUrl($bucket, $path);
521 6
        $signature = Auth::createReusableSignature($expired, $bucket);
522
523 6
        $data = ['op' => 'stat'];
524
525 6
        $url = $url.'?'.http_build_query($data);
526
527
        $req = [
528 6
            'url'     => $url,
529 6
            'method'  => 'get',
530 6
            'timeout' => self::$timeout,
531
            'header'  => [
532 6
                'Authorization: '.$signature,
533 6
            ],
534 6
        ];
535
536 6
        return self::sendRequest($req);
0 ignored issues
show
Documentation introduced by
$req is of type array<string,string|inte...,{\"0\":\"string\"}>"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
537
    }
538
539
    /*
540
     * 内部私有方法
541
     * @param  string  $bucket  bucket名称
542
     * @param  string  $path        文件/目录路径路径
543
     */
544 2
    private static function delBase($bucket, $path)
545
    {
546 2
        if ($path == '/') {
547
            return [
548
                'code'    => ErrorCode::COSAPI_PARAMS_ERROR,
549
                'message' => 'can not delete bucket using api! go to '.
550
                    'http://console.qcloud.com/cos to operate bucket', ];
551
        }
552
553 2
        $path = self::cosUrlEncode($path);
554 2
        $expired = time() + self::EXPIRED_SECONDS;
0 ignored issues
show
Unused Code introduced by
$expired is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
555 2
        $url = self::generateResUrl($bucket, $path);
556 2
        $signature = Auth::createNonreusableSignature($bucket, $path);
557
558 2
        $data = ['op' => 'delete'];
559
560 2
        $data = json_encode($data);
561
562
        $req = [
563 2
            'url'     => $url,
564 2
            'method'  => 'post',
565 2
            'timeout' => self::$timeout,
566 2
            'data'    => $data,
567
            'header'  => [
568 2
                'Authorization: '.$signature,
569 2
                'Content-Type: application/json',
570 2
            ],
571 2
        ];
572
573 2
        return self::sendRequest($req);
0 ignored issues
show
Documentation introduced by
$req is of type array<string,string|inte...",\"1\":\"string\"}>"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
574
    }
575
576
    /*
577
     * 内部公共方法, 路径编码
578
     * @param  string  $path 待编码路径
579
     */
580 13
    private static function cosUrlEncode($path)
581
    {
582 13
        return str_replace('%2F', '/', rawurlencode($path));
583
    }
584
585
    /*
586
     * 内部公共方法, 构造URL
587
     * @param  string  $bucket
588
     * @param  string  $dstPath
589
     */
590 15
    private static function generateResUrl($bucket, $dstPath)
591
    {
592 15
        $endPoint = Conf::API_COSAPI_END_POINT;
593 15
        $endPoint = str_replace('region', self::$region, $endPoint);
594
595 15
        return $endPoint.Conf::getAppId().'/'.$bucket.$dstPath;
596
    }
597
598
    /*
599
     * 内部公共方法, 发送消息
600
     * @param  string  $req
601
     */
602 15
    private static function sendRequest($req)
603
    {
604 15
        $rsp = HttpClient::sendRequest($req);
0 ignored issues
show
Documentation introduced by
$req is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
605 15
        if ($rsp === false) {
606
            return [
607
                'code'    => ErrorCode::COSAPI_NETWORK_ERROR,
608
                'message' => 'network error',
609
            ];
610
        }
611
612 15
        $info = HttpClient::info();
0 ignored issues
show
Unused Code introduced by
$info is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
613 15
        $ret = json_decode($rsp, true);
614
615 15
        if ($ret === null) {
616
            return [
617 15
                'code'    => ErrorCode::COSAPI_NETWORK_ERROR,
618 15
                'message' => $rsp,
619 15
                'data'    => [],
620 15
            ];
621
        }
622
623
        return $ret;
624
    }
625
626
    /**
627
     * Get slice size.
628
     */
629
    private static function getSliceSize($sliceSize)
0 ignored issues
show
Unused Code introduced by
The parameter $sliceSize is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
630
    {
631
        // Fix slice size to 1MB.
632
        return self::SLICE_SIZE_1M;
633
    }
634
635
    /*
636
     * 内部方法, 规整文件路径
637
     * @param  string  $path      文件路径
638
     * @param  string  $isfolder  是否为文件夹
639
     */
640 15
    private static function normalizerPath($path, $isfolder = false)
641
    {
642 15
        if (preg_match('/^\//', $path) == 0) {
643 15
            $path = '/'.$path;
644 15
        }
645
646 15
        if ($isfolder == true) {
647 3
            if (preg_match('/\/$/', $path) == 0) {
648 3
                $path = $path.'/';
649 3
            }
650 3
        }
651
652
        // Remove unnecessary slashes.
653 15
        $path = preg_replace('#/+#', '/', $path);
654
655 15
        return $path;
656
    }
657
658
    /**
659
     * 判断authority值是否正确.
660
     *
661
     * @param string $authority
662
     *
663
     * @return [type] bool
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
664
     */
665 1
    private static function isAuthorityValid($authority)
666
    {
667 1
        if ($authority == 'eInvalid' || $authority == 'eWRPrivate' || $authority == 'eWPrivateRPublic') {
668 1
            return true;
669
        }
670
671
        return false;
672
    }
673
674
    /**
675
     * 判断pattern值是否正确.
676
     *
677
     * @param string $authority
0 ignored issues
show
Bug introduced by
There is no parameter named $authority. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
678
     *
679
     * @return [type] bool
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
680
     */
681 1
    private static function isPatternValid($pattern)
682
    {
683 1
        if ($pattern == 'eListBoth' || $pattern == 'eListDirOnly' || $pattern == 'eListFileOnly') {
684 1
            return true;
685
        }
686
687
        return false;
688
    }
689
690
    /**
691
     * 判断是否符合自定义属性.
692
     *
693
     * @param string $key
694
     *
695
     * @return [type] bool
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
696
     */
697
    private static function isCustomer_header($key)
698
    {
699
        if ($key == 'Cache-Control' || $key == 'Content-Type' ||
700
            $key == 'Content-Disposition' || $key == 'Content-Language' ||
701
            $key == 'Content-Encoding' ||
702
            substr($key, 0, strlen('x-cos-meta-')) == 'x-cos-meta-'
703
        ) {
704
            return true;
705
        }
706
707
        return false;
708
    }
709
710
    /**
711
     * 增加自定义属性到data中.
712
     *
713
     * @param array $data
714
     * @param array $customer_headers_array
715
     *
716
     * @return [type] void
0 ignored issues
show
Documentation introduced by
The doc-type [type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
717
     */
718
    private static function add_customer_header(&$data, &$customer_headers_array)
719
    {
720
        if (count($customer_headers_array) < 1) {
721
            return;
722
        }
723
        foreach ($customer_headers_array as $key => $value) {
724
            if (self::isCustomer_header($key)) {
725
                $data[$key] = $value;
726
            }
727
        }
728
    }
729
730
    // Check |$path| is a valid file path.
731
    // Return true on success, otherwise return false.
732 1
    private static function isValidPath($path)
733
    {
734 1
        if (strpos($path, '?') !== false) {
735
            return false;
736
        }
737 1
        if (strpos($path, '*') !== false) {
738
            return false;
739
        }
740 1
        if (strpos($path, ':') !== false) {
741
            return false;
742
        }
743 1
        if (strpos($path, '|') !== false) {
744
            return false;
745
        }
746 1
        if (strpos($path, '\\') !== false) {
747
            return false;
748
        }
749 1
        if (strpos($path, '<') !== false) {
750
            return false;
751
        }
752 1
        if (strpos($path, '>') !== false) {
753
            return false;
754
        }
755 1
        if (strpos($path, '"') !== false) {
756
            return false;
757
        }
758
759 1
        return true;
760
    }
761
762
    /**
763
     * Copy a file.
764
     *
765
     * @param $bucket    bucket name.
766
     * @param $srcFpath  source file path.
767
     * @param $dstFpath  destination file path.
768
     * @param $overwrite if the destination location is occupied, overwrite it or not?
769
     *
770
     * @return array|mixed.
0 ignored issues
show
Documentation introduced by
The doc-type array|mixed. could not be parsed: Unknown type name "mixed." at position 6. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
771
     */
772 1 View Code Duplication
    public static function copyFile($bucket, $srcFpath, $dstFpath, $overwrite = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
773
    {
774 1
        $srcFpath = self::normalizerPath($srcFpath);
775 1
        $dstFpath = self::normalizerPath($dstFpath);
776
777 1
        $url = self::generateResUrl($bucket, $srcFpath);
778 1
        $sign = Auth::createNonreusableSignature($bucket, $srcFpath);
779
        $data = [
780 1
            'op'            => 'copy',
781 1
            'dest_fileid'   => $dstFpath,
782 1
            'to_over_write' => $overwrite ? 1 : 0,
783 1
        ];
784
        $req = [
785 1
            'url'     => $url,
786 1
            'method'  => 'post',
787 1
            'timeout' => self::$timeout,
788 1
            'data'    => $data,
789
            'header'  => [
790 1
                'Authorization: '.$sign,
791 1
            ],
792 1
        ];
793
794 1
        return self::sendRequest($req);
0 ignored issues
show
Documentation introduced by
$req is of type array<string,string|inte...,{\"0\":\"string\"}>"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
795
    }
796
797
    /**
798
     * Move a file.
799
     *
800
     * @param $bucket    bucket name.
801
     * @param $srcFpath  source file path.
802
     * @param $dstFpath  destination file path.
803
     * @param $overwrite if the destination location is occupied, overwrite it or not?
804
     *
805
     * @return array|mixed.
0 ignored issues
show
Documentation introduced by
The doc-type array|mixed. could not be parsed: Unknown type name "mixed." at position 6. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
806
     */
807 1 View Code Duplication
    public static function moveFile($bucket, $srcFpath, $dstFpath, $overwrite = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
808
    {
809 1
        $srcFpath = self::normalizerPath($srcFpath);
810 1
        $dstFpath = self::normalizerPath($dstFpath);
811
812 1
        $url = self::generateResUrl($bucket, $srcFpath);
813 1
        $sign = Auth::createNonreusableSignature($bucket, $srcFpath);
814
        $data = [
815 1
            'op'            => 'move',
816 1
            'dest_fileid'   => $dstFpath,
817 1
            'to_over_write' => $overwrite ? 1 : 0,
818 1
        ];
819
        $req = [
820 1
            'url'     => $url,
821 1
            'method'  => 'post',
822 1
            'timeout' => self::$timeout,
823 1
            'data'    => $data,
824
            'header'  => [
825 1
                'Authorization: '.$sign,
826 1
            ],
827 1
        ];
828
829 1
        return self::sendRequest($req);
0 ignored issues
show
Documentation introduced by
$req is of type array<string,string|inte...,{\"0\":\"string\"}>"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
830
    }
831
}
832