AppendTenantURL::__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 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use App\Services\TenantManager;
6
use Closure;
7
8
class AppendTenantURL
9
{
10
    /**
11
     * @var App\Services\TenantManager
0 ignored issues
show
Bug introduced by
The type App\Http\Middleware\App\Services\TenantManager was not found. Did you mean App\Services\TenantManager? If so, make sure to prefix the type with \.
Loading history...
12
     */
13
    protected $tenantManager;
14
15
    public function __construct(TenantManager $tenantManager)
16
    {
17
        $this->tenantManager = $tenantManager;
0 ignored issues
show
Documentation Bug introduced by
It seems like $tenantManager of type App\Services\TenantManager is incompatible with the declared type App\Http\Middleware\App\Services\TenantManager of property $tenantManager.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
18
    }
19
20
    /**
21
     * Handle an incoming request.
22
     *
23
     * @param \Illuminate\Http\Request $request
24
     * @param \Closure                 $next
25
     *
26
     * @return mixed
27
     */
28
    public function handle($request, Closure $next)
29
    {
30
        $response = $next($request);
31
        $content = json_decode($response->content(), true);
32
33
        //if this is an oauth request then append API dedicated tenant URL
34
        if (!empty($content['access_token'])) {
35
            $content['api_url'] = url($this->tenantManager->getTenant()->subdomain);
36
            $response->setContent($content);
37
        }
38
39
        return $response;
40
    }
41
}
42