CreateDefaultFolder::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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

16
        $this->lfm = /** @scrutinizer ignore-call */ app(LfmPath::class);
Loading history...
17
        $this->helper = app(Lfm::class);
18
    }
19
20
    public function handle($request, Closure $next)
21
    {
22
        $this->checkDefaultFolderExists('user');
23
        $this->checkDefaultFolderExists('share');
24
25
        return $next($request);
26
    }
27
28
    private function checkDefaultFolderExists($type = 'share')
29
    {
30
        if (! $this->helper->allowFolderType($type)) {
31
            return;
32
        }
33
34
        $this->lfm->dir($this->helper->getRootFolder($type))->createFolder();
35
    }
36
}
37