HasDisksTrait::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 1
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 2
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 1
    public function disk($name = null)
27
    {
28 1
        $name = $name ?: $this->getDefaultDriver();
29
30 1
        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');
0 ignored issues
show
Bug Best Practice introduced by
The expression return config('filesystems.default') also could return the type Nip\Config\Config which is incompatible with the documented return type string.
Loading history...
41
    }
42
43
    /**
44
     * Attempt to get the disk from the local cache.
45
     *
46
     * @param  string $name
47
     * @return FileDisk
48
     */
49 1
    protected function get($name)
50
    {
51 1
        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? ( Ignorable by Annotation )

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

51
        return isset($this->disks[$name]) ? $this->disks[$name] : $this->/** @scrutinizer ignore-call */ resolve($name);
Loading history...
52
    }
53
}
54