mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 09:34:04 +00:00
phpstan fixes
This commit is contained in:
parent
3c183e45d9
commit
f955b38e2b
12 changed files with 24 additions and 21 deletions
|
|
@ -35,7 +35,7 @@
|
||||||
"doctrine/dbal": "^3.6.0",
|
"doctrine/dbal": "^3.6.0",
|
||||||
"spatie/valuestore": "^1.2.5",
|
"spatie/valuestore": "^1.2.5",
|
||||||
"pestphp/pest": "^2.0",
|
"pestphp/pest": "^2.0",
|
||||||
"larastan/larastan": "^2.4",
|
"larastan/larastan": "^3.0",
|
||||||
"spatie/invade": "^1.1",
|
"spatie/invade": "^1.1",
|
||||||
"aws/aws-sdk-php-laravel": "~3.0"
|
"aws/aws-sdk-php-laravel": "~3.0"
|
||||||
},
|
},
|
||||||
|
|
@ -75,7 +75,7 @@
|
||||||
"coverage": "open coverage/phpunit/html/index.html",
|
"coverage": "open coverage/phpunit/html/index.html",
|
||||||
"phpstan": "vendor/bin/phpstan --memory-limit=256M",
|
"phpstan": "vendor/bin/phpstan --memory-limit=256M",
|
||||||
"phpstan-pro": "vendor/bin/phpstan --memory-limit=256M --pro",
|
"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": "./test --no-coverage",
|
||||||
"test-full": "./test",
|
"test-full": "./test",
|
||||||
"act": "act -j tests --matrix 'laravel:^11.0'",
|
"act": "act -j tests --matrix 'laravel:^11.0'",
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ parameters:
|
||||||
- Illuminate\Database\Eloquent\Model
|
- Illuminate\Database\Eloquent\Model
|
||||||
|
|
||||||
ignoreErrors:
|
ignoreErrors:
|
||||||
-
|
- identifier: trait.unused
|
||||||
identifier: missingType.iterableValue
|
- identifier: missingType.iterableValue
|
||||||
- '#FFI#'
|
- '#FFI#'
|
||||||
- '#Return type(.*?) of method Stancl\\Tenancy\\Database\\Models\\Tenant\:\:newCollection\(\) should be compatible with return type#'
|
- '#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#'
|
- '#Method Stancl\\Tenancy\\Database\\Models\\Tenant\:\:newCollection\(\) should return#'
|
||||||
|
|
|
||||||
|
|
@ -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
|
protected function getTenantChunks(): Collection
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,9 @@ use Stancl\Tenancy\Events\PullingPendingTenant;
|
||||||
/**
|
/**
|
||||||
* @property ?Carbon $pending_since
|
* @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<static>|\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<static>|\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 withoutPending()
|
||||||
*/
|
*/
|
||||||
trait HasPending
|
trait HasPending
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ use Stancl\Tenancy\Database\TenantDatabaseManagers\TenantDatabaseManager;
|
||||||
/**
|
/**
|
||||||
* @method \Illuminate\Database\Connection database()
|
* @method \Illuminate\Database\Connection database()
|
||||||
* @mixin TenantDatabaseManager
|
* @mixin TenantDatabaseManager
|
||||||
|
* @phpstan-require-extends TenantDatabaseManager
|
||||||
*/
|
*/
|
||||||
trait ManagesPostgresUsers
|
trait ManagesPostgresUsers
|
||||||
{
|
{
|
||||||
|
|
@ -40,8 +41,6 @@ trait ManagesPostgresUsers
|
||||||
|
|
||||||
public function deleteUser(DatabaseConfig $databaseConfig): bool
|
public function deleteUser(DatabaseConfig $databaseConfig): bool
|
||||||
{
|
{
|
||||||
/** @var TenantDatabaseManager $this */
|
|
||||||
|
|
||||||
// Tenant DB username
|
// Tenant DB username
|
||||||
$username = $databaseConfig->getUsername();
|
$username = $databaseConfig->getUsername();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,12 @@ declare(strict_types=1);
|
||||||
namespace Stancl\Tenancy\Database\Concerns;
|
namespace Stancl\Tenancy\Database\Concerns;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use Illuminate\Foundation\Bus\PendingDispatch;
|
||||||
use Stancl\Tenancy\Contracts\Tenant;
|
use Stancl\Tenancy\Contracts\Tenant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @phpstan-require-implements Tenant
|
||||||
|
*/
|
||||||
trait TenantRun
|
trait TenantRun
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
@ -16,11 +20,10 @@ trait TenantRun
|
||||||
*
|
*
|
||||||
* @template T
|
* @template T
|
||||||
* @param Closure(Tenant): T $callback
|
* @param Closure(Tenant): T $callback
|
||||||
* @return T
|
* @return (T is PendingDispatch ? null : T)
|
||||||
*/
|
*/
|
||||||
public function run(Closure $callback): mixed
|
public function run(Closure $callback): mixed
|
||||||
{
|
{
|
||||||
/** @var Tenant $this */
|
|
||||||
return tenancy()->run($this, $callback);
|
return tenancy()->run($this, $callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ use Symfony\Component\Finder\SplFileInfo;
|
||||||
|
|
||||||
class TraitRLSManager implements RLSPolicyManager
|
class TraitRLSManager implements RLSPolicyManager
|
||||||
{
|
{
|
||||||
/** @var Closure: array<\Illuminate\Database\Eloquent\Model> */
|
/** @var Closure(): array<Model> */
|
||||||
public static Closure|null $modelDiscoveryOverride = null;
|
public static Closure|null $modelDiscoveryOverride = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,6 @@ class DomainTenantResolver extends Contracts\CachedTenantResolver
|
||||||
$tenant->domain, // Current domain
|
$tenant->domain, // Current domain
|
||||||
]);
|
]);
|
||||||
} elseif (method_exists($tenant, 'domains') && $tenant->domains() instanceof Relation) {
|
} elseif (method_exists($tenant, 'domains') && $tenant->domains() instanceof Relation) {
|
||||||
/** @var Tenant&Model $tenant */
|
|
||||||
$tenant->unsetRelation('domains');
|
$tenant->unsetRelation('domains');
|
||||||
|
|
||||||
$domains = $tenant->domains->map(function (Domain&Model $domain) {
|
$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\Database\Eloquent\Relations\Pivot;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Stancl\Tenancy\Contracts\Tenant;
|
use Stancl\Tenancy\Contracts\Tenant;
|
||||||
|
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
||||||
use Stancl\Tenancy\Database\TenantCollection;
|
use Stancl\Tenancy\Database\TenantCollection;
|
||||||
use Stancl\Tenancy\Listeners\QueueableListener;
|
use Stancl\Tenancy\Listeners\QueueableListener;
|
||||||
use Stancl\Tenancy\ResourceSyncing\Events\SyncedResourceSaved;
|
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.
|
// 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) {
|
$currentTenantMapping = function ($model) use ($event) {
|
||||||
/** @var Tenant */
|
/** @var TenantWithDatabase */
|
||||||
$tenant = $event->tenant;
|
$tenant = $event->tenant;
|
||||||
|
|
||||||
return ((string) $model->pivot->getAttribute(Tenancy::tenantKeyColumn())) === ((string) $tenant->getTenantKey());
|
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
|
// 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
|
// even if people use their own pivot model that is not based on our TenantPivot
|
||||||
Pivot::withoutEvents(function () use ($centralModel, $event) {
|
Pivot::withoutEvents(function () use ($centralModel, $event) {
|
||||||
/** @var Tenant */
|
/** @var TenantWithDatabase */
|
||||||
$tenant = $event->tenant;
|
$tenant = $event->tenant;
|
||||||
|
|
||||||
$centralModel->tenants()->attach($tenant->getTenantKey());
|
$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?
|
// 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
|
interface SyncMaster extends Syncable
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ trait TriggerSyncingEvents
|
||||||
|
|
||||||
public function getCentralResourceAndTenant(): array
|
public function getCentralResourceAndTenant(): array
|
||||||
{
|
{
|
||||||
/** @var static&Pivot $this */
|
/** @var $this&Pivot $this */
|
||||||
$parent = $this->pivotParent;
|
$parent = $this->pivotParent;
|
||||||
|
|
||||||
if ($parent instanceof Tenant) {
|
if ($parent instanceof Tenant) {
|
||||||
|
|
@ -79,7 +79,7 @@ trait TriggerSyncingEvents
|
||||||
*/
|
*/
|
||||||
protected function getResourceClass(): string
|
protected function getResourceClass(): string
|
||||||
{
|
{
|
||||||
/** @var Pivot|MorphPivot|((Pivot|MorphPivot)&PivotWithRelation) $this */
|
/** @var $this&(Pivot|MorphPivot|((Pivot|MorphPivot)&PivotWithRelation)) $this */
|
||||||
if ($this instanceof PivotWithRelation) {
|
if ($this instanceof PivotWithRelation) {
|
||||||
return $this->getRelatedModel()::class;
|
return $this->getRelatedModel()::class;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ namespace Stancl\Tenancy;
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Foundation\Bus\PendingDispatch;
|
||||||
use Illuminate\Support\Traits\Macroable;
|
use Illuminate\Support\Traits\Macroable;
|
||||||
use Stancl\Tenancy\Concerns\DealsWithRouteContexts;
|
use Stancl\Tenancy\Concerns\DealsWithRouteContexts;
|
||||||
use Stancl\Tenancy\Concerns\ManagesRLSPolicies;
|
use Stancl\Tenancy\Concerns\ManagesRLSPolicies;
|
||||||
|
|
@ -71,7 +72,7 @@ class Tenancy
|
||||||
*
|
*
|
||||||
* @template T
|
* @template T
|
||||||
* @param Closure(Tenant): T $callback
|
* @param Closure(Tenant): T $callback
|
||||||
* @return T
|
* @return (T is PendingDispatch ? null : T)
|
||||||
*/
|
*/
|
||||||
public function run(Tenant $tenant, Closure $callback): mixed
|
public function run(Tenant $tenant, Closure $callback): mixed
|
||||||
{
|
{
|
||||||
|
|
@ -80,7 +81,7 @@ class Tenancy
|
||||||
$this->initialize($tenant);
|
$this->initialize($tenant);
|
||||||
$result = $callback($tenant);
|
$result = $callback($tenant);
|
||||||
|
|
||||||
if ($result instanceof \Illuminate\Foundation\Bus\PendingDispatch) { // #1277
|
if ($result instanceof PendingDispatch) { // #1277
|
||||||
$result = null;
|
$result = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue