Completed
Push — develop ( c9eca1...366df2 )
by Abdelrahman
01:26
created

Tenantable::handle()   C

Complexity

Conditions 7
Paths 13

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 23
rs 6.7272
c 2
b 0
f 0
cc 7
eloc 11
nc 13
nop 2
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('name', $subdomain)->first();
23
24
        if ($subdomain && ! $tenant) {
25
            return intend([
26
                'url' => route('frontarea.home'),
27
                'with' => ['warning' => trans('cortex/foundation::messages.resource_not_found', ['resource' => 'tenant', 'id' => $subdomain])],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 143 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
        // Scope bouncer
32
        (! $tenant || ! app()->bound(\Silber\Bouncer\Bouncer::class)) || app(\Silber\Bouncer\Bouncer::class)->scope()->to($tenant->getKey());
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 141 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...
33
34
        // unBind {subdomain} route parameter
35
        ! $request->route('subdomain') || $request->route()->forgetParameter('subdomain');
36
37
        // Activate current tenant
38
        ! $tenant || config(['rinvex.tenants.active' => $tenant]);
39
40
        return $next($request);
41
    }
42
}
43