Test Failed
Push — master ( 241100...2372f3 )
by Stream
08:09 queued 10s
created

ItemsController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 50
dl 0
loc 86
rs 10
c 2
b 1
f 0
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getItems() 0 18 1
A move() 0 20 1
A getCurrentPageFromRequest() 0 6 2
A domove() 0 28 5
1
<?php
2
3
namespace UniSharp\LaravelFilemanager\Controllers;
4
5
use UniSharp\LaravelFilemanager\Events\FileIsMoving;
6
use UniSharp\LaravelFilemanager\Events\FileWasMoving;
7
use UniSharp\LaravelFilemanager\Events\FolderIsMoving;
8
use UniSharp\LaravelFilemanager\Events\FolderWasMoving;
9
10
class ItemsController extends LfmController
11
{
12
    /**
13
     * Get the images to load for a selected folder.
14
     *
15
     * @return mixed
16
     */
17
    public function getItems()
18
    {
19
        $currentPage = self::getCurrentPageFromRequest();
20
21
        $perPage = $this->helper->getPaginationPerPage();
0 ignored issues
show
Bug introduced by
The method getPaginationPerPage() 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
        $perPage = $this->helper->getPaginationPerPage();

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...rollers\ItemsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
22
        $items = array_merge($this->lfm->folders(), $this->lfm->files());
0 ignored issues
show
Bug introduced by
The method folders() 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

22
        $items = array_merge($this->lfm->/** @scrutinizer ignore-call */ folders(), $this->lfm->files());

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 lfm does not exist on UniSharp\LaravelFilemana...rollers\ItemsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
23
24
        return [
25
            'items' => array_map(function ($item) {
26
                return $item->fill()->attributes;
27
            }, array_slice($items, ($currentPage - 1) * $perPage, $perPage)),
28
            'paginator' => [
29
                'current_page' => $currentPage,
30
                'total' => count($items),
31
                'per_page' => $perPage,
32
            ],
33
            'display' => $this->helper->getDisplayMode(),
34
            'working_dir' => $this->lfm->path('working_dir'),
35
        ];
36
    }
37
38
    public function move()
39
    {
40
        $items = request('items');
0 ignored issues
show
Bug introduced by
The function request 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

40
        $items = /** @scrutinizer ignore-call */ request('items');
Loading history...
41
        $folder_types = array_filter(['user', 'share'], function ($type) {
42
            return $this->helper->allowFolderType($type);
0 ignored issues
show
Bug Best Practice introduced by
The property helper does not exist on UniSharp\LaravelFilemana...rollers\ItemsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
43
        });
44
        return view('laravel-filemanager::move')
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

44
        return /** @scrutinizer ignore-call */ view('laravel-filemanager::move')
Loading history...
45
            ->with([
46
                'root_folders' => array_map(function ($type) use ($folder_types) {
47
                    $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...rollers\ItemsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property helper does not exist on UniSharp\LaravelFilemana...rollers\ItemsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
48
49
                    return (object) [
50
                        '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

50
                        'name' => /** @scrutinizer ignore-call */ trans('laravel-filemanager::lfm.title-' . $type),
Loading history...
51
                        'url' => $path->path('working_dir'),
52
                        'children' => $path->folders(),
53
                        'has_next' => ! ($type == end($folder_types)),
54
                    ];
55
                }, $folder_types),
56
            ])
57
            ->with('items', $items);
58
    }
59
60
    public function domove()
61
    {
62
        $target = $this->helper->input('goToFolder');
0 ignored issues
show
Bug Best Practice introduced by
The property helper does not exist on UniSharp\LaravelFilemana...rollers\ItemsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
63
        $items = $this->helper->input('items');
64
65
        foreach ($items as $item) {
66
            $old_file = $this->lfm->pretty($item);
0 ignored issues
show
Bug Best Practice introduced by
The property lfm does not exist on UniSharp\LaravelFilemana...rollers\ItemsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
67
            $is_directory = $old_file->isDirectory();
68
69
            if ($old_file->hasThumb()) {
70
                $new_file = $this->lfm->setName($item)->thumb()->dir($target);
71
                if ($is_directory) {
72
                    event(new FolderIsMoving($old_file->path(), $new_file->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

72
                    /** @scrutinizer ignore-call */ 
73
                    event(new FolderIsMoving($old_file->path(), $new_file->path()));
Loading history...
73
                } else {
74
                    event(new FileIsMoving($old_file->path(), $new_file->path()));
75
                }
76
                $this->lfm->setName($item)->thumb()->move($new_file);
77
            }
78
            $new_file = $this->lfm->setName($item)->dir($target);
79
            $this->lfm->setName($item)->move($new_file);
80
            if ($is_directory) {
81
                event(new FolderWasMoving($old_file->path(), $new_file->path()));
82
            } else {
83
                event(new FileWasMoving($old_file->path(), $new_file->path()));
84
            }
85
        };
86
87
        return parent::$success_response;
88
    }
89
90
    private static function getCurrentPageFromRequest()
91
    {
92
        $currentPage = (int) request()->get('page', 1);
0 ignored issues
show
Bug introduced by
The function request 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

92
        $currentPage = (int) /** @scrutinizer ignore-call */ request()->get('page', 1);
Loading history...
93
        $currentPage = $currentPage < 1 ? 1 : $currentPage;
94
95
        return $currentPage;
96
    }
97
}
98