FortrabbitAdapter::getUrl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Nedmas\FortrabbitStorage\Filesystem;
4
5
use Aws\S3\S3Client;
6
use League\Flysystem\AwsS3v3\AwsS3Adapter;
7
8
class FortrabbitAdapter extends AwsS3Adapter
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $storageUrl;
14
15
    /**
16
     * Constructor.
17
     *
18
     * @param S3Client $client
19
     * @param string   $bucket
20
     * @param string   $prefix
21
     * @param array    $options
22
     * @param string   $storageUrl
23
     */
24 12
    public function __construct(S3Client $client, $bucket, $prefix = '', array $options = [], $storageUrl = '')
25
    {
26 12
        parent::__construct($client, $bucket, $prefix, $options);
27
28 12
        $this->setStorageUrl($storageUrl);
29 12
    }
30
31
    /**
32
     * Get the storage URL.
33
     *
34
     * @return string storage URL
35
     */
36 6
    public function getStorageUrl()
37
    {
38 6
        return $this->storageUrl;
39
    }
40
41
    /**
42
     * Set the storage URL.
43
     *
44
     * @param string $url
45
     *
46
     * @return self
47
     */
48 12
    public function setStorageUrl($url)
49
    {
50 12
        $is_empty = empty($url);
51
52 12
        if (!$is_empty) {
53 12
            $url = rtrim($url, $this->pathSeparator) . $this->pathSeparator;
54 8
        }
55
56 12
        $this->storageUrl = $is_empty ? null : $url;
57
58 12
        return $this;
59
    }
60
61
    /**
62
     * Get the public URL.
63
     *
64
     * @return string public URL
65
     */
66 6
    public function getUrl($path)
67
    {
68 6
        return $this->storageUrl . $this->pathPrefix . $path;
69
    }
70
}
71