diff --git a/composer.json b/composer.json index 851f4ca1..a63e828f 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "doctrine/dbal": "^3.6.0", "spatie/valuestore": "^1.2.5", "pestphp/pest": "^2.0", - "larastan/larastan": "^2.4", + "larastan/larastan": "^3.0", "spatie/invade": "^1.1", "aws/aws-sdk-php-laravel": "~3.0" }, @@ -75,7 +75,7 @@ "coverage": "open coverage/phpunit/html/index.html", "phpstan": "vendor/bin/phpstan --memory-limit=256M", "phpstan-pro": "vendor/bin/phpstan --memory-limit=256M --pro", - "cs": "php-cs-fixer fix --config=.php-cs-fixer.php", + "cs": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --config=.php-cs-fixer.php", "test": "./test --no-coverage", "test-full": "./test", "act": "act -j tests --matrix 'laravel:^11.0'", diff --git a/phpstan.neon b/phpstan.neon index c4c667b1..984f5d2c 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -14,8 +14,8 @@ parameters: - Illuminate\Database\Eloquent\Model ignoreErrors: - - - identifier: missingType.iterableValue + - identifier: trait.unused + - identifier: missingType.iterableValue - '#FFI#' - '#Return type(.*?) of method Stancl\\Tenancy\\Database\\Models\\Tenant\:\:newCollection\(\) should be compatible with return type#' - '#Method Stancl\\Tenancy\\Database\\Models\\Tenant\:\:newCollection\(\) should return#' diff --git a/src/Concerns/ParallelCommand.php b/src/Concerns/ParallelCommand.php index 0eaa0fbe..14b7d083 100644 --- a/src/Concerns/ParallelCommand.php +++ b/src/Concerns/ParallelCommand.php @@ -136,7 +136,7 @@ trait ParallelCommand } /** - * @return Collection>> + * @return Collection> */ protected function getTenantChunks(): Collection { diff --git a/src/Database/Concerns/HasPending.php b/src/Database/Concerns/HasPending.php index ce0b1a37..8142e0ea 100644 --- a/src/Database/Concerns/HasPending.php +++ b/src/Database/Concerns/HasPending.php @@ -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|\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() */ trait HasPending { diff --git a/src/Database/Concerns/ManagesPostgresUsers.php b/src/Database/Concerns/ManagesPostgresUsers.php index c798fe13..bec94f49 100644 --- a/src/Database/Concerns/ManagesPostgresUsers.php +++ b/src/Database/Concerns/ManagesPostgresUsers.php @@ -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(); diff --git a/src/Database/Concerns/TenantRun.php b/src/Database/Concerns/TenantRun.php index b312e3aa..779c9149 100644 --- a/src/Database/Concerns/TenantRun.php +++ b/src/Database/Concerns/TenantRun.php @@ -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); } } diff --git a/src/RLS/PolicyManagers/TraitRLSManager.php b/src/RLS/PolicyManagers/TraitRLSManager.php index 8c0af518..52ed15ea 100644 --- a/src/RLS/PolicyManagers/TraitRLSManager.php +++ b/src/RLS/PolicyManagers/TraitRLSManager.php @@ -14,7 +14,7 @@ use Symfony\Component\Finder\SplFileInfo; class TraitRLSManager implements RLSPolicyManager { - /** @var Closure: array<\Illuminate\Database\Eloquent\Model> */ + /** @var Closure(): array */ public static Closure|null $modelDiscoveryOverride = null; /** diff --git a/src/Resolvers/DomainTenantResolver.php b/src/Resolvers/DomainTenantResolver.php index b5767172..9535cdf2 100644 --- a/src/Resolvers/DomainTenantResolver.php +++ b/src/Resolvers/DomainTenantResolver.php @@ -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) { diff --git a/src/ResourceSyncing/Listeners/UpdateOrCreateSyncedResource.php b/src/ResourceSyncing/Listeners/UpdateOrCreateSyncedResource.php index ff64a782..8677fc21 100644 --- a/src/ResourceSyncing/Listeners/UpdateOrCreateSyncedResource.php +++ b/src/ResourceSyncing/Listeners/UpdateOrCreateSyncedResource.php @@ -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()); diff --git a/src/ResourceSyncing/SyncMaster.php b/src/ResourceSyncing/SyncMaster.php index aba1dfca..9a373930 100644 --- a/src/ResourceSyncing/SyncMaster.php +++ b/src/ResourceSyncing/SyncMaster.php @@ -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 $tenants + * @property-read TenantWithDatabase[]|Collection $tenants */ interface SyncMaster extends Syncable { diff --git a/src/ResourceSyncing/TriggerSyncingEvents.php b/src/ResourceSyncing/TriggerSyncingEvents.php index 3ba86484..eec1b13d 100644 --- a/src/ResourceSyncing/TriggerSyncingEvents.php +++ b/src/ResourceSyncing/TriggerSyncingEvents.php @@ -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; } diff --git a/src/Tenancy.php b/src/Tenancy.php index bc88dc67..7e509481 100644 --- a/src/Tenancy.php +++ b/src/Tenancy.php @@ -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; }