FtpFsComponent   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 10 3
A initAdapter() 0 20 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\Adapter\Ftp;
13
use Yii;
14
use yii\base\InvalidConfigException;
15
16
class FtpFsComponent extends AbstractFsComponent
17
{
18
    /**
19
     * @var string
20
     */
21
    public $host;
22
    /**
23
     * @var integer
24
     */
25
    public $port;
26
    /**
27
     * @var string
28
     */
29
    public $username;
30
    /**
31
     * @var string
32
     */
33
    public $password;
34
    /**
35
     * @var boolean
36
     */
37
    public $ssl;
38
    /**
39
     * @var integer
40
     */
41
    public $timeout;
42
    /**
43
     * @var string
44
     */
45
    public $root;
46
    /**
47
     * @var integer
48
     */
49
    public $permPrivate;
50
    /**
51
     * @var integer
52
     */
53
    public $permPublic;
54
    /**
55
     * @var boolean
56
     */
57
    public $passive;
58
    /**
59
     * @var integer
60
     */
61
    public $transferMode;
62
63
    /**
64
     * @inheritdoc
65
     */
66
    public function init()
67
    {
68
        if ($this->host === null) {
69
            throw new InvalidConfigException('The "host" property must be set.');
70
        }
71
        if ($this->root !== null) {
72
            $this->root = Yii::getAlias($this->root);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Yii::getAlias($this->root) can also be of type boolean. However, the property $root 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...
73
        }
74
        parent::init();
75
    }
76
77
    /**
78
     * @return Ftp
79
     */
80
    protected function initAdapter()
81
    {
82
        $config = array_filter(
83
            [
84
                'host' => $this->host,
85
                'port' => $this->port,
86
                'username' => $this->username,
87
                'password' => $this->password,
88
                'ssl' => $this->ssl,
89
                'timeout' => $this->timeout,
90
                'root' => $this->root,
91
                'permPrivate' => $this->permPrivate,
92
                'permPublic' => $this->permPublic,
93
                'passive' => $this->passive,
94
                'transferMode' => $this->transferMode,
95
            ]
96
        );
97
98
        return new Ftp($config);
99
    }
100
}
101