LocalFsComponent   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 8 2
A initAdapter() 0 4 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
11
namespace dosamigos\flysystem;
12
13
use League\Flysystem\Adapter\Local;
14
use Yii;
15
use yii\base\InvalidConfigException;
16
17
class LocalFsComponent extends AbstractFsComponent
18
{
19
    /**
20
     * @var string
21
     */
22
    public $path;
23
    /**
24
     * @var int
25
     */
26
    public $writeFlags = LOCK_EX;
27
    /**
28
     * @var int
29
     */
30
    public $linkHandling = Local::DISALLOW_LINKS;
31
    /**
32
     * @var array
33
     */
34
    public $permissions = [];
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public function init()
40
    {
41
        if ($this->path === null) {
42
            throw new InvalidConfigException('The "path" property must be set.');
43
        }
44
        $this->path = Yii::getAlias($this->path);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Yii::getAlias($this->path) can also be of type boolean. However, the property $path is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
45
        parent::init();
46
    }
47
48
    /**
49
     * @return Local
50
     */
51
    protected function initAdapter()
52
    {
53
        return new Local($this->path, $this->writeFlags, $this->linkHandling, $this->permissions);
54
    }
55
}
56