Skip to content

Commit

Permalink
phpstan fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stancl committed Jan 5, 2025
1 parent 3c183e4 commit f955b38
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 21 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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'",
Expand Down
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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#'
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/ParallelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected function getProcesses(): int
}

/**
* @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
{
Expand Down
6 changes: 3 additions & 3 deletions src/Database/Concerns/HasPending.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
/**
* @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
{
Expand Down
3 changes: 1 addition & 2 deletions src/Database/Concerns/ManagesPostgresUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/**
* @method \Illuminate\Database\Connection database()
* @mixin TenantDatabaseManager
* @phpstan-require-extends TenantDatabaseManager
*/
trait ManagesPostgresUsers
{
Expand Down Expand Up @@ -40,8 +41,6 @@ public function createUser(DatabaseConfig $databaseConfig): bool

public function deleteUser(DatabaseConfig $databaseConfig): bool
{
/** @var TenantDatabaseManager $this */

// Tenant DB username
$username = $databaseConfig->getUsername();

Expand Down
7 changes: 5 additions & 2 deletions src/Database/Concerns/TenantRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
namespace Stancl\Tenancy\Database\Concerns;

use Closure;
use Illuminate\Foundation\Bus\PendingDispatch;
use Stancl\Tenancy\Contracts\Tenant;

/**
* @phpstan-require-implements Tenant
*/
trait TenantRun
{
/**
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/RLS/PolicyManagers/TraitRLSManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class TraitRLSManager implements RLSPolicyManager
{
/** @var Closure: array<\Illuminate\Database\Eloquent\Model> */
/** @var Closure(): array<Model> */
public static Closure|null $modelDiscoveryOverride = null;

/**
Expand Down
1 change: 0 additions & 1 deletion src/Resolvers/DomainTenantResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public function getPossibleCacheKeys(Tenant&Model $tenant): array
$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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
Expand Down Expand Up @@ -93,7 +94,7 @@ protected function updateResourceInCentralDatabaseAndGetTenants(SyncedResourceSa

// 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());
Expand All @@ -105,7 +106,7 @@ protected function updateResourceInCentralDatabaseAndGetTenants(SyncedResourceSa
// 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());
Expand Down
2 changes: 1 addition & 1 deletion src/ResourceSyncing/SyncMaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// 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
{
Expand Down
4 changes: 2 additions & 2 deletions src/ResourceSyncing/TriggerSyncingEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function bootTriggerSyncingEvents(): void

public function getCentralResourceAndTenant(): array
{
/** @var static&Pivot $this */
/** @var $this&Pivot $this */
$parent = $this->pivotParent;

if ($parent instanceof Tenant) {
Expand All @@ -79,7 +79,7 @@ public function getCentralResourceAndTenant(): array
*/
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;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Tenancy.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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;
Expand Down Expand Up @@ -71,7 +72,7 @@ public function initialize(Tenant|int|string $tenant): void
*
* @template T
* @param Closure(Tenant): T $callback
* @return T
* @return (T is PendingDispatch ? null : T)
*/
public function run(Tenant $tenant, Closure $callback): mixed
{
Expand All @@ -80,7 +81,7 @@ public function run(Tenant $tenant, Closure $callback): mixed
$this->initialize($tenant);
$result = $callback($tenant);

if ($result instanceof \Illuminate\Foundation\Bus\PendingDispatch) { // #1277
if ($result instanceof PendingDispatch) { // #1277
$result = null;
}

Expand Down

0 comments on commit f955b38

Please sign in to comment.