mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 11:34:03 +00:00
get down to 21 phpstan errors
This commit is contained in:
parent
a94227a19c
commit
f98a901aeb
16 changed files with 85 additions and 26 deletions
|
|
@ -99,19 +99,30 @@ class Tenancy
|
|||
{
|
||||
$class = config('tenancy.tenant_model');
|
||||
|
||||
return new $class;
|
||||
/** @var Tenant&Model $model */
|
||||
$model = new $class;
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to find a tenant using an ID.
|
||||
*
|
||||
* @return (Tenant&Model)|null
|
||||
*/
|
||||
public static function find(int|string $id): Tenant|null
|
||||
{
|
||||
return static::model()->where(static::model()->getTenantKeyName(), $id)->first();
|
||||
/** @var (Tenant&Model)|null */
|
||||
$tenant = static::model()->where(static::model()->getTenantKeyName(), $id)->first();
|
||||
|
||||
return $tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a callback in the central context.
|
||||
* Atomic, safely reverts to previous context.
|
||||
*/
|
||||
public function central(Closure $callback)
|
||||
public function central(Closure $callback): mixed
|
||||
{
|
||||
$previousTenant = $this->tenant;
|
||||
|
||||
|
|
@ -132,7 +143,7 @@ class Tenancy
|
|||
* Run a callback for multiple tenants.
|
||||
* More performant than running $tenant->run() one by one.
|
||||
*
|
||||
* @param array<Tenant>|array<string>|\Traversable|null $tenants
|
||||
* @param array<Tenant>|array<string|int>|\Traversable|string|int|null $tenants
|
||||
*/
|
||||
public function runForMultiple($tenants, Closure $callback): void
|
||||
{
|
||||
|
|
@ -155,6 +166,7 @@ class Tenancy
|
|||
$tenant = $this->find($tenant);
|
||||
}
|
||||
|
||||
/** @var Tenant $tenant */
|
||||
$this->initialize($tenant);
|
||||
$callback($tenant);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue