Passed
Push — master ( dc4af7...7bb9d6 )
by alpha
15:00
created

AppendFile   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 13
dl 0
loc 25
rs 10
c 1
b 0
f 1
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A macro() 0 18 2
A name() 0 3 1
1
<?php
2
3
namespace AlphaSnow\LaravelFilesystem\Aliyun\Macros;
4
5
use AlphaSnow\Flysystem\Aliyun\AliyunAdapter;
6
use AlphaSnow\Flysystem\Aliyun\AliyunException;
7
use Illuminate\Filesystem\FilesystemAdapter;
8
use League\Flysystem\Config;
9
use OSS\Core\OssException;
10
use Closure;
11
12
class AppendFile implements AliyunMacro
13
{
14
    public function name(): string
15
    {
16
        return "appendFile";
17
    }
18
19
    public function macro(): Closure
20
    {
21
        return function (string $path, string $content, int $position = 0, array $options = []) {
22
            try {
23
                /**
24
                 * @var FilesystemAdapter $this
25
                 * @var AliyunAdapter $adapter
26
                 */
27
                $adapter = $this->getAdapter();
28
                return $adapter->getClient()->appendFile(
29
                    $adapter->getBucket(),
30
                    $adapter->getPrefixer()->prefixPath($path),
31
                    $content,
32
                    $position,
33
                    $adapter->getOptions()->mergeConfig(new Config($options))
34
                );
35
            } catch (OssException $exception) {
36
                throw new AliyunException($exception->getErrorMessage(), 0, $exception);
37
            }
38
        };
39
    }
40
}
41