DiskAdapter::setFilesystem()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php namespace Nord\Lumen\FileManager\Adapters;
2
3
use Nord\Lumen\FileManager\Contracts\DiskAdapter as AdapterContract;
4
use Illuminate\Contracts\Filesystem\Filesystem;
5
use Nord\Lumen\FileManager\Contracts\File;
6
7
abstract class DiskAdapter implements AdapterContract
8
{
9
    const DEFAULT_DIRECTORY = 'files';
10
11
    /**
12
     * @var Filesystem
13
     */
14
    private $filesystem;
15
16
    /**
17
     * @var null|string
18
     */
19
    private $directory;
20
21
22
    /**
23
     * @inheritdoc
24
     */
25
    abstract public function getName();
26
27
28
    /**
29
     * @inheritdoc
30
     */
31
    abstract public function getFileUrl(File $file, array $options);
32
33
34
    /**
35
     * FilesystemAdapter constructor.
36
     *
37
     * @param array $config
38
     */
39
    public function __construct(array $config)
40
    {
41
        $this->configure($config);
42
    }
43
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public function saveFile($path, $contents, array $options)
49
    {
50
        return $this->filesystem->put($this->directory . '/' . $path, $contents, $options);
0 ignored issues
show
Documentation introduced by
$options is of type array, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
51
    }
52
53
54
    /**
55
     * @inheritdoc
56
     */
57
    public function fileExists(File $file, array $options)
58
    {
59
        return $this->filesystem->exists($this->getFilePath($file, $options));
60
    }
61
62
63
    /**
64
     * @inheritdoc
65
     */
66
    public function deleteFile(File $file, array $options)
67
    {
68
        return $this->filesystem->delete($this->getFilePath($file, $options));
69
    }
70
71
72
    /**
73
     * @inheritdoc
74
     */
75
    public function getFilePath(File $file, array $options)
76
    {
77
        return $this->createFilePath($file);
78
    }
79
80
81
    /**
82
     * @inheritdoc
83
     */
84
    public function setFilesystem(Filesystem $filesystem)
85
    {
86
        $this->filesystem = $filesystem;
87
    }
88
89
90
    /**
91
     * @param array $config
92
     */
93
    protected function configure(array $config)
94
    {
95
        $this->directory = array_get($config, 'directory', static::DEFAULT_DIRECTORY);
96
    }
97
98
99
    /**
100
     * @param File $file
101
     *
102
     * @return string
103
     */
104
    protected function createFilePath(File $file)
105
    {
106
        return $this->directory . '/' . $file->getFilePath();
107
    }
108
}
109