Issues (364)

app/Traits/TenantConnectionResolver.php (3 issues)

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
The assignment to $role_id is dead and can be removed.
Loading history...
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
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