Completed
Pull Request — master (#176)
by
unknown
08:47
created

QiniuStoreAPI::delete()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 3
eloc 10
nc 4
nop 2
1
<?php
2
/*
3
 * Qiniu objcet store 封装
4
 * Class QiniuStoreAPI
5
 * @author  iscod-ning
6
 * @computer kukuxiu
7
*/
8
9
function classLoader($class)
0 ignored issues
show
Best Practice introduced by
The function classLoader() has been defined more than once; this definition is ignored, only the first definition in autoload.php (L3-11) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
10
{
11
    $path = str_replace('\\', DIRECTORY_SEPARATOR, $class);
12
    $file = __DIR__ . '/src/' . $path . '.php';
13
14
    if (file_exists($file)) {
15
        require_once $file;
16
    }
17
}
18
spl_autoload_register('classLoader');
19
20
require_once  __DIR__ . '/src/Qiniu/functions.php';
21
22
use Qiniu\Auth;
23
use Qiniu\Storage\BucketManager;
24
use Qiniu\Storage\UploadManager;
25
26
class QiniuStoreAPI{
27
28
  private $accessKey = 'accessKey'; //AK
29
  private $secretKey = 'secretKey'; //SK
30
  private $bucket = 'bucket';//默认空间名
31
  private $auth;
32
33
  /**
34
   * 参数初始化
35
   * @param $appKey
36
   * @param $appSecret
37
   * @param string $format
0 ignored issues
show
Bug introduced by
There is no parameter named $format. 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...
38
  */ 
39
  public function __construct(){
40
    //初始化Auth状态:
41
    $auth = new Auth($this->accessKey, $this->secretKey);
42
    $this->auth = $auth;
43
  }
44
45
  /**
46
  *第三方资源抓取
47
  *@param $url第三方地址
48
  *@param $bucket云空间
49
  *@param $filename生成的名称
50
  *@return bool
51
  */
52
  public function fetch($url, $filename, $bucket = ''){
53
    if (!$bucket) $bucket = $this->bucket;
54
    $bmgr = new BucketManager($this->auth);
55
56
    list($ret, $err) = $bmgr->fetch($url, $bucket, $filename);
57
    if ($err !== null) {
58
      return false;
59
    }else{
60
      return isset($ret['key']) ? $ret['key'] : '';
61
    }
62
  }
63
64
  /**
65
  *@param $filePath 要上传文件的本地路径
66
  *@param $key 上传到七牛后保存的文件名
67
  *@param $bucket 上传的空间名称
68
  *@return bool
69
  */
70
  public function Upload($filePath, $key, $bucket = ''){
71
    if (!$bucket) $bucket = $this->bucket;
72
    $auth = $this->auth;
73
74
    // 生成上传 Token
75
    $token = $auth->uploadToken($bucket);
76
77
    // 初始化 UploadManager 对象并进行文件的上传。
78
    $uploadMgr = new UploadManager();
79
80
    list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath);
81
82
    if ($err !== null) {
83
        return false;
84
    } else {
85
      return isset($ret['key']) ? $ret['key'] : '';
86
    }
87
  }
88
89
  /**
90
  *删除文件
91
  */
92
  public function delete($key, $bucket = ''){
93
    $auth = $this->auth;
94
    if (!$bucket) $bucket = $this->bucket;
95
    //初始化BucketManager
96
    $bucketMgr = new BucketManager($auth);
97
98
    $err = $bucketMgr->delete($bucket, $key);
99
100
    if ($err !== null) {
101
        return false;
102
    } else {
103
      return true;
104
        echo "Success!";
0 ignored issues
show
Unused Code introduced by
echo 'Success!'; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
105
    }
106
  }
107
108
}