LocalFilesystem::init()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10
1
<?php
2
/**
3
 * @link https://github.com/acidwave/yii2-flysystem
4
 * @copyright Copyright (c) 2021 Acid Wave
5
 * @license http://opensource.org/licenses/BSD-3-Clause
6
 */
7
8
namespace Acidwave\Flysystem;
9
10
use League\Flysystem\Local\LocalFilesystemAdapter;
11
use Yii;
12
use yii\base\InvalidConfigException;
13
14
/**
15
 * LocalFilesystem
16
 *
17
 * @author Acid Wave <[email protected]>
18
 */
19
class LocalFilesystem extends Filesystem
20
{
21
    /**
22
     * @var string
23
     */
24
    public $path;
25
26
    /**
27
     * @inheritdoc
28
     */
29
    public function init()
30
    {
31
        if ($this->path === null) {
32
            throw new InvalidConfigException('The "path" property must be set.');
33
        }
34
35
        $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 false. 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...
36
37
        parent::init();
38
    }
39
40
    /**
41
     * @return LocalFilesystemAdapter
42
     */
43
    protected function prepareAdapter()
44
    {
45
        return new LocalFilesystemAdapter($this->path);
46
    }
47
}
48