RackspaceFsComponent   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 0
loc 66
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 19 6
A initAdapter() 0 12 1
1
<?php
2
/**
3
 * This file is part of the 2amigos/yii2-flysystem-component project.
4
 *
5
 * (c) 2amigOS! <http://2amigos.us/>
6
 *
7
 * For the full copyright and license information, please view
8
 * the LICENSE file that was distributed with this source code.
9
 */
10
namespace dosamigos\flysystem;
11
12
use League\Flysystem\Rackspace\RackspaceAdapter;
13
use OpenCloud\Rackspace;
14
use yii\base\InvalidConfigException;
15
16
class RackspaceFsComponent extends AbstractFsComponent
17
{
18
    /**
19
     * @var string
20
     */
21
    public $endpoint;
22
    /**
23
     * @var string
24
     */
25
    public $username;
26
    /**
27
     * @var string
28
     */
29
    public $apiKey;
30
    /**
31
     * @var string
32
     */
33
    public $region;
34
    /**
35
     * @var string
36
     */
37
    public $container;
38
    /**
39
     * @var string|null
40
     */
41
    public $prefix;
42
43
    /**
44
     * @inheritdoc
45
     */
46
    public function init()
47
    {
48
        if ($this->endpoint === null) {
49
            throw new InvalidConfigException('The "endpoint" property must be set.');
50
        }
51
        if ($this->username === null) {
52
            throw new InvalidConfigException('The "username" property must be set.');
53
        }
54
        if ($this->apiKey === null) {
55
            throw new InvalidConfigException('The "apiKey" property must be set.');
56
        }
57
        if ($this->region === null) {
58
            throw new InvalidConfigException('The "region" property must be set.');
59
        }
60
        if ($this->container === null) {
61
            throw new InvalidConfigException('The "container" property must be set.');
62
        }
63
        parent::init();
64
    }
65
66
    /**
67
     * @return RackspaceAdapter
68
     */
69
    protected function initAdapter()
70
    {
71
        $client = new Rackspace($this->endpoint, ['username' => $this->username, 'apiKey' => $this->apiKey]);
72
        $container = $client
73
            ->objectStoreService('cloudFiles', $this->region)
74
            ->getContainer($this->container);
0 ignored issues
show
Documentation introduced by
$this->container is of type string, but the function expects a object<stdClass>|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
75
76
        return new RackspaceAdapter(
77
            $container,
78
            $this->prefix
79
        );
80
    }
81
}
82