Passed
Branch master (7fc86c)
by xiaohui
04:06 queued 01:26
created
sdk/Core/ManageClient.php 1 patch
Braces   +24 added lines, -16 removed lines patch added patch discarded remove patch
@@ -137,10 +137,12 @@  discard block
 block discarded – undo
137 137
 	 */
138 138
 	public function existsFolder($namespace, $dir)
139 139
 	{
140
-		if (empty($namespace) || empty($dir))
141
-			return $this->_errorResponse("InvalidArgument", "namespace or dir is empty");
142
-		if (strpos($dir, '/') !== 0)
143
-			$dir = '/' . $dir;
140
+		if (empty($namespace) || empty($dir)) {
141
+					return $this->_errorResponse("InvalidArgument", "namespace or dir is empty");
142
+		}
143
+		if (strpos($dir, '/') !== 0) {
144
+					$dir = '/' . $dir;
145
+		}
144 146
 		$resourceInfo = new ResourceInfo($namespace, $dir);
145 147
 		$resourceId = $resourceInfo->buildResourceId(); //得到资源ID
146 148
 		$uri = '/' . Conf::MANAGE_API_VERSION . '/folders/' . $resourceId . '/exist';
@@ -155,10 +157,12 @@  discard block
 block discarded – undo
155 157
 	 */
156 158
 	public function createDir($namespace, $dir)
157 159
 	{
158
-		if (empty($namespace) || empty($dir))
159
-			return $this->_errorResponse("InvalidArgument", "namespace or dir is empty");
160
-		if (strpos($dir, '/') !== 0)
161
-			$dir = '/' . $dir;
160
+		if (empty($namespace) || empty($dir)) {
161
+					return $this->_errorResponse("InvalidArgument", "namespace or dir is empty");
162
+		}
163
+		if (strpos($dir, '/') !== 0) {
164
+					$dir = '/' . $dir;
165
+		}
162 166
 		$resourceInfo = new ResourceInfo($namespace, $dir);
163 167
 		$resourceId = $resourceInfo->buildResourceId(); //得到资源ID
164 168
 		$uri = '/' . Conf::MANAGE_API_VERSION . '/folders/' . $resourceId;
@@ -197,10 +201,12 @@  discard block
 block discarded – undo
197 201
 	 */
198 202
 	public function deleteDir($namespace, $dir)
199 203
 	{
200
-		if (empty($namespace) || empty($dir))
201
-			return $this->_errorResponse("InvalidArgument", "namespace or dir is empty");
202
-		if (strpos($dir, '/') !== 0)
203
-			$dir = '/' . $dir;
204
+		if (empty($namespace) || empty($dir)) {
205
+					return $this->_errorResponse("InvalidArgument", "namespace or dir is empty");
206
+		}
207
+		if (strpos($dir, '/') !== 0) {
208
+					$dir = '/' . $dir;
209
+		}
204 210
 		$resourceInfo = new ResourceInfo($namespace, $dir);
205 211
 		$resourceId = $resourceInfo->buildResourceId(); //得到资源ID
206 212
 		$uri = '/' . Conf::MANAGE_API_VERSION . '/folders/' . $resourceId;
@@ -260,8 +266,9 @@  discard block
 block discarded – undo
260 266
 	 */
261 267
 	public function mediaEncodeQuery($taskId)
262 268
 	{
263
-		if (empty($taskId))
264
-			return $this->_errorResponse("InvalidArgument", "taskId is empty");
269
+		if (empty($taskId)) {
270
+					return $this->_errorResponse("InvalidArgument", "taskId is empty");
271
+		}
265 272
 		$uri = '/' . Conf::MEDIA_ENCODE_VERSION . '/mediaEncodeResult/' . $taskId;
266 273
 		return $this->_send_request('GET', $uri);
267 274
 	}
@@ -287,8 +294,9 @@  discard block
 block discarded – undo
287 294
 	 */
288 295
 	public function vSnapshotQuery($taskId)
289 296
 	{
290
-		if (empty($taskId))
291
-			return $this->_errorResponse("InvalidArgument", "taskId is empty");
297
+		if (empty($taskId)) {
298
+					return $this->_errorResponse("InvalidArgument", "taskId is empty");
299
+		}
292 300
 		$uri = '/' . Conf::MANAGE_API_VERSION . '/snapshotResult/' . $taskId;
293 301
 		return $this->_send_request('GET', $uri);
294 302
 	}
Please login to merge, or discard this patch.
sdk/Utils/UploadOption.php 1 patch
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -60,10 +60,12 @@
 block discarded – undo
60 60
 	private function getParas_Common_BlockInit()
61 61
 	{
62 62
 		$paraArray = array();
63
-		if (isset($this->dir))
64
-			$paraArray['dir'] = $this->dir;
65
-		if (isset($this->name))
66
-			$paraArray['name'] = $this->name;
63
+		if (isset($this->dir)) {
64
+					$paraArray['dir'] = $this->dir;
65
+		}
66
+		if (isset($this->name)) {
67
+					$paraArray['name'] = $this->name;
68
+		}
67 69
 		$paraArray['md5'] = md5($this->content); // 计算文件md5
68 70
 		$paraArray['size'] = strlen($this->content); // 计算文件大小
69 71
 		$paraArray['content'] = $this->content;
Please login to merge, or discard this patch.
sdk/Utils/ResourceInfo.php 1 patch
Braces   +25 added lines, -14 removed lines patch added patch discarded remove patch
@@ -22,10 +22,14 @@  discard block
 block discarded – undo
22 22
 	 * 返回格式{$isValid, $message}*/
23 23
 	public function checkResourceInfo($dirState = false, $nameState = false)
24 24
 	{
25
-		if (empty($this->namespace))
26
-			return array(false, "namespace is empty.[{$this->toString()}]"); // 判断是否设置空间名
27
-		else
28
-			return $this->checkFileInfo($dirState, $nameState); // 判断dir和name的合法性
25
+		if (empty($this->namespace)) {
26
+					return array(false, "namespace is empty.[{$this->toString()}]");
27
+		}
28
+		// 判断是否设置空间名
29
+		else {
30
+					return $this->checkFileInfo($dirState, $nameState);
31
+		}
32
+		// 判断dir和name的合法性
29 33
 	}
30 34
 	/**检测文件信息是否合法。$dirState表示是否检测dir,$nameState表示是否检测filename<p>
31 35
 	 * 返回格式{$isValid, $message}*/
@@ -35,10 +39,14 @@  discard block
 block discarded – undo
35 39
 			return array(false, "file's name is empty.[{$this->toString()}]"); // 1:若需要进行文件名name检测,则判断文件名是否为空
36 40
 		}
37 41
 		if ($dirState) {
38
-			if (empty($this->dir))
39
-				$this->dir = '/'; // 2:判断路径是否为空,若为空,则默认为根目录'/'
40
-			else if (strpos($this->dir, '/') !== 0)
41
-				$this->dir = '/' . $this->dir; // 3:判断路径是否以'/'开头,若不是,则添加'/'
42
+			if (empty($this->dir)) {
43
+							$this->dir = '/';
44
+			}
45
+			// 2:判断路径是否为空,若为空,则默认为根目录'/'
46
+			else if (strpos($this->dir, '/') !== 0) {
47
+							$this->dir = '/' . $this->dir;
48
+			}
49
+			// 3:判断路径是否以'/'开头,若不是,则添加'/'
42 50
 		}
43 51
 		return array(true, null);
44 52
 	}
@@ -46,12 +54,15 @@  discard block
 block discarded – undo
46 54
 	public function buildResourceId()
47 55
 	{
48 56
 		$jsonData = array();
49
-		if (!empty($this->namespace))
50
-			array_push($jsonData, urldecode($this->namespace));
51
-		if (!empty($this->dir))
52
-			array_push($jsonData, urldecode($this->dir));
53
-		if (!empty($this->name))
54
-			array_push($jsonData, urldecode($this->name));
57
+		if (!empty($this->namespace)) {
58
+					array_push($jsonData, urldecode($this->namespace));
59
+		}
60
+		if (!empty($this->dir)) {
61
+					array_push($jsonData, urldecode($this->dir));
62
+		}
63
+		if (!empty($this->name)) {
64
+					array_push($jsonData, urldecode($this->name));
65
+		}
55 66
 		return EncodeUtils::encodeWithURLSafeBase64(json_encode($jsonData, true));
56 67
 	}
57 68
 	/**对URL中文进行编码*/
Please login to merge, or discard this patch.
sdk/Utils/MediaEncodeOption.php 1 patch
Braces   +46 added lines, -28 removed lines patch added patch discarded remove patch
@@ -25,12 +25,17 @@  discard block
 block discarded – undo
25 25
 	public function checkOptionParameters()
26 26
 	{
27 27
 		list($valid, $msg) = parent::checkOptionParameters(); //检测输入输出资源是否合法
28
-		if (!$valid)
29
-			return array($valid, $msg, null);
30
-		if (empty($this->encodeTemplate))
31
-			return array(false, "encodeTemplate is empty.", null); // 判断是否设置输入输出文件,或者转码模板
32
-		if (($this->usePreset != 0 && $this->usePreset != 1) || ($this->force != 0 && $this->force != 1))
33
-			return array(false, "parameters 'usePreset' or 'force' is invalid.", null); // 判断usePreset和force参数是否为0或1
28
+		if (!$valid) {
29
+					return array($valid, $msg, null);
30
+		}
31
+		if (empty($this->encodeTemplate)) {
32
+					return array(false, "encodeTemplate is empty.", null);
33
+		}
34
+		// 判断是否设置输入输出文件,或者转码模板
35
+		if (($this->usePreset != 0 && $this->usePreset != 1) || ($this->force != 0 && $this->force != 1)) {
36
+					return array(false, "parameters 'usePreset' or 'force' is invalid.", null);
37
+		}
38
+		// 判断usePreset和force参数是否为0或1
34 39
 		return $this->getOptionsHttpBody(); //返回http请求体
35 40
 	}
36 41
 	/**构建多媒体转码所需的http请求体*/
@@ -43,16 +48,21 @@  discard block
 block discarded – undo
43 48
 		$httpBody .= '&usePreset=' . $this->usePreset;
44 49
 		$httpBody .= '&force=' . $this->force;
45 50
 		// 可选的参数
46
-		if (isset($this->watermark))
47
-			$httpBody .= '&watermark=' . $this->watermark->buildResourceId();
48
-		if (isset($this->watermarkTemplate))
49
-			$httpBody .= '&watermarkTemplate=' . urlencode($this->watermarkTemplate);
50
-		if (isset($this->notifyUrl))
51
-			$httpBody .= '&notifyUrl=' . urlencode($this->notifyUrl);
52
-		if (isset($this->seek))
53
-			$httpBody .= '&seek=' .  $this->seek;
54
-		if (isset($this->duration))
55
-			$httpBody .= '&duration=' . $this->duration;
51
+		if (isset($this->watermark)) {
52
+					$httpBody .= '&watermark=' . $this->watermark->buildResourceId();
53
+		}
54
+		if (isset($this->watermarkTemplate)) {
55
+					$httpBody .= '&watermarkTemplate=' . urlencode($this->watermarkTemplate);
56
+		}
57
+		if (isset($this->notifyUrl)) {
58
+					$httpBody .= '&notifyUrl=' . urlencode($this->notifyUrl);
59
+		}
60
+		if (isset($this->seek)) {
61
+					$httpBody .= '&seek=' .  $this->seek;
62
+		}
63
+		if (isset($this->duration)) {
64
+					$httpBody .= '&duration=' . $this->duration;
65
+		}
56 66
 		return array(true, "valid", $httpBody); //视频转码参数合法,返回http请求体
57 67
 	}
58 68
 	/*######################以下是可选的参数set方法#######################*/
@@ -93,10 +103,13 @@  discard block
 block discarded – undo
93 103
 	public function checkOptionParameters()
94 104
 	{
95 105
 		list($valid, $msg) = parent::checkOptionParameters(); //检测输入输出资源是否合法
96
-		if (!$valid)
97
-			return array($valid, $msg, null);
98
-		if (empty($this->time) || !is_int($this->time) || $this->time < 0)
99
-			return array(false, "time is empty or invalid.", null); // 是否设置时间,且时间是否合法
106
+		if (!$valid) {
107
+					return array($valid, $msg, null);
108
+		}
109
+		if (empty($this->time) || !is_int($this->time) || $this->time < 0) {
110
+					return array(false, "time is empty or invalid.", null);
111
+		}
112
+		// 是否设置时间,且时间是否合法
100 113
 		return $this->getOptionsHttpBody(); //返回http请求体
101 114
 	}
102 115
 
@@ -108,8 +121,9 @@  discard block
 block discarded – undo
108 121
 		$httpBody .= '&output=' . $this->getOutputResId();
109 122
 		$httpBody .= '&time=' . $this->time;
110 123
 		// 可选的参数
111
-		if (isset($this->notifyUrl))
112
-			$httpBody .= '&notifyUrl=' . urlencode($this->notifyUrl);
124
+		if (isset($this->notifyUrl)) {
125
+					$httpBody .= '&notifyUrl=' . urlencode($this->notifyUrl);
126
+		}
113 127
 		return array(true, "valid", $httpBody); //视频转码参数合法,返回http请求体
114 128
 	}
115 129
 
@@ -142,14 +156,18 @@  discard block
 block discarded – undo
142 156
 	/**检测参数选项是否合法*/
143 157
 	public function checkOptionParameters()
144 158
 	{
145
-		if (empty($this->input) || empty($this->output))
146
-			return array(false, "input or output resources is empty."); // 判断是否设置输入输出文件,或者转码模板
159
+		if (empty($this->input) || empty($this->output)) {
160
+					return array(false, "input or output resources is empty.");
161
+		}
162
+		// 判断是否设置输入输出文件,或者转码模板
147 163
 		list($valid, $msg) = $this->input->checkResourceInfo(true, true); //检测输入的资源信息是否合法
148
-		if (!$valid)
149
-			return array($valid, $msg);
164
+		if (!$valid) {
165
+					return array($valid, $msg);
166
+		}
150 167
 		list($valid, $msg) = $this->output->checkResourceInfo(true, true); //检测输入的资源信息是否合法
151
-		if (!$valid)
152
-			return array($valid, $msg);
168
+		if (!$valid) {
169
+					return array($valid, $msg);
170
+		}
153 171
 		return array(true, null);
154 172
 	}
155 173
 	public function getInputResId()
Please login to merge, or discard this patch.