Passed
Pull Request — master (#52)
by
unknown
13:46
created

AwsS3V3AdapterWrapper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A publicUrl() 0 6 2
1
<?php
2
3
namespace AnyCloud\Service\File\Adapter\AwsS3V3;
4
5
use Aws\S3\S3ClientInterface;
6
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
7
use League\Flysystem\Config;
8
use League\Flysystem\PathPrefixer;
9
10
class AwsS3V3AdapterWrapper extends AwsS3V3Adapter
11
{
12
    private ?PathPrefixer $prefixer;
13
14
    public function __construct(
15
        private S3ClientInterface $client,
16
        private array $config,
17
    ) {
18
        parent::__construct($client, $config['bucket']);
19
20
        $pathPrefix = $this->config['public_path_prefix'];
21
        if ($pathPrefix) {
22
            $this->prefixer = new PathPrefixer($pathPrefix, '/');
23
        } else {
24
            $this->prefixer = null;
25
        }
26
    }
27
28
    public function publicUrl(string $path, Config $cnf): string
29
    {
30
        if ($this->prefixer) {
31
            return $this->prefixer->prefixPath($path);
32
        }
33
        return parent::publicUrl($path, $cnf);
34
    }
35
}
36