Completed
Push — master ( da9025...5f7c52 )
by summer
20s
created
src/AliOssAdapter.php 2 patches
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -148,10 +148,10 @@  discard block
 block discarded – undo
148 148
         $object = $this->applyPathPrefix($path);
149 149
         $options = $this->getOptions($this->options, $config);
150 150
 
151
-        if (! isset($options[OssClient::OSS_LENGTH])) {
151
+        if (!isset($options[OssClient::OSS_LENGTH])) {
152 152
             $options[OssClient::OSS_LENGTH] = Util::contentSize($contents);
153 153
         }
154
-        if (! isset($options[OssClient::OSS_CONTENT_TYPE])) {
154
+        if (!isset($options[OssClient::OSS_CONTENT_TYPE])) {
155 155
             $options[OssClient::OSS_CONTENT_TYPE] = Util::guessMimeType($path, $contents);
156 156
         }
157 157
         try {
@@ -180,13 +180,13 @@  discard block
 block discarded – undo
180 180
         return $this->write($path, $contents, $config);
181 181
     }
182 182
 
183
-    public function writeFile($path, $filePath, Config $config){
183
+    public function writeFile($path, $filePath, Config $config) {
184 184
         $object = $this->applyPathPrefix($path);
185 185
         $options = $this->getOptions($this->options, $config);
186 186
 
187 187
         $options[OssClient::OSS_CHECK_MD5] = true;
188 188
 
189
-        if (! isset($options[OssClient::OSS_CONTENT_TYPE])) {
189
+        if (!isset($options[OssClient::OSS_CONTENT_TYPE])) {
190 190
             $options[OssClient::OSS_CONTENT_TYPE] = Util::guessMimeType($path, '');
191 191
         }
192 192
         try {
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
      */
210 210
     public function update($path, $contents, Config $config)
211 211
     {
212
-        if (! $config->has('visibility') && ! $config->has('ACL')) {
212
+        if (!$config->has('visibility') && !$config->has('ACL')) {
213 213
             $config->set(static::$metaMap['ACL'], $this->getObjectACL($path));
214 214
         }
215 215
         // $this->delete($path);
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
      */
237 237
     public function rename($path, $newpath)
238 238
     {
239
-        if (! $this->copy($path, $newpath)){
239
+        if (!$this->copy($path, $newpath)) {
240 240
             return false;
241 241
         }
242 242
 
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
     {
251 251
         $object = $this->applyPathPrefix($path);
252 252
         $newObject = $this->applyPathPrefix($newpath);
253
-        try{
253
+        try {
254 254
             $this->client->copyObject($this->bucket, $object, $this->bucket, $newObject);
255 255
         } catch (OssException $e) {
256 256
             $this->logErr(__FUNCTION__, $e);
@@ -268,14 +268,14 @@  discard block
 block discarded – undo
268 268
         $bucket = $this->bucket;
269 269
         $object = $this->applyPathPrefix($path);
270 270
 
271
-        try{
271
+        try {
272 272
             $this->client->deleteObject($bucket, $object);
273
-        }catch (OssException $e) {
273
+        } catch (OssException $e) {
274 274
             $this->logErr(__FUNCTION__, $e);
275 275
             return false;
276 276
         }
277 277
 
278
-        return ! $this->has($path);
278
+        return !$this->has($path);
279 279
     }
280 280
 
281 281
     /**
@@ -286,9 +286,9 @@  discard block
 block discarded – undo
286 286
         $dirname = rtrim($this->applyPathPrefix($dirname), '/').'/';
287 287
         $dirObjects = $this->listDirObjects($dirname, true);
288 288
 
289
-        if(count($dirObjects['objects']) > 0 ){
289
+        if (count($dirObjects['objects']) > 0) {
290 290
 
291
-            foreach($dirObjects['objects'] as $object)
291
+            foreach ($dirObjects['objects'] as $object)
292 292
             {
293 293
                 $objects[] = $object['Key'];
294 294
             }
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
      * @return mixed
320 320
      * @throws OssException
321 321
      */
322
-    public function listDirObjects($dirname = '', $recursive =  false)
322
+    public function listDirObjects($dirname = '', $recursive = false)
323 323
     {
324 324
         $delimiter = '/';
325 325
         $nextMarker = '';
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
         //存储结果
329 329
         $result = [];
330 330
 
331
-        while(true){
331
+        while (true) {
332 332
             $options = [
333 333
                 'delimiter' => $delimiter,
334 334
                 'prefix'    => $dirname,
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 
362 362
                     $result['objects'][] = $object;
363 363
                 }
364
-            }else{
364
+            } else {
365 365
                 $result["objects"] = [];
366 366
             }
367 367
 
@@ -369,14 +369,14 @@  discard block
 block discarded – undo
369 369
                 foreach ($prefixList as $prefixInfo) {
370 370
                     $result['prefix'][] = $prefixInfo->getPrefix();
371 371
                 }
372
-            }else{
372
+            } else {
373 373
                 $result['prefix'] = [];
374 374
             }
375 375
 
376 376
             //递归查询子目录所有文件
377
-            if($recursive){
378
-                foreach( $result['prefix'] as $pfix){
379
-                    $next  =  $this->listDirObjects($pfix , $recursive);
377
+            if ($recursive) {
378
+                foreach ($result['prefix'] as $pfix) {
379
+                    $next = $this->listDirObjects($pfix, $recursive);
380 380
                     $result["objects"] = array_merge($result['objects'], $next["objects"]);
381 381
                 }
382 382
             }
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
     public function setVisibility($path, $visibility)
415 415
     {
416 416
         $object = $this->applyPathPrefix($path);
417
-        $acl = ( $visibility === AdapterInterface::VISIBILITY_PUBLIC ) ? OssClient::OSS_ACL_TYPE_PUBLIC_READ : OssClient::OSS_ACL_TYPE_PRIVATE;
417
+        $acl = ($visibility === AdapterInterface::VISIBILITY_PUBLIC) ? OssClient::OSS_ACL_TYPE_PUBLIC_READ : OssClient::OSS_ACL_TYPE_PRIVATE;
418 418
 
419 419
         $this->client->putObjectAcl($this->bucket, $object, $acl);
420 420
 
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
     public function read($path)
438 438
     {
439 439
         $result = $this->readObject($path);
440
-        $result['contents'] = (string) $result['raw_contents'];
440
+        $result['contents'] = (string)$result['raw_contents'];
441 441
         unset($result['raw_contents']);
442 442
         return $result;
443 443
     }
@@ -486,7 +486,7 @@  discard block
 block discarded – undo
486 486
         $contents = $dirObjects["objects"];
487 487
 
488 488
         $result = array_map([$this, 'normalizeResponse'], $contents);
489
-        $result = array_filter($result, function ($value) {
489
+        $result = array_filter($result, function($value) {
490 490
             return $value['path'] !== false;
491 491
         });
492 492
 
@@ -525,7 +525,7 @@  discard block
 block discarded – undo
525 525
      */
526 526
     public function getMimetype($path)
527 527
     {
528
-        if( $object = $this->getMetadata($path))
528
+        if ($object = $this->getMetadata($path))
529 529
             $object['mimetype'] = $object['content-type'];
530 530
         return $object;
531 531
     }
@@ -535,8 +535,8 @@  discard block
 block discarded – undo
535 535
      */
536 536
     public function getTimestamp($path)
537 537
     {
538
-        if( $object = $this->getMetadata($path))
539
-            $object['timestamp'] = strtotime( $object['last-modified'] );
538
+        if ($object = $this->getMetadata($path))
539
+            $object['timestamp'] = strtotime($object['last-modified']);
540 540
         return $object;
541 541
     }
542 542
 
@@ -553,9 +553,9 @@  discard block
 block discarded – undo
553 553
             return false;
554 554
         }
555 555
 
556
-        if ($acl == OssClient::OSS_ACL_TYPE_PUBLIC_READ ){
556
+        if ($acl == OssClient::OSS_ACL_TYPE_PUBLIC_READ) {
557 557
             $res['visibility'] = AdapterInterface::VISIBILITY_PUBLIC;
558
-        }else{
558
+        } else {
559 559
             $res['visibility'] = AdapterInterface::VISIBILITY_PRIVATE;
560 560
         }
561 561
 
@@ -568,10 +568,10 @@  discard block
 block discarded – undo
568 568
      *
569 569
      * @return string
570 570
      */
571
-    public function getUrl( $path )
571
+    public function getUrl($path)
572 572
     {
573 573
         if (!$this->has($path)) throw new FileNotFoundException($path.' not found');
574
-        return ( $this->ssl ? 'https://' : 'http://' ) . ( $this->isCname ? ( $this->cdnDomain == '' ? $this->endPoint : $this->cdnDomain ) : $this->bucket . '.' . $this->endPoint ) . '/' . ltrim($path, '/');
574
+        return ($this->ssl ? 'https://' : 'http://').($this->isCname ? ($this->cdnDomain == '' ? $this->endPoint : $this->cdnDomain) : $this->bucket.'.'.$this->endPoint).'/'.ltrim($path, '/');
575 575
     }
576 576
     
577 577
     
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
         $options = [];
675 675
 
676 676
         foreach (static::$metaOptions as $option) {
677
-            if (! $config->has($option)) {
677
+            if (!$config->has($option)) {
678 678
                 continue;
679 679
             }
680 680
             $options[static::$metaMap[$option]] = $config->get($option);
@@ -701,9 +701,9 @@  discard block
 block discarded – undo
701 701
      * @param $fun string function name : __FUNCTION__
702 702
      * @param $e
703 703
      */
704
-    protected function logErr($fun, $e){
705
-        if( $this->debug ){
706
-            Log::error($fun . ": FAILED");
704
+    protected function logErr($fun, $e) {
705
+        if ($this->debug) {
706
+            Log::error($fun.": FAILED");
707 707
             Log::error($e->getMessage());
708 708
         }
709 709
     }
Please login to merge, or discard this patch.
Braces   +16 added lines, -11 removed lines patch added patch discarded remove patch
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 
271 271
         try{
272 272
             $this->client->deleteObject($bucket, $object);
273
-        }catch (OssException $e) {
273
+        } catch (OssException $e) {
274 274
             $this->logErr(__FUNCTION__, $e);
275 275
             return false;
276 276
         }
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 
362 362
                     $result['objects'][] = $object;
363 363
                 }
364
-            }else{
364
+            } else{
365 365
                 $result["objects"] = [];
366 366
             }
367 367
 
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
                 foreach ($prefixList as $prefixInfo) {
370 370
                     $result['prefix'][] = $prefixInfo->getPrefix();
371 371
                 }
372
-            }else{
372
+            } else{
373 373
                 $result['prefix'] = [];
374 374
             }
375 375
 
@@ -525,8 +525,9 @@  discard block
 block discarded – undo
525 525
      */
526 526
     public function getMimetype($path)
527 527
     {
528
-        if( $object = $this->getMetadata($path))
529
-            $object['mimetype'] = $object['content-type'];
528
+        if( $object = $this->getMetadata($path)) {
529
+                    $object['mimetype'] = $object['content-type'];
530
+        }
530 531
         return $object;
531 532
     }
532 533
 
@@ -535,8 +536,9 @@  discard block
 block discarded – undo
535 536
      */
536 537
     public function getTimestamp($path)
537 538
     {
538
-        if( $object = $this->getMetadata($path))
539
-            $object['timestamp'] = strtotime( $object['last-modified'] );
539
+        if( $object = $this->getMetadata($path)) {
540
+                    $object['timestamp'] = strtotime( $object['last-modified'] );
541
+        }
540 542
         return $object;
541 543
     }
542 544
 
@@ -555,7 +557,7 @@  discard block
 block discarded – undo
555 557
 
556 558
         if ($acl == OssClient::OSS_ACL_TYPE_PUBLIC_READ ){
557 559
             $res['visibility'] = AdapterInterface::VISIBILITY_PUBLIC;
558
-        }else{
560
+        } else{
559 561
             $res['visibility'] = AdapterInterface::VISIBILITY_PRIVATE;
560 562
         }
561 563
 
@@ -570,7 +572,9 @@  discard block
 block discarded – undo
570 572
      */
571 573
     public function getUrl( $path )
572 574
     {
573
-        if (!$this->has($path)) throw new FileNotFoundException($path.' not found');
575
+        if (!$this->has($path)) {
576
+            throw new FileNotFoundException($path.' not found');
577
+        }
574 578
         return ( $this->ssl ? 'https://' : 'http://' ) . ( $this->isCname ? ( $this->cdnDomain == '' ? $this->endPoint : $this->cdnDomain ) : $this->bucket . '.' . $this->endPoint ) . '/' . ltrim($path, '/');
575 579
     }
576 580
     
@@ -584,8 +588,9 @@  discard block
 block discarded – undo
584 588
      * @throws OssException
585 589
      */
586 590
     public function getTemporaryUrl($path, $expire, $options) {
587
-        if (!$this->has($path))
588
-            throw new FileNotFoundException($path.' not found');
591
+        if (!$this->has($path)) {
592
+                    throw new FileNotFoundException($path.' not found');
593
+        }
589 594
         $method = OssClient::OSS_HTTP_GET;
590 595
         if (Arr::has($options, OssClient::OSS_METHOD)) {
591 596
             $method = $options['method'];
Please login to merge, or discard this patch.