TenantConnectionResolver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 8
Bugs 4 Features 0
Metric Value
eloc 9
c 8
b 4
f 0
dl 0
loc 16
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConnectionName() 0 14 5
1
<?php
2
3
namespace App\Traits;
4
5
use Illuminate\Support\Facades\App;
6
use Illuminate\Support\Facades\Auth;
7
8
trait TenantConnectionResolver
9
{
10
    public function getConnectionName()
11
    {
12
        if (! App::runningUnitTests() && Auth::check()) {
13
            $user = \Auth::user();
14
            $role_id = $user->role_id;
0 ignored issues
show
Unused Code introduced by
The assignment to $role_id is dead and can be removed.
Loading history...
Bug introduced by
Accessing role_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
15
            if ($user->isAdmin()) {
0 ignored issues
show
Bug introduced by
The method isAdmin() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

15
            if ($user->/** @scrutinizer ignore-call */ isAdmin()) {
Loading history...
16
                return env('DB_DATABASE', 'genealogy'); //'enso');
17
            }
18
            if (session()->get('db')) {
19
                return 'tenantdb';
20
            }
21
        }
22
23
        return $this->connection;
24
    }
25
}
26