Completed
Push — master ( 5e382b...96318b )
by Stream
09:47 queued 06:25
created

FolderController::getAddfolder()   B

Complexity

Conditions 7
Paths 9

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 13
c 1
b 0
f 0
nc 9
nop 0
dl 0
loc 19
rs 8.8333
1
<?php
2
3
namespace UniSharp\LaravelFilemanager\Controllers;
4
5
class FolderController extends LfmController
6
{
7
    /**
8
     * Get list of folders as json to populate treeview.
9
     *
10
     * @return mixed
11
     */
12
    public function getFolders()
13
    {
14
        $folder_types = array_filter(['user', 'share'], function ($type) {
15
            return $this->helper->allowFolderType($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 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

15
            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...
16
        });
17
18
        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

18
        return /** @scrutinizer ignore-call */ view('laravel-filemanager::tree')
Loading history...
19
            ->with([
20
                'root_folders' => array_map(function ($type) use ($folder_types) {
21
                    $path = $this->lfm->dir($this->helper->getRootFolder($type));
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...
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

21
                    /** @scrutinizer ignore-call */ 
22
                    $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...
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...
22
23
                    return (object) [
24
                        'name' => trans('laravel-filemanager::lfm.title-' . $type),
0 ignored issues
show
Bug introduced by
The function trans 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

24
                        'name' => /** @scrutinizer ignore-call */ trans('laravel-filemanager::lfm.title-' . $type),
Loading history...
25
                        'url' => $path->path('working_dir'),
26
                        'children' => $path->folders(),
27
                        'has_next' => ! ($type == end($folder_types)),
28
                    ];
29
                }, $folder_types),
30
            ]);
31
    }
32
33
    /**
34
     * Add a new folder.
35
     *
36
     * @return mixed
37
     */
38
    public function getAddfolder()
39
    {
40
        $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...
41
42
        try {
43
            if ($folder_name === null || $folder_name == '') {
44
                return $this->helper->error('folder-name');
45
            } elseif ($this->lfm->setName($folder_name)->exists()) {
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...
46
                return $this->helper->error('folder-exist');
47
            } elseif (config('lfm.alphanumeric_directory') && preg_match('/[^\w-]/i', $folder_name)) {
0 ignored issues
show
Bug introduced by
The function config 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

47
            } elseif (/** @scrutinizer ignore-call */ config('lfm.alphanumeric_directory') && preg_match('/[^\w-]/i', $folder_name)) {
Loading history...
48
                return $this->helper->error('folder-alnum');
49
            } else {
50
                $this->lfm->setName($folder_name)->createFolder();
51
            }
52
        } catch (\Exception $e) {
53
            return $e->getMessage();
54
        }
55
56
        return parent::$success_response;
57
    }
58
}
59