AppendFile::name()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace AlphaSnow\LaravelFilesystem\Aliyun\Macros;
4
5
use AlphaSnow\Flysystem\Aliyun\AliyunException;
6
use AlphaSnow\LaravelFilesystem\Aliyun\OssClientAdapter;
7
use Illuminate\Filesystem\FilesystemAdapter;
8
use OSS\Core\OssException;
9
use Closure;
10
11
class AppendFile implements AliyunMacro
12
{
13
    /**
14
     * @return string
15
     */
16 8
    public function name(): string
17
    {
18 8
        return "appendFile";
19
    }
20
21
    /**
22
     * @return Closure
23
     */
24 1
    public function macro(): Closure
25
    {
26 1
        return function (string $path, string $file, int $position = 0, array $options = []) {
27
            /**
28
             * @var FilesystemAdapter $this
29
             */
30 1
            $adapter = new OssClientAdapter($this);
31
32
            try {
33 1
                return $adapter->client()->appendFile(
34 1
                    $adapter->bucket(),
35 1
                    $adapter->path($path),
36
                    $file,
37
                    $position,
38 1
                    $adapter->options($options)
39
                );
40
            } catch (OssException $exception) {
41
                throw new AliyunException($exception->getErrorMessage(), 0, $exception);
42
            }
43
        };
44
    }
45
}
46