GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SftpFilesystem   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 89
Duplicated Lines 24.72 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B init() 0 20 6
A prepareAdapter() 22 22 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * @link https://github.com/creocoder/yii2-flysystem
4
 * @copyright Copyright (c) 2015 Alexander Kochetov
5
 * @license http://opensource.org/licenses/BSD-3-Clause
6
 */
7
8
namespace creocoder\flysystem;
9
10
use League\Flysystem\Sftp\SftpAdapter;
11
use Yii;
12
use yii\base\InvalidConfigException;
13
14
/**
15
 * SftpFilesystem
16
 *
17
 * @author Alexander Kochetov <[email protected]>
18
 */
19
class SftpFilesystem extends Filesystem
20
{
21
    /**
22
     * @var string
23
     */
24
    public $host;
25
    /**
26
     * @var string
27
     */
28
    public $port;
29
    /**
30
     * @var string
31
     */
32
    public $username;
33
    /**
34
     * @var string
35
     */
36
    public $password;
37
    /**
38
     * @var integer
39
     */
40
    public $timeout;
41
    /**
42
     * @var string
43
     */
44
    public $root;
45
    /**
46
     * @var string
47
     */
48
    public $privateKey;
49
    /**
50
     * @var integer
51
     */
52
    public $permPrivate;
53
    /**
54
     * @var integer
55
     */
56
    public $permPublic;
57
58
    /**
59
     * @inheritdoc
60
     */
61
    public function init()
62
    {
63
        if ($this->host === null) {
64
            throw new InvalidConfigException('The "host" property must be set.');
65
        }
66
67
        if ($this->username === null) {
68
            throw new InvalidConfigException('The "username" property must be set.');
69
        }
70
71
        if ($this->password === null && $this->privateKey === null) {
72
            throw new InvalidConfigException('Either "password" or "privateKey" property must be set.');
73
        }
74
75
        if ($this->root !== null) {
76
            $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...
77
        }
78
79
        parent::init();
80
    }
81
82
    /**
83
     * @return SftpAdapter
84
     */
85 View Code Duplication
    protected function prepareAdapter()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
86
    {
87
        $config = [];
88
89
        foreach ([
90
            'host',
91
            'port',
92
            'username',
93
            'password',
94
            'timeout',
95
            'root',
96
            'privateKey',
97
            'permPrivate',
98
            'permPublic',
99
        ] as $name) {
100
            if ($this->$name !== null) {
101
                $config[$name] = $this->$name;
102
            }
103
        }
104
105
        return new SftpAdapter($config);
106
    }
107
}
108