Completed
Pull Request — master (#1)
by
unknown
04:41
created

AzureBlobStorageAdapter::__construct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 3
nc 2
nop 4
1
<?php
2
3
4
namespace DiamondByBOLD\FlysystemAzureBlobStorage;
5
6
use League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter as BaseAzureBlobStorageAdapter;
7
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
8
9
final class AzureBlobStorageAdapter extends BaseAzureBlobStorageAdapter
10
{
11
    /**
12
     * The Azure Blob Client
13
     *
14
     * @var BlobRestProxy
15
     */
16
    private $client;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
17
18
    /**
19
     * The container name
20
     *
21
     * @var string
22
     */
23
    private $container;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
24
25
    /**
26
     * @var string
27
     */
28
    private $url;
29
30
    /**
31
     * AzureBlobStorageAdapter constructor.
32
     * @param BlobRestProxy $client
33
     * @param string $container
34
     * @param string|null $url
35
     * @param null $prefix
36
     * @throws \Exception
37
     */
38
    public function __construct(BlobRestProxy $client, string $container, string $url = null, $prefix = null)
39
    {
40
        parent::__construct($client, $container, $prefix);
41
42
        $this->client = $client;
43
        $this->container = $container;
44
        $this->setPathPrefix($prefix);
45
46
        if ($url && !filter_var($url, FILTER_VALIDATE_URL)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $url of type null|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
47
            throw new \Exception('Invalid Url');
48
        }
49
        $this->url = $url;
50
    }
51
52
    public function getUrl(string $path) : string{
53
        if ($this->url) {
54
            return rtrim($this->url, '/') . '/' . ($this->container === '$root' ? '' : $this->container . '/') . ltrim($path, '/');
55
        }
56
57
        return $this->client->getBlobUrl($this->container, $path);
58
    }
59
}
60