Passed
Push — main ( 082ac6...e6b4be )
by Sugeng
03:46
created

LocalComponent   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 9
c 2
b 0
f 0
dl 0
loc 50
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 9 2
A initAdapter() 0 3 1
A getPresignedUrl() 0 3 1
A getUrl() 0 3 1
1
<?php
2
3
namespace diecoding\flysystem;
4
5
use League\Flysystem\Local\LocalFilesystemAdapter;
6
use Yii;
7
use yii\base\InvalidConfigException;
8
9
/**
10
 * Class LocalComponent
11
 *
12
 * @package diecoding\flysystem
13
 * 
14
 * ```php
15
 * 'components' => [
16
 *     'fs' => [
17
 *         'class' => \diecoding\flysystem\LocalComponent::class,
18
 *         'path' => dirname(dirname(__DIR__)) . '/storage', // or you can use @alias
19
 *         'basePath' => '', // for multiple project in single storage, will be format to `$basePath . '/' . $path`
20
 *     ],
21
 * ],
22
 * ```
23
 * 
24
 * @link      https://sugengsulistiyawan.my.id/
25
 * @author    Sugeng Sulistiyawan <[email protected]>
26
 * @copyright Copyright (c) 2023
27
 */
28
class LocalComponent extends AbstractComponent
29
{
30
    /**
31
     * @var string
32
     */
33
    public $path;
34
35
    /**
36
     * @inheritdoc
37
     */
38
    public function init()
39
    {
40
        if (empty($this->path)) {
41
            throw new InvalidConfigException('The "path" property must be set.');
42
        }
43
44
        $this->path = $this->normalizePath(Yii::getAlias($this->path));
0 ignored issues
show
Bug introduced by
It seems like Yii::getAlias($this->path) can also be of type false; however, parameter $path of diecoding\flysystem\Abst...ponent::normalizePath() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
        $this->path = $this->normalizePath(/** @scrutinizer ignore-type */ Yii::getAlias($this->path));
Loading history...
45
46
        parent::init();
47
    }
48
49
    /**
50
     * Get a URL
51
     * 
52
     * @param string $filePath
53
     * @return string
54
     */
55
    public function getUrl(string $filePath)
56
    {
57
        throw new InvalidConfigException('Not Implemented');
58
    }
59
60
    /**
61
     * Get a pre-signed URL
62
     * 
63
     * @param string $filePath
64
     * @param int|string|\DateTimeInterface $expires
65
     * @return string
66
     */
67
    public function getPresignedUrl(string $filePath, $expires = '+5 Minutes')
68
    {
69
        throw new InvalidConfigException('Not Implemented');
70
    }
71
72
    /**
73
     * @return LocalFilesystemAdapter
74
     */
75
    protected function initAdapter()
76
    {
77
        return new LocalFilesystemAdapter($this->path);
78
    }
79
}
80