Completed
Push — master ( f0e226...e1b15c )
by sabaku
04:13
created
tests/UpyunTest.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use Upyun\Config;
4 4
 use Upyun\Upyun;
5 5
 
6
-class UpyunTest extends \PHPUnit_Framework_TestCase{
6
+class UpyunTest extends \PHPUnit_Framework_TestCase {
7 7
 
8 8
     /**
9 9
      * @var Upyun
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
         $config->setFormApiKey('Mv83tlocuzkmfKKUFbz2s04FzTw=');
21 21
         $config->processNotifyUrl = 'http://localhost:9999';
22 22
         self::$upyun        = new Upyun($config);
23
-        self::$tempFilePath = __DIR__ . '/assets/test.txt';
23
+        self::$tempFilePath = __DIR__.'/assets/test.txt';
24 24
         touch(self::$tempFilePath);
25 25
     }
26 26
 
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
 
39 39
     public function testWriteStream() {
40 40
         $filename = 'test.jpeg';
41
-        $f = fopen(__DIR__ . '/assets/sample.jpeg', 'rb');
42
-        if(!$f) {
41
+        $f = fopen(__DIR__.'/assets/sample.jpeg', 'rb');
42
+        if (!$f) {
43 43
             throw new \Exception('open test file failed!');
44 44
         }
45 45
         self::$upyun->write($filename, $f);
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
     public function testWriteWithAsyncProcess() {
51 51
         $filename = 'test_async.jpeg';
52 52
         $newFilename = 'test_async.png';
53
-        $f = fopen(__DIR__ . '/assets/sample.jpeg', 'rb');
54
-        if(!$f) {
53
+        $f = fopen(__DIR__.'/assets/sample.jpeg', 'rb');
54
+        if (!$f) {
55 55
             throw new \Exception('open test file failed!');
56 56
         }
57 57
         $result = self::$upyun->write($filename, $f, array(
@@ -72,8 +72,8 @@  discard block
 block discarded – undo
72 72
         $fs = new Upyun(new Config(BUCKET, USER_NAME, 'error-password'));
73 73
         try {
74 74
             $fs->write('test.txt', 'test file content');
75
-        } catch(\Exception $e) {
76
-            return ;
75
+        } catch (\Exception $e) {
76
+            return;
77 77
         }
78 78
         throw new \Exception('should get sign error.');
79 79
     }
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
         $r = self::$upyun->delete('test-delete.txt');
105 105
         try {
106 106
             self::$upyun->read('test-delete.txt');
107
-        } catch(\Exception $e) {
108
-            return ;
107
+        } catch (\Exception $e) {
108
+            return;
109 109
         }
110 110
         throw new \Exception('delete file failed');
111 111
     }
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 
190 190
     public function testProcess() {
191 191
         $source = 'php-sdk-sample.mp4';
192
-        self::$upyun->write($source, fopen(__DIR__ . '/assets/SampleVideo_640x360_1mb.mp4', 'r'));
192
+        self::$upyun->write($source, fopen(__DIR__.'/assets/SampleVideo_640x360_1mb.mp4', 'r'));
193 193
         $result = self::$upyun->process($source, array(
194 194
             array('type' => 'video', 'avopts' => '/s/240p(4:3)/as/1/r/30', 'return_info' => true, 'save_as' => '/video/result.mp4')
195 195
         ));
Please login to merge, or discard this patch.
tests/config.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,5 +3,5 @@
 block discarded – undo
3 3
     'user_name' => 'tester',
4 4
     'pwd' => 'grjxv2mxELR3',
5 5
     'bucket' => 'sdkimg',
6
-    'picture_path' => dirname(__FILE__) . '/assets/sample.jpeg'
6
+    'picture_path' => dirname(__FILE__).'/assets/sample.jpeg'
7 7
 );
8 8
\ No newline at end of file
Please login to merge, or discard this patch.
tests/SignatureTest.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use Upyun\Signature;
4 4
 use Upyun\Config;
5 5
 
6
-class SignatureTest extends \PHPUnit_Framework_TestCase{
6
+class SignatureTest extends \PHPUnit_Framework_TestCase {
7 7
 
8 8
     /**
9 9
      * @var Config;
@@ -16,6 +16,6 @@  discard block
 block discarded – undo
16 16
 
17 17
     public function testGetSignature() {
18 18
         $sign = Signature::getSignature($this->config, array('a' => 'a', 'b' => 'b'), Signature::SIGN_MULTIPART, '123');
19
-        $this->assertEquals($sign , '2aa0afd612df8fab4b3fded36c396234');
19
+        $this->assertEquals($sign, '2aa0afd612df8fab4b3fded36c396234');
20 20
     }
21 21
 }
22 22
\ No newline at end of file
Please login to merge, or discard this patch.
tests/bootstrap.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@  discard block
 block discarded – undo
1 1
 <?php
2
-require dirname(__DIR__) . '/vendor/autoload.php';
3
-$config = require_once __DIR__ . '/config.php';
2
+require dirname(__DIR__).'/vendor/autoload.php';
3
+$config = require_once __DIR__.'/config.php';
4 4
 
5 5
 define('USER_NAME', $config['user_name']);
6 6
 define('PWD', $config['pwd']);
7 7
 define('BUCKET', $config['bucket']);
8
-define('PIC_PATH' , $config['picture_path']);
9
-define('PIC_SIZE' , filesize(PIC_PATH));
8
+define('PIC_PATH', $config['picture_path']);
9
+define('PIC_SIZE', filesize(PIC_PATH));
10 10
 
11 11
 function getFileUrl($path) {
12
-    return "http://" . BUCKET . ".b0.upaiyun.com/" . ltrim($path, '/');
12
+    return "http://".BUCKET.".b0.upaiyun.com/".ltrim($path, '/');
13 13
 }
14 14
 
15 15
 function getUpyunFileSize($path) {
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
     preg_match('~^HTTP/1.1 (\d{3})~', $return, $match1);
23 23
     preg_match('~Content-Length: (\d+)~', $return, $match2);
24 24
 
25
-    if(isset($match1[1]) && $match1[1] == 200) {
25
+    if (isset($match1[1]) && $match1[1] == 200) {
26 26
         return isset($match2[1]) ? intval($match2[1]) : false;
27 27
     } else {
28 28
         return false;
Please login to merge, or discard this patch.
tests/Api/MultiTest.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 use GuzzleHttp\Psr7;
7 7
 use Upyun\Upyun;
8 8
 
9
-class MultiTest extends \PHPUnit_Framework_TestCase{
9
+class MultiTest extends \PHPUnit_Framework_TestCase {
10 10
 
11 11
     /**
12 12
      * @var Multi;
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
     }
21 21
 
22 22
     public function testUpload() {
23
-        $filePath = __DIR__ . '/../assets/sample.jpeg';
23
+        $filePath = __DIR__.'/../assets/sample.jpeg';
24 24
         $stream = Psr7\stream_for(fopen($filePath, 'rb'));
25 25
         $r = $this->multiPart->upload('test-sample.jpeg', $stream, md5_file($filePath));
26 26
         $this->assertEquals($r->getStatusCode(), 200);
Please login to merge, or discard this patch.
src/Upyun/Uploader.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@
 block discarded – undo
31 31
         if(! $useBlock) {
32 32
             $req = new Rest($this->config);
33 33
             return $req->request('PUT', $path)
34
-                       ->withHeaders($params)
35
-                       ->withFile($stream)
36
-                       ->send();
34
+                        ->withHeaders($params)
35
+                        ->withFile($stream)
36
+                        ->send();
37 37
         } else {
38 38
             return $this->pointUpload($path, $stream, $params);
39 39
         }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
             return $req->upload($path, $stream, $params);
29 29
         }
30 30
 
31
-        if(! $useBlock) {
31
+        if (!$useBlock) {
32 32
             $req = new Rest($this->config);
33 33
             return $req->request('PUT', $path)
34 34
                        ->withHeaders($params)
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
         $headers = array();
54 54
         if (is_array($params)) {
55 55
             foreach ($params as $key => $val) {
56
-                $headers['X-Upyun-Meta-' . $key] = $val;
56
+                $headers['X-Upyun-Meta-'.$key] = $val;
57 57
             }
58 58
         }
59 59
         $res = $req->request('PUT', $path)
@@ -103,10 +103,10 @@  discard block
 block discarded – undo
103 103
     }
104 104
 
105 105
     private function needUseBlock($fileSize) {
106
-        if($this->config->uploadType === 'BLOCK') {
106
+        if ($this->config->uploadType === 'BLOCK') {
107 107
             return true;
108
-        } else if($this->config->uploadType === 'AUTO' &&
109
-                  $fileSize >= $this->config->sizeBoundary ) {
108
+        } else if ($this->config->uploadType === 'AUTO' &&
109
+                  $fileSize >= $this->config->sizeBoundary) {
110 110
             return true;
111 111
         } else {
112 112
             return false;
Please login to merge, or discard this patch.
src/Upyun/Config.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -111,7 +111,7 @@
 block discarded – undo
111 111
             throw new \Exception('form api key is empty.');
112 112
         }
113 113
 
114
-       return $this->formApiKey;
114
+        return $this->formApiKey;
115 115
     }
116 116
 
117 117
     public function setFormApiKey($key) {
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -82,17 +82,17 @@  discard block
 block discarded – undo
82 82
     /**
83 83
      * 分块上传接口请求地址
84 84
      */
85
-    const ED_FORM            = 'm0.api.upyun.com';
85
+    const ED_FORM = 'm0.api.upyun.com';
86 86
 
87 87
     /**
88 88
      * 异步云处理接口地址
89 89
      */
90
-    const ED_VIDEO           = 'p0.api.upyun.com';
90
+    const ED_VIDEO = 'p0.api.upyun.com';
91 91
 
92 92
     /**
93 93
      * 刷新接口地址
94 94
      */
95
-    const ED_PURGE           = 'http://purge.upyun.com/purge/';
95
+    const ED_PURGE = 'http://purge.upyun.com/purge/';
96 96
 
97 97
     public function __construct($bucketName, $operatorName, $operatorPassword) {
98 98
         $this->bucketName = $bucketName;
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
     }
108 108
 
109 109
     public function getFormApiKey() {
110
-        if(! $this->formApiKey) {
110
+        if (!$this->formApiKey) {
111 111
             throw new \Exception('form api key is empty.');
112 112
         }
113 113
 
Please login to merge, or discard this patch.
src/Upyun/Upyun.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      * @throws \Exception 上传失败时,抛出异常
87 87
      */
88 88
     public function write($path, $content, $params = array(), $withAsyncProcess = false) {
89
-        if(!$content) {
89
+        if (!$content) {
90 90
             throw new \Exception('write content can not be empty.');
91 91
         }
92 92
 
@@ -122,8 +122,8 @@  discard block
 block discarded – undo
122 122
         $params = Util::getHeaderParams($response->getHeaders());
123 123
 
124 124
 
125
-        if(! isset($params['x-upyun-list-iter'])) {
126
-            if(is_resource($saveHandler)) {
125
+        if (!isset($params['x-upyun-list-iter'])) {
126
+            if (is_resource($saveHandler)) {
127 127
                 Psr7\copy_to_stream($response->getBody(), Psr7\stream_for($saveHandler));
128 128
                 return true;
129 129
             } else {
@@ -150,9 +150,9 @@  discard block
 block discarded – undo
150 150
         try {
151 151
             $req->request('HEAD', $path)
152 152
                             ->send();
153
-        } catch(GuzzleHttp\Exception\BadResponseException $e) {
153
+        } catch (GuzzleHttp\Exception\BadResponseException $e) {
154 154
             $statusCode = $e->getResponse()->getStatusCode();
155
-            if($statusCode === 404) {
155
+            if ($statusCode === 404) {
156 156
                 return false;
157 157
             } else {
158 158
                 throw $e;
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
     public function delete($path, $async = false) {
192 192
         $req = new Rest($this->config);
193 193
         $req->request('DELETE', $path);
194
-        if($async) {
194
+        if ($async) {
195 195
             $req->withHeader('x-upyun-async', 'true');
196 196
         }
197 197
         $res = $req->send();
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
      * @throws \Exception
208 208
      */
209 209
     public function createDir($path) {
210
-        $path = rtrim($path, '/') . '/';
210
+        $path = rtrim($path, '/').'/';
211 211
         $req = new Rest($this->config);
212 212
         $res = $req->request('POST', $path)
213 213
             ->withHeader('folder', 'true')
@@ -236,9 +236,9 @@  discard block
 block discarded – undo
236 236
      */
237 237
     public function usage($path = '/') {
238 238
 
239
-        $path = rtrim($path, '/') . '/';
239
+        $path = rtrim($path, '/').'/';
240 240
         $req = new Rest($this->config);
241
-        $response = $req->request('GET', $path . '?usage')
241
+        $response = $req->request('GET', $path.'?usage')
242 242
             ->withHeader('folder', 'true')
243 243
             ->send();
244 244
 
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
      */
255 255
     public function purge($urls) {
256 256
         $urlString = $urls;
257
-        if(is_array($urls)) {
257
+        if (is_array($urls)) {
258 258
             $urlString = implode("\n", $urls);
259 259
         }
260 260
 
Please login to merge, or discard this patch.
src/Upyun/Video.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@
 block discarded – undo
87 87
         $callbackParams = array();
88 88
         foreach($callbackKeys as $key) {
89 89
             if(isset($_POST[$key])) {
90
-               $callbackParams[$key] = Util::trim($_POST[$key]);
90
+                $callbackParams[$key] = Util::trim($_POST[$key]);
91 91
             }
92 92
         }
93 93
 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
             $postParams
33 33
         );
34 34
 
35
-        if($response->status_code !== 200) {
35
+        if ($response->status_code !== 200) {
36 36
             $body = json_decode($response->body, true);
37 37
             throw new \Exception(sprintf('%s, with x-request-id=%s', $body['msg'], $body['id']), $body['code']);
38 38
         }
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
         if (count($taskIds) <= $limit) {
49 49
             $taskIds = implode(',', $taskIds);
50 50
         } else {
51
-            throw new \Exception('can not query more than ' . $limit . ' tasks at one time!');
51
+            throw new \Exception('can not query more than '.$limit.' tasks at one time!');
52 52
         }
53 53
 
54 54
         $query['task_ids'] = $taskIds;
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
             $query
66 66
         );
67 67
 
68
-        if($response->status_code !== 200) {
68
+        if ($response->status_code !== 200) {
69 69
             $body = json_decode($response->body, true);
70 70
             throw new \Exception(sprintf('%s, with x-request-id=%s', $body['msg'], $body['id']), $body['code']);
71 71
         }
Please login to merge, or discard this patch.