akubiczek /
applicake-backend
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Services; |
||
| 4 | |||
| 5 | use App\Models\Tenant; |
||
| 6 | use App\TenantUser; |
||
| 7 | |||
| 8 | class TenantManager |
||
| 9 | { |
||
| 10 | /* |
||
| 11 | * @var null|App\Models\Tenant |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 12 | */ |
||
| 13 | private $tenant; |
||
| 14 | |||
| 15 | public function setTenant(?Tenant $tenant) |
||
| 16 | { |
||
| 17 | $this->tenant = $tenant; |
||
|
0 ignored issues
–
show
It seems like
$tenant can also be of type App\Models\Tenant. However, the property $tenant is declared as type App\Services\App\Models\Tenant|null. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||
| 18 | |||
| 19 | return $this; |
||
| 20 | } |
||
| 21 | |||
| 22 | public function getTenant(): ?Tenant |
||
| 23 | { |
||
| 24 | return $this->tenant; |
||
| 25 | } |
||
| 26 | |||
| 27 | public function loadTenant($identifier): bool |
||
| 28 | { |
||
| 29 | $tenant = Tenant::query()->where('subdomain', '=', $identifier)->first(); |
||
| 30 | |||
| 31 | if ($tenant) { |
||
| 32 | $this->setTenant($tenant); |
||
| 33 | |||
| 34 | return true; |
||
| 35 | } |
||
| 36 | |||
| 37 | return false; |
||
| 38 | } |
||
| 39 | |||
| 40 | public function loadTenantByUsername($username): bool |
||
| 41 | { |
||
| 42 | $user = TenantUser::query()->where('username', '=', $username)->first(); |
||
| 43 | |||
| 44 | if ($user) { |
||
| 45 | $this->setTenant($user->tenant); |
||
| 46 | |||
| 47 | return true; |
||
| 48 | } |
||
| 49 | |||
| 50 | return false; |
||
| 51 | } |
||
| 52 | } |
||
| 53 |