From 6e5d08ccc4e1026464df2d203bd992842f354dd3 Mon Sep 17 00:00:00 2001 From: jemygraw Date: Tue, 22 Aug 2017 17:44:10 +0800 Subject: [PATCH 1/2] enable crc32 check by default --- src/Qiniu/Storage/FormUploader.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Qiniu/Storage/FormUploader.php b/src/Qiniu/Storage/FormUploader.php index 2a523ee0..bad6e262 100644 --- a/src/Qiniu/Storage/FormUploader.php +++ b/src/Qiniu/Storage/FormUploader.php @@ -13,10 +13,10 @@ final class FormUploader * @param $upToken 上传凭证 * @param $key 上传文件名 * @param $data 上传二进制流 + * @param $config 上传配置 * @param $params 自定义变量,规格参考 * http://developer.qiniu.com/docs/v6/api/overview/up/response/vars.html#xvar * @param $mime 上传数据的mimeType - * @param $checkCrc 是否校验crc32 * * @return array 包含已上传文件的信息,类似: * [ @@ -30,8 +30,7 @@ public static function put( $data, $config, $params, - $mime, - $checkCrc + $mime ) { $fields = array('token' => $upToken); @@ -41,9 +40,10 @@ public static function put( $fname = $key; $fields['key'] = $key; } - if ($checkCrc) { - $fields['crc32'] = \Qiniu\crc32_data($data); - } + + //enable crc32 check by default + $fields['crc32'] = \Qiniu\crc32_data($data); + if ($params) { foreach ($params as $k => $v) { $fields[$k] = $v; @@ -70,10 +70,10 @@ public static function put( * @param $upToken 上传凭证 * @param $key 上传文件名 * @param $filePath 上传文件的路径 + * @param $config 上传配置 * @param $params 自定义变量,规格参考 * http://developer.qiniu.com/docs/v6/api/overview/up/response/vars.html#xvar * @param $mime 上传数据的mimeType - * @param $checkCrc 是否校验crc32 * * @return array 包含已上传文件的信息,类似: * [ @@ -87,8 +87,7 @@ public static function putFile( $filePath, $config, $params, - $mime, - $checkCrc + $mime ) { @@ -96,9 +95,9 @@ public static function putFile( if ($key !== null) { $fields['key'] = $key; } - if ($checkCrc) { - $fields['crc32'] = \Qiniu\crc32_file($filePath); - } + + $fields['crc32'] = \Qiniu\crc32_file($filePath); + if ($params) { foreach ($params as $k => $v) { $fields[$k] = $v; From fb9dc1a6ba5a328c869168c4e28f779d65250812 Mon Sep 17 00:00:00 2001 From: jemygraw Date: Tue, 22 Aug 2017 17:54:52 +0800 Subject: [PATCH 2/2] use `phpcs --standard=PSR2` to clean the code style --- examples/cdn_get_bandwidth.php | 10 ++++-- examples/cdn_get_log_list.php | 2 +- examples/cdn_refresh_urls_dirs.php | 1 - examples/pfop_vframe.php | 7 +++-- examples/pfop_watermark.php | 3 +- examples/qetag.php | 4 +-- examples/rs_change_mime.php | 4 +-- examples/rs_delete.php | 2 +- examples/rs_stat.php | 4 +-- examples/rsf_list_files.php | 2 +- examples/saveas.php | 8 ++--- examples/upload_and_pfop.php | 2 +- examples/upload_tokens.php | 2 +- src/Qiniu/Auth.php | 6 ++-- src/Qiniu/Cdn/CdnManager.php | 24 +++++++------- src/Qiniu/Config.php | 2 +- src/Qiniu/Etag.php | 8 ++--- src/Qiniu/Http/Client.php | 6 ++-- src/Qiniu/Http/Response.php | 8 ++--- src/Qiniu/Processing/ImageUrlBuilder.php | 38 +++++++++++------------ src/Qiniu/Processing/Operation.php | 2 +- src/Qiniu/Storage/FormUploader.php | 4 +-- src/Qiniu/Storage/ResumeUploader.php | 2 +- src/Qiniu/Zone.php | 2 +- src/Qiniu/functions.php | 6 ++-- tests/Qiniu/Tests/AuthTest.php | 12 +++---- tests/Qiniu/Tests/BucketTest.php | 13 +++++--- tests/Qiniu/Tests/EtagTest.php | 8 ++--- tests/Qiniu/Tests/ImageUrlBuilderTest.php | 14 ++++----- tests/bootstrap.php | 4 +-- 30 files changed, 108 insertions(+), 102 deletions(-) diff --git a/examples/cdn_get_bandwidth.php b/examples/cdn_get_bandwidth.php index 3fbec1a9..4d2ccf6f 100644 --- a/examples/cdn_get_bandwidth.php +++ b/examples/cdn_get_bandwidth.php @@ -25,10 +25,16 @@ $granularity = "day"; //获取带宽数据 -list($bandwidthData, $getBandwidthErr) = $cdnManager->getBandwidthData($domains, $startDate, $endDate, $granularity); +list($bandwidthData, $getBandwidthErr) = $cdnManager->getBandwidthData( + $domains, + $startDate, + $endDate, + $granularity +); + if ($getBandwidthErr != null) { var_dump($getBandwidthErr); } else { echo "get bandwidth data success\n"; print_r($bandwidthData); -} \ No newline at end of file +} diff --git a/examples/cdn_get_log_list.php b/examples/cdn_get_log_list.php index 168b9f41..4e5c9424 100644 --- a/examples/cdn_get_log_list.php +++ b/examples/cdn_get_log_list.php @@ -15,7 +15,7 @@ "phpsdk.qiniudn.com" ); -$logDate='2017-08-20'; +$logDate = '2017-08-20'; //获取日志下载链接 //参考文档:http://developer.qiniu.com/article/fusion/api/log.html diff --git a/examples/cdn_refresh_urls_dirs.php b/examples/cdn_refresh_urls_dirs.php index 5a1ea65b..c05e75f2 100644 --- a/examples/cdn_refresh_urls_dirs.php +++ b/examples/cdn_refresh_urls_dirs.php @@ -50,4 +50,3 @@ echo "refresh request sent\n"; print_r($refreshResult); } - diff --git a/examples/pfop_vframe.php b/examples/pfop_vframe.php index 410f2228..e1df2d54 100644 --- a/examples/pfop_vframe.php +++ b/examples/pfop_vframe.php @@ -20,12 +20,13 @@ $notifyUrl = 'http://375dec79.ngrok.com/notify.php'; $force = false; -$config =new \Qiniu\Config(); -$config->useHTTPS=true; +$config = new \Qiniu\Config(); +$config->useHTTPS = true; $pfop = new PersistentFop($auth, $config); //要进行视频截图操作 -$fops = "vframe/jpg/offset/1/w/480/h/360/rotate/90|saveas/" . \Qiniu\base64_urlSafeEncode($bucket . ":qiniu_480x360.jpg"); +$fops = "vframe/jpg/offset/1/w/480/h/360/rotate/90|saveas/" . + \Qiniu\base64_urlSafeEncode($bucket . ":qiniu_480x360.jpg"); list($id, $err) = $pfop->execute($bucket, $key, $fops, $pipeline, $notifyUrl, $force); echo "\n====> pfop avthumb result: \n"; diff --git a/examples/pfop_watermark.php b/examples/pfop_watermark.php index 65564784..72aa6c44 100644 --- a/examples/pfop_watermark.php +++ b/examples/pfop_watermark.php @@ -31,7 +31,8 @@ $base64URL = Qiniu\base64_urlSafeEncode('http://devtools.qiniu.com/qiniu.png'); //水印参数 -$fops = "avthumb/mp4/s/640x360/vb/1.4m/image/" . $base64URL . "|saveas/" . \Qiniu\base64_urlSafeEncode($bucket . ":qiniu_wm.mp4"); +$fops = "avthumb/mp4/s/640x360/vb/1.4m/image/" . $base64URL . "|saveas/" + . \Qiniu\base64_urlSafeEncode($bucket . ":qiniu_wm.mp4"); list($id, $err) = $pfop->execute($bucket, $key, $fops, $pipeline, $notifyUrl, $force); echo "\n====> pfop avthumb result: \n"; diff --git a/examples/qetag.php b/examples/qetag.php index bab37c32..f6aff8a7 100644 --- a/examples/qetag.php +++ b/examples/qetag.php @@ -2,10 +2,10 @@ require_once __DIR__ . '/../autoload.php'; use Qiniu\Etag; -$localFile="/Users/jemy/Documents/qiniu.mp4"; +$localFile = "/Users/jemy/Documents/qiniu.mp4"; list($etag, $err) = Etag::sum($localFile); if ($err == null) { - echo "Etag: $etag"; + echo "Etag: $etag"; } else { var_dump($err); } diff --git a/examples/rs_change_mime.php b/examples/rs_change_mime.php index 6c7da23d..0d3f3ad0 100644 --- a/examples/rs_change_mime.php +++ b/examples/rs_change_mime.php @@ -8,13 +8,13 @@ $bucket = getenv('QINIU_TEST_BUCKET'); $key = 'qiniu.mp4'; -$newMime='video/x-mp4'; +$newMime = 'video/x-mp4'; $auth = new Auth($accessKey, $secretKey); $config = new \Qiniu\Config(); $bucketManager = new \Qiniu\Storage\BucketManager($auth, $config); -$err = $bucketManager->changeMime($bucket,$key,$newMime); +$err = $bucketManager->changeMime($bucket, $key, $newMime); if ($err) { print_r($err); } diff --git a/examples/rs_delete.php b/examples/rs_delete.php index 8e2e924b..365d3bec 100644 --- a/examples/rs_delete.php +++ b/examples/rs_delete.php @@ -14,4 +14,4 @@ $err = $bucketManager->delete($bucket, $key); if ($err) { print_r($err); -} \ No newline at end of file +} diff --git a/examples/rs_stat.php b/examples/rs_stat.php index 25167083..891e4e02 100644 --- a/examples/rs_stat.php +++ b/examples/rs_stat.php @@ -7,11 +7,11 @@ $secretKey = getenv('QINIU_SECRET_KEY'); $bucket = getenv('QINIU_TEST_BUCKET'); -$key="qiniu.mp4"; +$key = "qiniu.mp4"; $auth = new Auth($accessKey, $secretKey); $config = new \Qiniu\Config(); $bucketManager = new \Qiniu\Storage\BucketManager($auth, $config); -list($fileInfo,$err)=$bucketManager->stat($bucket, $key); +list($fileInfo, $err) = $bucketManager->stat($bucket, $key); if ($err) { print_r($err); } else { diff --git a/examples/rsf_list_files.php b/examples/rsf_list_files.php index ce5723d0..a3981c54 100644 --- a/examples/rsf_list_files.php +++ b/examples/rsf_list_files.php @@ -30,7 +30,7 @@ echo "\n====> list file err: \n"; var_dump($err); } else { - if(array_key_exists('marker',$ret)) { + if (array_key_exists('marker', $ret)) { echo "Marker:" . $ret["marker"] . "\n"; } echo "\nList Iterms====>\n"; diff --git a/examples/saveas.php b/examples/saveas.php index d4c209d7..d896f3bc 100644 --- a/examples/saveas.php +++ b/examples/saveas.php @@ -9,19 +9,19 @@ $secretKey = 'Secret_Key'; //生成EncodedEntryURI的值 -$entry=':';//为生成缩略图的文件名 +$entry = ':';//为生成缩略图的文件名 //生成的值 -$encodedEntryURI=\Qiniu\base64_urlSafeEncode($entry); +$encodedEntryURI = \Qiniu\base64_urlSafeEncode($entry); //使用SecretKey对新的下载URL进行HMAC1-SHA1签名 -$newurl = "78re52.com1.z0.glb.clouddn.com/resource/Ship.jpg?imageView2/2/w/200/h/200|saveas/".$encodedEntryURI; +$newurl = "78re52.com1.z0.glb.clouddn.com/resource/Ship.jpg?imageView2/2/w/200/h/200|saveas/" . $encodedEntryURI; $sign = hash_hmac("sha1", $newurl, $secretKey, true); //对签名进行URL安全的Base64编码 $encodedSign = \Qiniu\base64_urlSafeEncode($sign); //最终得到的完整下载URL -$finalURL = "http://".$newurl."/sign/".$accessKey.":".$encodedSign; +$finalURL = "http://" . $newurl . "/sign/" . $accessKey . ":" . $encodedSign; $callbackBody = file_get_contents("$finalURL"); diff --git a/examples/upload_and_pfop.php b/examples/upload_and_pfop.php index c5449928..b0c6608f 100644 --- a/examples/upload_and_pfop.php +++ b/examples/upload_and_pfop.php @@ -15,7 +15,7 @@ $token = $auth->uploadToken($bucket); $uploadMgr = new UploadManager(); -$pfop = "imageMogr2/rotate/90|saveas/".\Qiniu\base64_urlSafeEncode($bucket.":php-logo-rotate.png"); +$pfop = "imageMogr2/rotate/90|saveas/" . \Qiniu\base64_urlSafeEncode($bucket . ":php-logo-rotate.png"); //转码完成后通知到你的业务服务器。(公网可以访问,并相应200 OK) $notifyUrl = 'http://notify.fake.com'; diff --git a/examples/upload_tokens.php b/examples/upload_tokens.php index 274dadbd..90f24238 100644 --- a/examples/upload_tokens.php +++ b/examples/upload_tokens.php @@ -65,4 +65,4 @@ 'persistentNotifyUrl' => "http://api.example.com/qiniu/pfop/notify", ); $upToken = $auth->uploadToken($bucket, null, $expires, $policy, true); -print($upToken . "\n"); \ No newline at end of file +print($upToken . "\n"); diff --git a/src/Qiniu/Auth.php b/src/Qiniu/Auth.php index a652886d..10f05ae5 100644 --- a/src/Qiniu/Auth.php +++ b/src/Qiniu/Auth.php @@ -87,7 +87,7 @@ public function uploadToken( $args = self::copyPolicy($args, $policy, $strictPolicy); $args['scope'] = $scope; $args['deadline'] = $deadline; - + $b = json_encode($args); return $this->signWithData($b); } @@ -118,7 +118,7 @@ public function uploadToken( 'persistentOps', 'persistentNotifyUrl', 'persistentPipeline', - + 'deleteAfterDays', 'fileType', 'isPrefixalScope', @@ -130,7 +130,7 @@ private static function copyPolicy(&$policy, $originPolicy, $strictPolicy) return array(); } foreach ($originPolicy as $key => $value) { - if (!$strictPolicy || in_array((string) $key, self::$policyFields, true)) { + if (!$strictPolicy || in_array((string)$key, self::$policyFields, true)) { $policy[$key] = $value; } } diff --git a/src/Qiniu/Cdn/CdnManager.php b/src/Qiniu/Cdn/CdnManager.php index e3c6cd1b..a460ec2d 100644 --- a/src/Qiniu/Cdn/CdnManager.php +++ b/src/Qiniu/Cdn/CdnManager.php @@ -19,7 +19,7 @@ public function __construct(Auth $auth) } /** - * @param array $urls 待刷新的文件链接数组 + * @param array $urls 待刷新的文件链接数组 * @return array */ public function refreshUrls(array $urls) @@ -28,7 +28,7 @@ public function refreshUrls(array $urls) } /** - * @param array $dirs 待刷新的文件链接数组 + * @param array $dirs 待刷新的文件链接数组 * @return array * 目前客户默认没有目录刷新权限,刷新会有400038报错,参考:https://developer.qiniu.com/fusion/api/1229/cache-refresh * 需要刷新目录请工单联系技术支持 https://support.qiniu.com/tickets/category @@ -82,9 +82,9 @@ public function prefetchUrls(array $urls) } /** - * @param array $domains 待获取带宽数据的域名数组 - * @param string $startDate 开始的日期,格式类似 2017-01-01 - * @param string $endDate 结束的日期,格式类似 2017-01-01 + * @param array $domains 待获取带宽数据的域名数组 + * @param string $startDate 开始的日期,格式类似 2017-01-01 + * @param string $endDate 结束的日期,格式类似 2017-01-01 * @param string $granularity 获取数据的时间间隔,可以是 5min, hour 或者 day * * @return array 带宽数据和错误信息,参考 examples/cdn_manager.php 代码 @@ -105,9 +105,9 @@ public function getBandwidthData(array $domains, $startDate, $endDate, $granular } /** - * @param array $domains 待获取流量数据的域名数组 - * @param string $startDate 开始的日期,格式类似 2017-01-01 - * @param string $endDate 结束的日期,格式类似 2017-01-01 + * @param array $domains 待获取流量数据的域名数组 + * @param string $startDate 开始的日期,格式类似 2017-01-01 + * @param string $endDate 结束的日期,格式类似 2017-01-01 * @param string $granularity 获取数据的时间间隔,可以是 5min, hour 或者 day * * @return array 流量数据和错误信息,参考 examples/cdn_manager.php 代码 @@ -128,7 +128,7 @@ public function getFluxData(array $domains, $startDate, $endDate, $granularity) } /** - * @param array $domains 待获取日志下载链接的域名数组 + * @param array $domains 待获取日志下载链接的域名数组 * @param string $logDate 获取指定日期的日志下载链接,格式类似 2017-01-01 * * @return array 日志下载链接数据和错误信息,参考 examples/cdn_manager.php 代码 @@ -161,9 +161,9 @@ private function post($url, $body) /** * 构建时间戳防盗链鉴权的访问外链 * - * @param string $rawUrl 需要签名的资源url - * @param string $encryptKey 时间戳防盗链密钥 - * @param string $durationInSeconds 链接的有效期(以秒为单位) + * @param string $rawUrl 需要签名的资源url + * @param string $encryptKey 时间戳防盗链密钥 + * @param string $durationInSeconds 链接的有效期(以秒为单位) * * @return string 带鉴权信息的资源外链,参考 examples/cdn_timestamp_antileech.php 代码 */ diff --git a/src/Qiniu/Config.php b/src/Qiniu/Config.php index 29ad74ec..b75e59c5 100644 --- a/src/Qiniu/Config.php +++ b/src/Qiniu/Config.php @@ -49,7 +49,7 @@ public function getUpHost($accessKey, $bucket) public function getUpBackupHost($accessKey, $bucket) { - $zone=$this->getZone($accessKey, $bucket); + $zone = $this->getZone($accessKey, $bucket); if ($this->useHTTPS === true) { $scheme = "https://"; } else { diff --git a/src/Qiniu/Etag.php b/src/Qiniu/Etag.php index d5541ddf..d7be0644 100644 --- a/src/Qiniu/Etag.php +++ b/src/Qiniu/Etag.php @@ -38,7 +38,7 @@ public static function sum($filename) $fstat = fstat($fhandler); $fsize = $fstat['size']; - if ((int) $fsize === 0) { + if ((int)$fsize === 0) { fclose($fhandler); return array('Fto5o-5ea0sNMlW_75VgGJCv2AcJ', null); } @@ -52,12 +52,12 @@ public static function sum($filename) fclose($fhandler); return array(null, $err); } - list($sha1Code, ) = self::calcSha1($fdata); + list($sha1Code,) = self::calcSha1($fdata); $sha1Buf = array_merge($sha1Buf, $sha1Code); } else { array_push($sha1Buf, 0x96); $sha1BlockBuf = array(); - for ($i=0; $i < $blockCnt; $i++) { + for ($i = 0; $i < $blockCnt; $i++) { $fdata = fread($fhandler, Config::BLOCK_SIZE); list($sha1Code, $err) = self::calcSha1($fdata); if ($err !== null) { @@ -67,7 +67,7 @@ public static function sum($filename) $sha1BlockBuf = array_merge($sha1BlockBuf, $sha1Code); } $tmpData = self::packArray('C*', $sha1BlockBuf); - list($sha1Final, ) = self::calcSha1($tmpData); + list($sha1Final,) = self::calcSha1($tmpData); $sha1Buf = array_merge($sha1Buf, $sha1Final); } $etag = \Qiniu\base64_urlSafeEncode(self::packArray('C*', $sha1Buf)); diff --git a/src/Qiniu/Http/Client.php b/src/Qiniu/Http/Client.php index dd4a9c98..03d9dbdf 100644 --- a/src/Qiniu/Http/Client.php +++ b/src/Qiniu/Http/Client.php @@ -82,7 +82,7 @@ public static function sendRequest($request) CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HEADER => true, CURLOPT_NOBODY => false, - CURLOPT_CUSTOMREQUEST => $request->method, + CURLOPT_CUSTOMREQUEST => $request->method, CURLOPT_URL => $request->url ); @@ -106,7 +106,7 @@ public static function sendRequest($request) curl_setopt_array($ch, $options); $result = curl_exec($ch); $t2 = microtime(true); - $duration = round($t2-$t1, 3); + $duration = round($t2 - $t1, 3); $ret = curl_errno($ch); if ($ret !== 0) { $r = new Response(-1, $duration, array(), null, curl_error($ch)); @@ -128,7 +128,7 @@ private static function parseHeaders($raw) foreach ($headerLines as $line) { $headerLine = trim($line); $kv = explode(':', $headerLine); - if (count($kv) >1) { + if (count($kv) > 1) { $headers[$kv[0]] = trim($kv[1]); } } diff --git a/src/Qiniu/Http/Response.php b/src/Qiniu/Http/Response.php index 0081ea1d..e11a6174 100644 --- a/src/Qiniu/Http/Response.php +++ b/src/Qiniu/Http/Response.php @@ -104,7 +104,7 @@ public function __construct($code, $duration, array $headers = array(), $body = if (self::isJson($headers)) { try { $jsonData = self::bodyJson($body); - if ($code >=400) { + if ($code >= 400) { $this->error = $body; if ($jsonData['error'] !== null) { $this->error = $jsonData['error']; @@ -117,7 +117,7 @@ public function __construct($code, $duration, array $headers = array(), $body = $this->error = $e->getMessage(); } } - } elseif ($code >=400) { + } elseif ($code >= 400) { $this->error = $body; } return; @@ -130,7 +130,7 @@ public function json() private static function bodyJson($body) { - return \Qiniu\json_decode((string) $body, true, 512); + return \Qiniu\json_decode((string)$body, true, 512); } public function xVia() @@ -163,7 +163,7 @@ public function ok() public function needRetry() { $code = $this->statusCode; - if ($code< 0 || ($code / 100 === 5 and $code !== 579) || $code === 996) { + if ($code < 0 || ($code / 100 === 5 and $code !== 579) || $code === 996) { return true; } } diff --git a/src/Qiniu/Processing/ImageUrlBuilder.php b/src/Qiniu/Processing/ImageUrlBuilder.php index 4086e9ce..1ac5bf71 100644 --- a/src/Qiniu/Processing/ImageUrlBuilder.php +++ b/src/Qiniu/Processing/ImageUrlBuilder.php @@ -57,39 +57,39 @@ public function thumbnail( $quality = null, $ignoreError = 1 ) { - + // url合法效验 - if (! $this->isUrl($url)) { + if (!$this->isUrl($url)) { return $url; } // 参数合法性效验 - if (! in_array(intval($mode), $this->modeArr, true)) { + if (!in_array(intval($mode), $this->modeArr, true)) { return $url; } - if (! $width || ! $height) { + if (!$width || !$height) { return $url; } $thumbStr = 'imageView2/' . $mode . '/w/' . $width . '/h/' . $height . '/'; // 拼接输出格式 - if (! is_null($format) + if (!is_null($format) && in_array($format, $this->formatArr) ) { $thumbStr .= 'format/' . $format . '/'; } // 拼接渐进显示 - if (! is_null($interlace) + if (!is_null($interlace) && in_array(intval($interlace), array(0, 1), true) ) { $thumbStr .= 'interlace/' . $interlace . '/'; } // 拼接图片质量 - if (! is_null($quality) + if (!is_null($quality) && intval($quality) >= 0 && intval($quality) <= 100 ) { @@ -126,7 +126,7 @@ public function waterImg( $watermarkScale = null ) { // url合法效验 - if (! $this->isUrl($url)) { + if (!$this->isUrl($url)) { return $url; } @@ -145,21 +145,21 @@ public function waterImg( } // 拼接横轴边距 - if (! is_null($dx) + if (!is_null($dx) && is_numeric($dx) ) { $waterStr .= 'dx/' . $dx . '/'; } // 拼接纵轴边距 - if (! is_null($dy) + if (!is_null($dy) && is_numeric($dy) ) { $waterStr .= 'dy/' . $dy . '/'; } // 拼接自适应原图的短边比例 - if (! is_null($watermarkScale) + if (!is_null($watermarkScale) && is_numeric($watermarkScale) && $watermarkScale > 0 && $watermarkScale < 1 @@ -199,7 +199,7 @@ public function waterText( $dy = null ) { // url合法效验 - if (! $this->isUrl($url)) { + if (!$this->isUrl($url)) { return $url; } @@ -213,7 +213,7 @@ public function waterText( } // 拼接文字颜色 - if (! is_null($fontColor) + if (!is_null($fontColor) && $fontColor ) { $waterStr .= 'fill/' . \Qiniu\base64_urlSafeEncode($fontColor) . '/'; @@ -232,14 +232,14 @@ public function waterText( } // 拼接横轴边距 - if (! is_null($dx) + if (!is_null($dx) && is_numeric($dx) ) { $waterStr .= 'dx/' . $dx . '/'; } // 拼接纵轴边距 - if (! is_null($dy) + if (!is_null($dy) && is_numeric($dy) ) { $waterStr .= 'dy/' . $dy . '/'; @@ -261,9 +261,9 @@ protected function isUrl($url) $urlArr = parse_url($url); return $urlArr['scheme'] - && in_array($urlArr['scheme'], array('http', 'https')) - && $urlArr['host'] - && $urlArr['path']; + && in_array($urlArr['scheme'], array('http', 'https')) + && $urlArr['host'] + && $urlArr['path']; } /** @@ -277,6 +277,6 @@ protected function hasQuery($url) { $urlArr = parse_url($url); - return ! empty($urlArr['query']); + return !empty($urlArr['query']); } } diff --git a/src/Qiniu/Processing/Operation.php b/src/Qiniu/Processing/Operation.php index 02d7d753..919136fc 100644 --- a/src/Qiniu/Processing/Operation.php +++ b/src/Qiniu/Processing/Operation.php @@ -50,7 +50,7 @@ public function buildUrl($key, $fops, $protocol = 'http') $fops = implode('|', $fops); } - $url = $protocol."://$this->domain/$key?$fops"; + $url = $protocol . "://$this->domain/$key?$fops"; if ($this->auth !== null) { $url = $this->auth->privateDownloadUrl($url, $this->token_expire); } diff --git a/src/Qiniu/Storage/FormUploader.php b/src/Qiniu/Storage/FormUploader.php index bad6e262..02a4b819 100644 --- a/src/Qiniu/Storage/FormUploader.php +++ b/src/Qiniu/Storage/FormUploader.php @@ -32,7 +32,7 @@ public static function put( $params, $mime ) { - + $fields = array('token' => $upToken); if ($key === null) { $fname = 'filename'; @@ -89,7 +89,7 @@ public static function putFile( $params, $mime ) { - + $fields = array('token' => $upToken, 'file' => self::createFile($filePath, $mime)); if ($key !== null) { diff --git a/src/Qiniu/Storage/ResumeUploader.php b/src/Qiniu/Storage/ResumeUploader.php index 52f5f13e..3d3c6b22 100644 --- a/src/Qiniu/Storage/ResumeUploader.php +++ b/src/Qiniu/Storage/ResumeUploader.php @@ -46,7 +46,7 @@ public function __construct( $mime, $config ) { - + $this->upToken = $upToken; $this->key = $key; $this->inputStream = $inputStream; diff --git a/src/Qiniu/Zone.php b/src/Qiniu/Zone.php index 37f19551..e6f954b0 100644 --- a/src/Qiniu/Zone.php +++ b/src/Qiniu/Zone.php @@ -29,7 +29,7 @@ public function __construct( $apiHost = "api.qiniu.com", $iovipHost = null ) { - + $this->srcUpHosts = $srcUpHosts; $this->cdnUpHosts = $cdnUpHosts; $this->rsHost = $rsHost; diff --git a/src/Qiniu/functions.php b/src/Qiniu/functions.php index b1b509e9..2ccdf323 100644 --- a/src/Qiniu/functions.php +++ b/src/Qiniu/functions.php @@ -165,7 +165,7 @@ function thumbnail( $interlace = null, $ignoreError = 1 ) { - + static $imageUrlBuilder = null; if (is_null($imageUrlBuilder)) { $imageUrlBuilder = new \Qiniu\Processing\ImageUrlBuilder; @@ -197,7 +197,7 @@ function waterImg( $dy = null, $watermarkScale = null ) { - + static $imageUrlBuilder = null; if (is_null($imageUrlBuilder)) { $imageUrlBuilder = new \Qiniu\Processing\ImageUrlBuilder; @@ -233,7 +233,7 @@ function waterText( $dx = null, $dy = null ) { - + static $imageUrlBuilder = null; if (is_null($imageUrlBuilder)) { $imageUrlBuilder = new \Qiniu\Processing\ImageUrlBuilder; diff --git a/tests/Qiniu/Tests/AuthTest.php b/tests/Qiniu/Tests/AuthTest.php index 4fce4c9c..712cbd57 100644 --- a/tests/Qiniu/Tests/AuthTest.php +++ b/tests/Qiniu/Tests/AuthTest.php @@ -1,9 +1,7 @@ privateDownloadUrl('http://www.qiniu.com?go=1'); + $url = $dummyAuth->privateDownloadUrl('http://www.qiniu.com?go=1'); $expect = 'http://www.qiniu.com?go=1&e=1234571490&token=abcdefghklmnopq:8vzBeLZ9W3E4kbBLFLW0Xe0u7v4='; $this->assertEquals($expect, $url); unset($_SERVER['override_qiniu_auth_time']); @@ -60,7 +56,7 @@ public function testUploadToken() { global $dummyAuth; $_SERVER['override_qiniu_auth_time'] = true; - $token = $dummyAuth->uploadToken('1', '2', 3600, array('endUser'=> 'y')); + $token = $dummyAuth->uploadToken('1', '2', 3600, array('endUser' => 'y')); // @codingStandardsIgnoreStart $exp = 'abcdefghklmnopq:yyeexeUkPOROoTGvwBjJ0F0VLEo=:eyJlbmRVc2VyIjoieSIsInNjb3BlIjoiMToyIiwiZGVhZGxpbmUiOjEyMzQ1NzE0OTB9'; // @codingStandardsIgnoreEnd diff --git a/tests/Qiniu/Tests/BucketTest.php b/tests/Qiniu/Tests/BucketTest.php index 88a7fce1..534d8c2f 100644 --- a/tests/Qiniu/Tests/BucketTest.php +++ b/tests/Qiniu/Tests/BucketTest.php @@ -10,6 +10,7 @@ class BucketTest extends \PHPUnit_Framework_TestCase protected $bucketName; protected $key; protected $key2; + protected function setUp() { global $bucketName; @@ -152,7 +153,7 @@ public function testFetch() ); $this->assertArrayHasKey('key', $ret); $this->assertNull($error); - + list($ret, $error) = $this->bucketManager->fetch( 'http://developer.qiniu.com/docs/v6/sdk/php-sdk.html', $this->bucketName @@ -167,7 +168,8 @@ public function testBatchCopy() $ops = BucketManager::buildBatchCopy( $this->bucketName, array($this->key => $key), - $this->bucketName,true + $this->bucketName, + true ); list($ret, $error) = $this->bucketManager->batch($ops); $this->assertEquals(200, $ret[0]['code']); @@ -178,13 +180,14 @@ public function testBatchCopy() public function testBatchMove() { - $key = 'movefrom'. rand(); + $key = 'movefrom' . rand(); $this->bucketManager->copy($this->bucketName, $this->key, $this->bucketName, $key); $key2 = $key . 'to'; $ops = BucketManager::buildBatchMove( $this->bucketName, array($key => $key2), - $this->bucketName,true + $this->bucketName, + true ); list($ret, $error) = $this->bucketManager->batch($ops); $this->assertEquals(200, $ret[0]['code']); @@ -197,7 +200,7 @@ public function testBatchRename() $key = 'rename' . rand(); $this->bucketManager->copy($this->bucketName, $this->key, $this->bucketName, $key); $key2 = $key . 'to'; - $ops = BucketManager::buildBatchRename($this->bucketName, array($key => $key2),true); + $ops = BucketManager::buildBatchRename($this->bucketName, array($key => $key2), true); list($ret, $error) = $this->bucketManager->batch($ops); $this->assertEquals(200, $ret[0]['code']); $error = $this->bucketManager->delete($this->bucketName, $key2); diff --git a/tests/Qiniu/Tests/EtagTest.php b/tests/Qiniu/Tests/EtagTest.php index 935b9076..42a14993 100644 --- a/tests/Qiniu/Tests/EtagTest.php +++ b/tests/Qiniu/Tests/EtagTest.php @@ -16,7 +16,7 @@ public function test0M() public function testLess4M() { - $file = qiniuTempFile(3*1024*1024); + $file = qiniuTempFile(3 * 1024 * 1024); list($r, $error) = Etag::sum($file); unlink($file); $this->assertEquals('Fs5BpnAjRykYTg6o5E09cjuXrDkG', $r); @@ -25,7 +25,7 @@ public function testLess4M() public function test4M() { - $file = qiniuTempFile(4*1024*1024); + $file = qiniuTempFile(4 * 1024 * 1024); list($r, $error) = Etag::sum($file); unlink($file); $this->assertEquals('FiuKULnybewpEnrfTmxjsxc-3dWp', $r); @@ -34,7 +34,7 @@ public function test4M() public function testMore4M() { - $file = qiniuTempFile(5*1024*1024); + $file = qiniuTempFile(5 * 1024 * 1024); list($r, $error) = Etag::sum($file); unlink($file); $this->assertEquals('lhvyfIWMYFTq4s4alzlhXoAkqfVL', $r); @@ -43,7 +43,7 @@ public function testMore4M() public function test8M() { - $file = qiniuTempFile(8*1024*1024); + $file = qiniuTempFile(8 * 1024 * 1024); list($r, $error) = Etag::sum($file); unlink($file); $this->assertEquals('lmRm9ZfGZ86bnMys4wRTWtJj9ClG', $r); diff --git a/tests/Qiniu/Tests/ImageUrlBuilderTest.php b/tests/Qiniu/Tests/ImageUrlBuilderTest.php index 26050f99..fca87b6f 100644 --- a/tests/Qiniu/Tests/ImageUrlBuilderTest.php +++ b/tests/Qiniu/Tests/ImageUrlBuilderTest.php @@ -67,7 +67,7 @@ public function testThumbutl() $url . '?imageView2/1/w/200/h/200/format/png/interlace/1/ignore-error/1/', \Qiniu\thumbnail($url, 1, 200, 200, 'png', 1, 101) ); - + // 多参数测试 $this->assertEquals( $url2 . '|imageView2/1/w/200/h/200/ignore-error/1/', @@ -114,7 +114,7 @@ public function waterImgTest() . '/dissolve/100/gravity/SouthEast/', \Qiniu\waterImg($url, $image) ); - + // 横轴边距测试 $this->assertEquals( $url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw==' @@ -126,7 +126,7 @@ public function waterImgTest() . '/dissolve/100/gravity/SouthEast/', \Qiniu\waterImg($url, $image, 100, 'SouthEast', 'sad') ); - + // 纵轴边距测试 $this->assertEquals( $url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw==' @@ -138,7 +138,7 @@ public function waterImgTest() . '/dissolve/100/gravity/SouthEast/', \Qiniu\waterImg($url, $image, 100, 'SouthEast', 'sad', 'asdf') ); - + // 自适应原图的短边比例测试 $this->assertEquals( $url . '?watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw==' @@ -150,7 +150,7 @@ public function waterImgTest() . '/dissolve/100/gravity/SouthEast/', \Qiniu\waterImg($url, $image, 100, 'SouthEast', 'sad', 'asdf', 2) ); - + // 多参数测试 $this->assertEquals( $url2 . '|watermark/1/image/aHR0cDovL2RldmVsb3Blci5xaW5pdS5jb20vcmVzb3VyY2UvbG9nby0yLmpwZw==' @@ -201,7 +201,7 @@ public function waterTextTest() . '/dissolve/100/gravity/SouthEast/', \Qiniu\waterText($url, $text, $font, 'sdf', $fontColor) ); - + // 透明度测试 $this->assertEquals( $url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fontsize/500/fill/I0ZGMDAwMA==' @@ -213,7 +213,7 @@ public function waterTextTest() . '/gravity/SouthEast/', \Qiniu\waterText($url, $text, $font, 'sdf', $fontColor, 101) ); - + // 水印位置测试 $this->assertEquals( $url . '?watermark/2/text/5rWL6K-V5LiA5LiL/font/5b6u6L2v6ZuF6buR/fontsize/500/fill/I0ZGMDAwMA==' diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 2b495ba6..5bd8b056 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,6 +1,6 @@ 0) { - fseek($file, $size-1); + fseek($file, $size - 1); fwrite($file, ' '); } fclose($file);