Passed
Push — develop ( 773331...6920d3 )
by Ngoding
15:22
created

AbstractUseLayout   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 10
c 1
b 0
f 0
dl 0
loc 40
ccs 7
cts 10
cp 0.7
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 6 1
A getLayout() 0 11 3
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
use Illuminate\Support\Facades\Config;
8
use Illuminate\Support\Facades\Session;
9
10
abstract class AbstractUseLayout
11
{
12
    /**
13
     * The default value of layout.
14
     *
15
     * @var string
16
     */
17
    public static $defaultLayout = 'default';
18
19
    /**
20
     * Handle an incoming request.
21
     *
22
     * @param  \Illuminate\Http\Request  $request
23
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
24
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
25
     */
26 3
    public function handle(Request $request, Closure $next)
27
    {
28 3
        Config::set('setting.layout', $this->getLayout());
29 3
        Session::put(['layout' => $this->getLayout()]);
30
31 3
        return $next($request);
32
    }
33
34
    /**
35
     * Return the specified value of layout.
36
     *
37
     * @return string
38
     */
39 3
    protected function getLayout(): string
40
    {
41 3
        if (property_exists($this, 'layout')) {
42 3
            return $this->layout;
43
        }
44
45
        if (method_exists($this, 'layout')) {
46
            return $this->layout();
47
        }
48
49
        return static::$defaultLayout;
50
    }
51
}
52