MultiUser::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace UniSharp\LaravelFilemanager\Middlewares;
4
5
use Closure;
6
use Illuminate\Support\Str;
7
use UniSharp\LaravelFilemanager\Lfm;
8
9
class MultiUser
10
{
11
    private $helper;
12
13
    public function __construct()
14
    {
15
        $this->helper = app(Lfm::class);
0 ignored issues
show
Bug introduced by
The function app 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

15
        $this->helper = /** @scrutinizer ignore-call */ app(Lfm::class);
Loading history...
16
    }
17
18
    public function handle($request, Closure $next)
19
    {
20
        if ($this->helper->allowFolderType('user')) {
21
            $previous_dir = $request->input('working_dir');
22
            $working_dir = $this->helper->getRootFolder('user');
23
24
            if ($previous_dir == null) {
25
                $request->merge(compact('working_dir'));
26
            } elseif (! $this->validDir($previous_dir)) {
27
                $request->replace(compact('working_dir'));
28
            }
29
        }
30
31
        return $next($request);
32
    }
33
34
    private function validDir($previous_dir)
35
    {
36
        if (Str::startsWith($previous_dir, $this->helper->getRootFolder('share'))) {
37
            return true;
38
        }
39
40
        if (Str::startsWith($previous_dir, $this->helper->getRootFolder('user'))) {
41
            return true;
42
        }
43
44
        return false;
45
    }
46
}
47