Completed
Pull Request — master (#831)
by
unknown
03:34
created

LfmStorageRepository   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 7
Bugs 4 Features 0
Metric Value
eloc 21
c 7
b 4
f 0
dl 0
loc 58
rs 10
wmc 9

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A rootPath() 0 9 2
A url() 0 3 1
A move() 0 3 1
A save() 0 6 1
A makeDirectory() 0 5 1
A extension() 0 3 1
A __call() 0 4 1
1
<?php
2
3
namespace Xuandung38\LaravelFilemanager;
4
5
use Illuminate\Support\Facades\Storage;
6
use League\Flysystem\Cached\CachedAdapter;
0 ignored issues
show
Bug introduced by
The type League\Flysystem\Cached\CachedAdapter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
class LfmStorageRepository
9
{
10
    private $disk;
11
    private $path;
12
    private $helper;
13
14
    public function __construct($storage_path, $helper)
15
    {
16
        $this->helper = $helper;
17
        $this->disk = Storage::disk($this->helper->config('disk'));
18
        $this->path = $storage_path;
19
    }
20
21
    public function __call($function_name, $arguments)
22
    {
23
        // TODO: check function exists
24
        return $this->disk->$function_name($this->path, ...$arguments);
25
    }
26
27
    public function rootPath()
28
    {
29
        $adapter = $this->disk->getDriver()->getAdapter();
30
31
        if ($adapter instanceof CachedAdapter) {
32
            $adapter = $adapter->getAdapter();
33
        }
34
35
        return $adapter->getPathPrefix();
36
    }
37
38
    public function move($new_lfm_path)
39
    {
40
        return $this->disk->move($this->path, $new_lfm_path->path('storage'));
41
    }
42
43
    public function save($file)
44
    {
45
        $nameint = strripos($this->path, "/");
46
        $nameclean = substr($this->path, $nameint + 1);
47
        $pathclean = substr_replace($this->path, "", $nameint);
48
        $this->disk->putFileAs($pathclean, $file, $nameclean, 'public');
0 ignored issues
show
Bug introduced by
'public' of type string is incompatible with the type array expected by parameter $options of Illuminate\Filesystem\Fi...temAdapter::putFileAs(). ( Ignorable by Annotation )

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

48
        $this->disk->putFileAs($pathclean, $file, $nameclean, /** @scrutinizer ignore-type */ 'public');
Loading history...
49
    }
50
51
    public function url($path)
52
    {
53
        return $this->disk->url($path);
54
    }
55
56
    public function makeDirectory()
57
    {
58
        $this->disk->makeDirectory($this->path, ...func_get_args());
0 ignored issues
show
Unused Code introduced by
The call to Illuminate\Filesystem\Fi...dapter::makeDirectory() has too many arguments starting with func_get_args(). ( Ignorable by Annotation )

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

58
        $this->disk->/** @scrutinizer ignore-call */ 
59
                     makeDirectory($this->path, ...func_get_args());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
59
60
        $this->disk->setVisibility($this->path, 'public');
61
    }
62
63
    public function extension()
64
    {
65
        return pathinfo($this->path, PATHINFO_EXTENSION);
66
    }
67
}
68