AppendFile::macro()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0438

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 11
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 18
ccs 7
cts 9
cp 0.7778
crap 2.0438
rs 9.9
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