ZipArchiveFilesystem   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 32
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A prepareAdapter() 0 4 1
A init() 0 9 2
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\ZipArchive\FilesystemZipArchiveProvider;
11
use League\Flysystem\ZipArchive\ZipArchiveAdapter;
12
use Yii;
13
use yii\base\InvalidConfigException;
14
15
/**
16
 * ZipArchiveFilesystem
17
 *
18
 * @author Acid Wave <[email protected]>
19
 */
20
class ZipArchiveFilesystem extends Filesystem
21
{
22
    /**
23
     * @var string
24
     */
25
    public $filename;
26
    /**
27
     * @var integer
28
     */
29
    public $localDirectoryPermissions = 700;
30
31
    /**
32
     * @inheritdoc
33
     */
34
    public function init()
35
    {
36
        if ($this->filename === null) {
37
            throw new InvalidConfigException('The "filename" property must be set.');
38
        }
39
40
        $this->filename = Yii::getAlias($this->filename);
0 ignored issues
show
Documentation Bug introduced by
It seems like Yii::getAlias($this->filename) can also be of type false. However, the property $filename 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...
41
42
        parent::init();
43
    }
44
45
    /**
46
     * @return ZipArchiveAdapter
47
     */
48
    protected function prepareAdapter()
49
    {
50
        $provider = new FilesystemZipArchiveProvider($this->filename, $this->localDirectoryPermissions);
51
        return new ZipArchiveAdapter($provider);
52
    }
53
}
54