Passed
Pull Request — master (#1065)
by
unknown
03:45
created

FolderController::getFolders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 18
rs 9.8666
1
<?php
2
3
namespace UniSharp\LaravelFilemanager\Controllers;
4
5
use UniSharp\LaravelFilemanager\Events\FolderIsCreating;
6
use UniSharp\LaravelFilemanager\Events\FolderWasCreated;
7
use Illuminate\Support\Str;
8
class FolderController extends LfmController
9
{
10
    /**
11
     * Get list of folders as json to populate treeview.
12
     *
13
     * @return mixed
14
     */
15
    public function getFolders()
16
    {
17
        $folder_types = array_filter(['user', 'share'], function ($type) {
18
            return $this->helper->allowFolderType($type);
0 ignored issues
show
Bug introduced by
The method allowFolderType() does not exist on null. ( Ignorable by Annotation )

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

18
            return $this->helper->/** @scrutinizer ignore-call */ allowFolderType($type);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug Best Practice introduced by
The property helper does not exist on UniSharp\LaravelFilemana...ollers\FolderController. Since you implemented __get, consider adding a @property annotation.
Loading history...
19
        });
20
21
        return view('laravel-filemanager::tree')
0 ignored issues
show
Bug introduced by
The function view was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

21
        return /** @scrutinizer ignore-call */ view('laravel-filemanager::tree')
Loading history...
22
            ->with([
23
                'root_folders' => array_map(function ($type) use ($folder_types) {
24
                    $path = $this->lfm->dir($this->helper->getRootFolder($type));
0 ignored issues
show
Bug Best Practice introduced by
The property helper does not exist on UniSharp\LaravelFilemana...ollers\FolderController. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property lfm does not exist on UniSharp\LaravelFilemana...ollers\FolderController. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
The method dir() does not exist on null. ( Ignorable by Annotation )

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

24
                    /** @scrutinizer ignore-call */ 
25
                    $path = $this->lfm->dir($this->helper->getRootFolder($type));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
25
26
                    return (object) [
27
                        'name' => trans('laravel-filemanager::lfm.title-' . $type),
0 ignored issues
show
Unused Code introduced by
The call to trans() has too many arguments starting with 'laravel-filemanager::lfm.title-' . $type. ( Ignorable by Annotation )

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

27
                        'name' => /** @scrutinizer ignore-call */ trans('laravel-filemanager::lfm.title-' . $type),

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...
Bug introduced by
Are you sure the usage of trans('laravel-filemanager::lfm.title-' . $type) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
28
                        'url' => $path->path('working_dir'),
29
                        'children' => $path->folders(),
30
                        'has_next' => ! ($type == end($folder_types)),
31
                    ];
32
                }, $folder_types),
33
            ]);
34
    }
35
36
    /**
37
     * Add a new folder.
38
     *
39
     * @return mixed
40
     */
41
    public function getAddfolder()
42
    {
43
        $folder_name = $this->helper->input('name');
0 ignored issues
show
Bug Best Practice introduced by
The property helper does not exist on UniSharp\LaravelFilemana...ollers\FolderController. Since you implemented __get, consider adding a @property annotation.
Loading history...
44
45
        $folder_name = Str::slug($folder_name, '_');
46
47
        $new_path = $this->lfm->setName($folder_name)->path('absolute');
0 ignored issues
show
Bug Best Practice introduced by
The property lfm does not exist on UniSharp\LaravelFilemana...ollers\FolderController. Since you implemented __get, consider adding a @property annotation.
Loading history...
48
49
        event(new FolderIsCreating($new_path));
0 ignored issues
show
Bug introduced by
The function event was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

49
        /** @scrutinizer ignore-call */ 
50
        event(new FolderIsCreating($new_path));
Loading history...
50
51
        try {
52
            if ($folder_name === null || $folder_name == '') {
53
                return $this->helper->error('folder-name');
54
            } elseif ($this->lfm->setName($folder_name)->exists()) {
55
                return $this->helper->error('folder-exist');
56
            } else {
57
                $this->lfm->setName($folder_name)->createFolder();
58
            }
59
        } catch (\Exception $e) {
60
            return $e->getMessage();
61
        }
62
63
        event(new FolderWasCreated($new_path));
64
65
        return parent::$success_response;
66
    }
67
}
68