Test Setup Failed
Push — master ( dee4cd...d18a68 )
by Gabriel
06:19 queued 12s
created

HasDisksTrait::disk()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Nip\Filesystem\FilesystemManager;
4
5
use Nip\Filesystem\FileDisk;
6
7
/**
8
 * Trait HasDisksTrait
9
 * @package Nip\Filesystem\FilesystemManager
10
 */
11
trait HasDisksTrait
12
{
13
    /**
14
     * The array of resolved filesystem drivers.
15
     *
16
     * @var FileDisk[]
17
     */
18
    protected $disks = [];
19
20
    /**
21
     * Get a filesystem instance.
22
     *
23
     * @param  string $name
24
     * @return FileDisk
25
     */
26
    public function disk($name = null)
27
    {
28
        $name = $name ?: $this->getDefaultDriver();
29
30
        return $this->disks[$name] = $this->get($name);
31
    }
32
33
    /**
34
     * Get the default driver name.
35
     *
36
     * @return string
37
     */
38
    public function getDefaultDriver()
39
    {
40
        return config('filesystems.default');
41
    }
42
43
    /**
44
     * Attempt to get the disk from the local cache.
45
     *
46
     * @param  string $name
47
     * @return FileDisk
48
     */
49
    protected function get($name)
50
    {
51
        return isset($this->disks[$name]) ? $this->disks[$name] : $this->resolve($name);
0 ignored issues
show
Bug introduced by
It seems like resolve() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
52
    }
53
}
54