Completed
Push — master ( f0e226...e1b15c )
by sabaku
04:13
created
src/Upyun/Api/Multi.php 3 patches
Doc Comments   +7 added lines patch added patch discarded remove patch
@@ -51,6 +51,10 @@  discard block
 block discarded – undo
51 51
         }
52 52
     }
53 53
 
54
+    /**
55
+     * @param string $path
56
+     * @param string $fileHash
57
+     */
54 58
     private function initRequest($path, Psr7\Stream $stream, $fileHash, $params) {
55 59
         $metaData = array(
56 60
             'expiration' => time() + $this->config->blockExpiration,
@@ -78,6 +82,9 @@  discard block
 block discarded – undo
78 82
         return $initInfo;
79 83
     }
80 84
 
85
+    /**
86
+     * @param integer $blockId
87
+     */
81 88
     private function blockUpload($blocksInfo, $blockId, Psr7\Stream $stream, $params = []) {
82 89
         $startPosition = $blockId * $this->config->maxBlockSize;
83 90
         $endPosition   = $blockId >= $blocksInfo->blocks - 1 ? $stream->getSize() : $startPosition + $this->config->maxBlockSize;
Please login to merge, or discard this patch.
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
     public function __construct(Config $config) {
19 19
         $this->config = $config;
20 20
         $this->url = ($this->config->useSsl ? 'https://' : 'http://') . Config::ED_FORM . '/'.
21
-                     $this->config->bucketName;
21
+                        $this->config->bucketName;
22 22
     }
23 23
 
24 24
     /**
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
 
104 104
         $multipart = [];
105 105
         foreach($postData as $key => $value) {
106
-           $multipart[] = ['name' => $key, 'contents' => $value];
106
+            $multipart[] = ['name' => $key, 'contents' => $value];
107 107
         }
108 108
         $multipart[] = [
109 109
             'name' => 'file',
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 
18 18
     public function __construct(Config $config) {
19 19
         $this->config = $config;
20
-        $this->url = ($this->config->useSsl ? 'https://' : 'http://') . Config::ED_FORM . '/'.
20
+        $this->url = ($this->config->useSsl ? 'https://' : 'http://').Config::ED_FORM.'/'.
21 21
                      $this->config->bucketName;
22 22
     }
23 23
 
@@ -31,20 +31,20 @@  discard block
 block discarded – undo
31 31
      * @throws \Exception
32 32
      */
33 33
     public function upload($path, $stream, $fileHash, $params = []) {
34
-        $path = '/' . ltrim($path, '/');
34
+        $path = '/'.ltrim($path, '/');
35 35
         $initInfo = $this->initRequest($path, $stream, $fileHash, $params);
36 36
         $blockStatus = $initInfo->status;
37 37
 
38 38
         $newBlockStatus = $blockStatus;
39 39
 
40
-        for($blockId = 0; $blockId < $initInfo->blocks; $blockId++) {
41
-            if($blockStatus[$blockId] === 0) {
40
+        for ($blockId = 0; $blockId < $initInfo->blocks; $blockId++) {
41
+            if ($blockStatus[$blockId] === 0) {
42 42
                 $return = $this->blockUpload($initInfo, $blockId, $stream);
43 43
                 $newBlockStatus = $return->status;
44 44
             }
45 45
         }
46 46
 
47
-        if(array_sum($newBlockStatus) === $initInfo->blocks) {
47
+        if (array_sum($newBlockStatus) === $initInfo->blocks) {
48 48
             return $this->endRequest($initInfo, $params);
49 49
         } else {
50 50
             throw new \Exception(sprintf("chunk upload failed! current every block status is : [%s]", implode(',', $newBlockStatus)));
@@ -102,13 +102,13 @@  discard block
 block discarded – undo
102 102
         );
103 103
 
104 104
         $multipart = [];
105
-        foreach($postData as $key => $value) {
105
+        foreach ($postData as $key => $value) {
106 106
            $multipart[] = ['name' => $key, 'contents' => $value];
107 107
         }
108 108
         $multipart[] = [
109 109
             'name' => 'file',
110 110
             'contents' => $fileBlock,
111
-            'filename' => 'file',  //this value must be file
111
+            'filename' => 'file', //this value must be file
112 112
             'headers' => ['Content-Type' => 'application/octet-stream']
113 113
         ];
114 114
         $postData['file'] = $fileBlock;
Please login to merge, or discard this patch.
src/Upyun/Api/Pretreat.php 3 patches
Doc Comments   +6 added lines patch added patch discarded remove patch
@@ -16,6 +16,9 @@  discard block
 block discarded – undo
16 16
         $this->config = $config;
17 17
     }
18 18
 
19
+    /**
20
+     * @param string $source
21
+     */
19 22
     public function process($source, $tasks) {
20 23
         $encodedTasks = Util::base64Json($tasks);
21 24
 
@@ -43,6 +46,9 @@  discard block
 block discarded – undo
43 46
     }
44 47
 
45 48
 
49
+    /**
50
+     * @param string $path
51
+     */
46 52
     public function query($taskIds, $path) {
47 53
         $client = new Client([
48 54
             'timeout' => $this->config->timeout,
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 namespace Upyun\Api;
3 3
 
4
-use GuzzleHttp\Psr7;
5 4
 use GuzzleHttp\Client;
6 5
 use Upyun\Config;
7 6
 use Upyun\Signature;
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
             'accept' => 'json'
32 32
         );
33 33
 
34
-        $url = $this->url . '/pretreatment';
34
+        $url = $this->url.'/pretreatment';
35 35
         $signature = Signature::getSignature($this->config, $params, Signature::SIGN_VIDEO);
36 36
         $response = $client->request('POST', $url, [
37 37
             'headers' => array('Authorization' => "UPYUN {$this->config->operatorName}:$signature"),
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
             'task_ids' => implode(',', $taskIds)
54 54
         );
55 55
 
56
-        $url = $this->url . $path;
56
+        $url = $this->url.$path;
57 57
         $signature = Signature::getSignature($this->config, $params, Signature::SIGN_VIDEO);
58 58
         $response = $client->request('GET', $url, [
59 59
             'headers' => array('Authorization' => "UPYUN {$this->config->operatorName}:$signature"),
Please login to merge, or discard this patch.
src/Upyun/Api/Rest.php 2 patches
Doc Comments   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,6 +29,9 @@  discard block
 block discarded – undo
29 29
         $this->endpoint = Config::$restApiEndPoint . '/' . $config->bucketName;
30 30
     }
31 31
     
32
+    /**
33
+     * @param string $method
34
+     */
32 35
     public function request($method, $storagePath) {
33 36
         $this->method = strtoupper($method);
34 37
         $this->storagePath = '/' . ltrim($storagePath, '/');
@@ -37,7 +40,7 @@  discard block
 block discarded – undo
37 40
 
38 41
 
39 42
     /**
40
-     * @param string|resource $file
43
+     * @param Psr7\Stream $file
41 44
      *
42 45
      * @return $this
43 46
      */
@@ -49,7 +52,7 @@  discard block
 block discarded – undo
49 52
     }
50 53
 
51 54
     /**
52
-     * @return mixed|\Psr\Http\Message\ResponseInterface
55
+     * @return \Psr\Http\Message\ResponseInterface
53 56
      */
54 57
     public function send() {
55 58
         $client = new Client([
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -26,12 +26,12 @@  discard block
 block discarded – undo
26 26
 
27 27
     public function __construct(Config $config) {
28 28
         $this->config   = $config;
29
-        $this->endpoint = Config::$restApiEndPoint . '/' . $config->bucketName;
29
+        $this->endpoint = Config::$restApiEndPoint.'/'.$config->bucketName;
30 30
     }
31 31
     
32 32
     public function request($method, $storagePath) {
33 33
         $this->method = strtoupper($method);
34
-        $this->storagePath = '/' . ltrim($storagePath, '/');
34
+        $this->storagePath = '/'.ltrim($storagePath, '/');
35 35
         return $this;
36 36
     }
37 37
 
@@ -56,10 +56,10 @@  discard block
 block discarded – undo
56 56
             'timeout' => $this->config->timeout,
57 57
         ]);
58 58
 
59
-        $url = ($this->config->useSsl ? 'https://' : 'http://') . $this->endpoint . $this->storagePath;
59
+        $url = ($this->config->useSsl ? 'https://' : 'http://').$this->endpoint.$this->storagePath;
60 60
         $bodySize = 0;
61 61
         $body = null;
62
-        if($this->file && $this->method === 'PUT') {
62
+        if ($this->file && $this->method === 'PUT') {
63 63
             $bodySize = $this->file->getSize();
64 64
             $body = $this->file;
65 65
         }
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
     }
82 82
 
83 83
     public function withHeaders($headers) {
84
-        if(is_array($headers)) {
84
+        if (is_array($headers)) {
85 85
             foreach ($headers as $header => $value) {
86 86
                 $this->withHeader($header, $value);
87 87
             }
Please login to merge, or discard this patch.
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.