Completed
Push — develop ( fce6a6...d243d8 )
by Abdelrahman
03:57
created

Tenantable   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 31
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 20 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Tenants\Http\Middleware;
6
7
use Closure;
8
9
class Tenantable
10
{
11
    /**
12
     * Handle an incoming request.
13
     *
14
     * @param \Illuminate\Http\Request $request
15
     * @param \Closure                 $next
16
     *
17
     * @return mixed
18
     */
19
    public function handle($request, Closure $next)
20
    {
21
        $subdomain = $request->route('subdomain');
22
        $tenant = app('rinvex.tenants.tenant')->where('slug', $subdomain)->first();
23
24
        if ($subdomain && ! $tenant) {
25
            return intend([
26
                'url' => route('guestarea.home'),
27
                'with' => ['warning' => trans('cortex/tenants::messages.tenant.not_found', ['tenantSlug' => $subdomain])],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 122 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
28
            ]);
29
        }
30
31
        // unBind {subdomain} route parameter
32
        ! $request->route('subdomain') || $request->route()->forgetParameter('subdomain');
33
34
        // Activate current tenant
35
        ! $tenant || config(['rinvex.tenants.tenant.active' => $tenant]);
36
37
        return $next($request);
38
    }
39
}
40