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

ItemsController::domove()   A

Complexity

Conditions 5
Paths 7

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 5
eloc 19
c 1
b 1
f 0
nc 7
nop 0
dl 0
loc 28
rs 9.3222
1
<?php
2
3
namespace Xuandung38\LaravelFilemanager\Controllers;
4
5
use Xuandung38\LaravelFilemanager\Events\FileIsMoving;
6
use Xuandung38\LaravelFilemanager\Events\FileWasMoving;
7
use Xuandung38\LaravelFilemanager\Events\FolderIsMoving;
8
use Xuandung38\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
        return [
20
            'items' => array_map(function ($item) {
21
                return $item->fill()->attributes;
22
            }, 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
            }, 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 Xuandung38\LaravelFilema...rollers\ItemsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
23
            'display' => $this->helper->getDisplayMode(),
0 ignored issues
show
Bug introduced by
The method getDisplayMode() 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

23
            'display' => $this->helper->/** @scrutinizer ignore-call */ getDisplayMode(),

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 Xuandung38\LaravelFilema...rollers\ItemsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
24
            'working_dir' => $this->lfm->path('working_dir'),
25
        ];
26
    }
27
28
    public function move()
29
    {
30
        $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

30
        $items = /** @scrutinizer ignore-call */ request('items');
Loading history...
31
        $folder_types = array_filter(['user', 'share'], function ($type) {
32
            return $this->helper->allowFolderType($type);
0 ignored issues
show
Bug Best Practice introduced by
The property helper does not exist on Xuandung38\LaravelFilema...rollers\ItemsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
33
        });
34
        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

34
        return /** @scrutinizer ignore-call */ view('laravel-filemanager::move')
Loading history...
35
            ->with([
36
                'root_folders' => array_map(function ($type) use ($folder_types) {
37
                    $path = $this->lfm->dir($this->helper->getRootFolder($type));
0 ignored issues
show
Bug Best Practice introduced by
The property helper does not exist on Xuandung38\LaravelFilema...rollers\ItemsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug Best Practice introduced by
The property lfm does not exist on Xuandung38\LaravelFilema...rollers\ItemsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
38
39
                    return (object) [
40
                        'name' => __('laravel-filemanager::lfm.title-' . $type),
0 ignored issues
show
Bug introduced by
The function __ 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
                        'name' => /** @scrutinizer ignore-call */ __('laravel-filemanager::lfm.title-' . $type),
Loading history...
41
                        'url' => $path->path('working_dir'),
42
                        'children' => $path->folders(),
43
                        'has_next' => ! ($type == end($folder_types)),
44
                    ];
45
                }, $folder_types),
46
            ])
47
            ->with('items', $items);
48
    }
49
50
    public function domove()
51
    {
52
        $target = $this->helper->input('goToFolder');
0 ignored issues
show
Bug Best Practice introduced by
The property helper does not exist on Xuandung38\LaravelFilema...rollers\ItemsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
53
        $items = $this->helper->input('items');
54
55
        foreach ($items as $item) {
56
            $old_file = $this->lfm->pretty($item);
0 ignored issues
show
Bug Best Practice introduced by
The property lfm does not exist on Xuandung38\LaravelFilema...rollers\ItemsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
57
            $is_directory = $old_file->isDirectory();
58
59
            if ($old_file->hasThumb()) {
60
                $new_file = $this->lfm->setName($item)->thumb()->dir($target);
61
                if ($is_directory) {
62
                    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

62
                    /** @scrutinizer ignore-call */ 
63
                    event(new FolderIsMoving($old_file->path(), $new_file->path()));
Loading history...
63
                } else {
64
                    event(new FileIsMoving($old_file->path(), $new_file->path()));
65
                }
66
                $this->lfm->setName($item)->thumb()->move($new_file);
67
            }
68
            $new_file = $this->lfm->setName($item)->dir($target);
69
            $this->lfm->setName($item)->move($new_file);
70
            if ($is_directory) {
71
                event(new FolderWasMoving($old_file->path(), $new_file->path()));
72
            } else {
73
                event(new FileWasMoving($old_file->path(), $new_file->path()));
74
            }
75
        };
76
77
        return parent::$success_response;
78
    }
79
}
80