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.

LocalFilesystem   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 10 10 2
A prepareAdapter() 4 4 1

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\Adapter\Local;
11
use Yii;
12
use yii\base\InvalidConfigException;
13
14
/**
15
 * LocalFilesystem
16
 *
17
 * @author Alexander Kochetov <[email protected]>
18
 */
19 View Code Duplication
class LocalFilesystem extends Filesystem
0 ignored issues
show
Duplication introduced by
This class 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...
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 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...
36
37
        parent::init();
38
    }
39
40
    /**
41
     * @return Local
42
     */
43
    protected function prepareAdapter()
44
    {
45
        return new Local($this->path);
46
    }
47
}
48