LfmStorageRepository::move()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
c 1
b 1
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace UniSharp\LaravelFilemanager;
4
5
use Illuminate\Support\Facades\Storage;
6
7
class LfmStorageRepository
8
{
9
    private $disk;
10
    private $path;
11
    private $helper;
12
13
    public function __construct($storage_path, $helper)
14
    {
15
        $this->helper = $helper;
16
        $this->disk = Storage::disk($this->helper->config('disk'));
17
        $this->path = $storage_path;
18
    }
19
20
    public function __call($function_name, $arguments)
21
    {
22
        // TODO: check function exists
23
        return $this->disk->$function_name($this->path, ...$arguments);
24
    }
25
26
    public function rootPath()
27
    {
28
        return $this->disk->path('');
29
    }
30
31
    public function move($new_lfm_path)
32
    {
33
        return $this->disk->move($this->path, $new_lfm_path->path('storage'));
34
    }
35
36
    public function save($file)
37
    {
38
        $nameint = strripos($this->path, "/");
39
        $nameclean = substr($this->path, $nameint + 1);
40
        $pathclean = substr_replace($this->path, "", $nameint);
41
        $this->disk->putFileAs($pathclean, $file, $nameclean, 'public');
0 ignored issues
show
Bug introduced by
It seems like $pathclean can also be of type array; however, parameter $path of Illuminate\Filesystem\Fi...temAdapter::putFileAs() 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

41
        $this->disk->putFileAs(/** @scrutinizer ignore-type */ $pathclean, $file, $nameclean, 'public');
Loading history...
42
    }
43
44
    public function url($path)
45
    {
46
        return $this->disk->url($path);
47
    }
48
49
    public function makeDirectory()
50
    {
51
        $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

51
        $this->disk->/** @scrutinizer ignore-call */ 
52
                     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...
52
53
        // some filesystems (e.g. Google Storage, S3?) don't let you set ACLs on directories (because they don't exist)
54
        // https://cloud.google.com/storage/docs/naming#object-considerations
55
        if ($this->disk->has($this->path)) {
0 ignored issues
show
Bug introduced by
The method has() does not exist on Illuminate\Contracts\Filesystem\Filesystem. It seems like you code against a sub-type of Illuminate\Contracts\Filesystem\Filesystem such as Illuminate\Filesystem\FilesystemAdapter. ( Ignorable by Annotation )

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

55
        if ($this->disk->/** @scrutinizer ignore-call */ has($this->path)) {
Loading history...
56
            $this->disk->setVisibility($this->path, 'public');
57
        }
58
    }
59
60
    public function extension()
61
    {
62
        setlocale(LC_ALL, 'en_US.UTF-8');
63
        return pathinfo($this->path, PATHINFO_EXTENSION);
64
    }
65
}
66