mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 20:54:04 +00:00
phpstan fixes
This commit is contained in:
parent
3c183e45d9
commit
f955b38e2b
12 changed files with 24 additions and 21 deletions
|
|
@ -136,7 +136,7 @@ trait ParallelCommand
|
|||
}
|
||||
|
||||
/**
|
||||
* @return Collection<int, array<int, \Stancl\Tenancy\Contracts\Tenant&\Illuminate\Database\Eloquent\Model>>>
|
||||
* @return Collection<int, array<int, \Stancl\Tenancy\Contracts\Tenant&\Illuminate\Database\Eloquent\Model>>
|
||||
*/
|
||||
protected function getTenantChunks(): Collection
|
||||
{
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@ use Stancl\Tenancy\Events\PullingPendingTenant;
|
|||
/**
|
||||
* @property ?Carbon $pending_since
|
||||
*
|
||||
* @method static static|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder withPending(bool $withPending = true)
|
||||
* @method static static|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder onlyPending()
|
||||
* @method static static|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder withoutPending()
|
||||
* @method static static|\Illuminate\Database\Eloquent\Builder<static>|\Illuminate\Database\Query\Builder withPending(bool $withPending = true)
|
||||
* @method static static|\Illuminate\Database\Eloquent\Builder<static>|\Illuminate\Database\Query\Builder onlyPending()
|
||||
* @method static static|\Illuminate\Database\Eloquent\Builder<static>|\Illuminate\Database\Query\Builder withoutPending()
|
||||
*/
|
||||
trait HasPending
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use Stancl\Tenancy\Database\TenantDatabaseManagers\TenantDatabaseManager;
|
|||
/**
|
||||
* @method \Illuminate\Database\Connection database()
|
||||
* @mixin TenantDatabaseManager
|
||||
* @phpstan-require-extends TenantDatabaseManager
|
||||
*/
|
||||
trait ManagesPostgresUsers
|
||||
{
|
||||
|
|
@ -40,8 +41,6 @@ trait ManagesPostgresUsers
|
|||
|
||||
public function deleteUser(DatabaseConfig $databaseConfig): bool
|
||||
{
|
||||
/** @var TenantDatabaseManager $this */
|
||||
|
||||
// Tenant DB username
|
||||
$username = $databaseConfig->getUsername();
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,12 @@ declare(strict_types=1);
|
|||
namespace Stancl\Tenancy\Database\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Foundation\Bus\PendingDispatch;
|
||||
use Stancl\Tenancy\Contracts\Tenant;
|
||||
|
||||
/**
|
||||
* @phpstan-require-implements Tenant
|
||||
*/
|
||||
trait TenantRun
|
||||
{
|
||||
/**
|
||||
|
|
@ -16,11 +20,10 @@ trait TenantRun
|
|||
*
|
||||
* @template T
|
||||
* @param Closure(Tenant): T $callback
|
||||
* @return T
|
||||
* @return (T is PendingDispatch ? null : T)
|
||||
*/
|
||||
public function run(Closure $callback): mixed
|
||||
{
|
||||
/** @var Tenant $this */
|
||||
return tenancy()->run($this, $callback);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use Symfony\Component\Finder\SplFileInfo;
|
|||
|
||||
class TraitRLSManager implements RLSPolicyManager
|
||||
{
|
||||
/** @var Closure: array<\Illuminate\Database\Eloquent\Model> */
|
||||
/** @var Closure(): array<Model> */
|
||||
public static Closure|null $modelDiscoveryOverride = null;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -84,7 +84,6 @@ class DomainTenantResolver extends Contracts\CachedTenantResolver
|
|||
$tenant->domain, // Current domain
|
||||
]);
|
||||
} elseif (method_exists($tenant, 'domains') && $tenant->domains() instanceof Relation) {
|
||||
/** @var Tenant&Model $tenant */
|
||||
$tenant->unsetRelation('domains');
|
||||
|
||||
$domains = $tenant->domains->map(function (Domain&Model $domain) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Stancl\Tenancy\Contracts\Tenant;
|
||||
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
||||
use Stancl\Tenancy\Database\TenantCollection;
|
||||
use Stancl\Tenancy\Listeners\QueueableListener;
|
||||
use Stancl\Tenancy\ResourceSyncing\Events\SyncedResourceSaved;
|
||||
|
|
@ -93,7 +94,7 @@ class UpdateOrCreateSyncedResource extends QueueableListener
|
|||
|
||||
// If the model was just created, the mapping of the tenant to the user likely doesn't exist, so we create it.
|
||||
$currentTenantMapping = function ($model) use ($event) {
|
||||
/** @var Tenant */
|
||||
/** @var TenantWithDatabase */
|
||||
$tenant = $event->tenant;
|
||||
|
||||
return ((string) $model->pivot->getAttribute(Tenancy::tenantKeyColumn())) === ((string) $tenant->getTenantKey());
|
||||
|
|
@ -105,7 +106,7 @@ class UpdateOrCreateSyncedResource extends QueueableListener
|
|||
// Here we should call TenantPivot, but we call general Pivot, so that this works
|
||||
// even if people use their own pivot model that is not based on our TenantPivot
|
||||
Pivot::withoutEvents(function () use ($centralModel, $event) {
|
||||
/** @var Tenant */
|
||||
/** @var TenantWithDatabase */
|
||||
$tenant = $event->tenant;
|
||||
|
||||
$centralModel->tenants()->attach($tenant->getTenantKey());
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
|||
// todo@move move all resource syncing-related things to a separate namespace?
|
||||
|
||||
/**
|
||||
* @property-read TenantWithDatabase[]|Collection<TenantWithDatabase> $tenants
|
||||
* @property-read TenantWithDatabase[]|Collection<int, TenantWithDatabase&Model> $tenants
|
||||
*/
|
||||
interface SyncMaster extends Syncable
|
||||
{
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ trait TriggerSyncingEvents
|
|||
|
||||
public function getCentralResourceAndTenant(): array
|
||||
{
|
||||
/** @var static&Pivot $this */
|
||||
/** @var $this&Pivot $this */
|
||||
$parent = $this->pivotParent;
|
||||
|
||||
if ($parent instanceof Tenant) {
|
||||
|
|
@ -79,7 +79,7 @@ trait TriggerSyncingEvents
|
|||
*/
|
||||
protected function getResourceClass(): string
|
||||
{
|
||||
/** @var Pivot|MorphPivot|((Pivot|MorphPivot)&PivotWithRelation) $this */
|
||||
/** @var $this&(Pivot|MorphPivot|((Pivot|MorphPivot)&PivotWithRelation)) $this */
|
||||
if ($this instanceof PivotWithRelation) {
|
||||
return $this->getRelatedModel()::class;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ namespace Stancl\Tenancy;
|
|||
use Closure;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Foundation\Bus\PendingDispatch;
|
||||
use Illuminate\Support\Traits\Macroable;
|
||||
use Stancl\Tenancy\Concerns\DealsWithRouteContexts;
|
||||
use Stancl\Tenancy\Concerns\ManagesRLSPolicies;
|
||||
|
|
@ -71,7 +72,7 @@ class Tenancy
|
|||
*
|
||||
* @template T
|
||||
* @param Closure(Tenant): T $callback
|
||||
* @return T
|
||||
* @return (T is PendingDispatch ? null : T)
|
||||
*/
|
||||
public function run(Tenant $tenant, Closure $callback): mixed
|
||||
{
|
||||
|
|
@ -80,7 +81,7 @@ class Tenancy
|
|||
$this->initialize($tenant);
|
||||
$result = $callback($tenant);
|
||||
|
||||
if ($result instanceof \Illuminate\Foundation\Bus\PendingDispatch) { // #1277
|
||||
if ($result instanceof PendingDispatch) { // #1277
|
||||
$result = null;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue