mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 17:44:04 +00:00
[4.x] General code cleanup (#1278)
* Declare sensitive parameters as sensitive ... just so that they don't show up in logs * Remove unnecessary null-coalescing * Simplify return * Merge isset() calls * Inline return * Use nullsafe operator * Simplify if-else branches * Use direct empty string comparison instead of strlen() * Add missing type * Change interface as events expect a TenantWithDatabase not just a Tenant * Narrow typehint * Remove redundant type casts * Fix style with php-cs-fixer * Fix typos * Revert unwanted if-else simplification * fix phpstan errors * narrow type --------- Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
parent
05b602e37f
commit
79f740d057
24 changed files with 45 additions and 53 deletions
|
|
@ -7,8 +7,8 @@ namespace Stancl\Tenancy\ResourceSyncing;
|
|||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Stancl\Tenancy\Contracts\Tenant;
|
||||
use Stancl\Tenancy\Contracts\UniqueIdentifierGenerator;
|
||||
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
||||
use Stancl\Tenancy\ResourceSyncing\Events\CentralResourceAttachedToTenant;
|
||||
use Stancl\Tenancy\ResourceSyncing\Events\CentralResourceDetachedFromTenant;
|
||||
use Stancl\Tenancy\ResourceSyncing\Events\SyncedResourceSaved;
|
||||
|
|
@ -78,7 +78,7 @@ trait ResourceSyncing
|
|||
}
|
||||
|
||||
/** Default implementation for \Stancl\Tenancy\ResourceSyncing\SyncMaster */
|
||||
public function triggerAttachEvent(Tenant&Model $tenant): void
|
||||
public function triggerAttachEvent(TenantWithDatabase&Model $tenant): void
|
||||
{
|
||||
if ($this instanceof SyncMaster) {
|
||||
/** @var SyncMaster&Model $this */
|
||||
|
|
@ -87,7 +87,7 @@ trait ResourceSyncing
|
|||
}
|
||||
|
||||
/** Default implementation for \Stancl\Tenancy\ResourceSyncing\SyncMaster */
|
||||
public function triggerDetachEvent(Tenant&Model $tenant): void
|
||||
public function triggerDetachEvent(TenantWithDatabase&Model $tenant): void
|
||||
{
|
||||
if ($this instanceof SyncMaster) {
|
||||
/** @var SyncMaster&Model $this */
|
||||
|
|
|
|||
|
|
@ -7,25 +7,25 @@ namespace Stancl\Tenancy\ResourceSyncing;
|
|||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Stancl\Tenancy\Contracts\Tenant;
|
||||
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
||||
|
||||
// todo@move move all resource syncing-related things to a separate namespace?
|
||||
|
||||
/**
|
||||
* @property-read Tenant[]|Collection $tenants
|
||||
* @property-read TenantWithDatabase[]|Collection<TenantWithDatabase> $tenants
|
||||
*/
|
||||
interface SyncMaster extends Syncable
|
||||
{
|
||||
/**
|
||||
* @return BelongsToMany<Tenant&Model, self&Model>
|
||||
* @return BelongsToMany<TenantWithDatabase&Model, self&Model>
|
||||
*/
|
||||
public function tenants(): BelongsToMany;
|
||||
|
||||
public function getTenantModelName(): string;
|
||||
|
||||
public function triggerDetachEvent(Tenant&Model $tenant): void;
|
||||
public function triggerDetachEvent(TenantWithDatabase&Model $tenant): void;
|
||||
|
||||
public function triggerAttachEvent(Tenant&Model $tenant): void;
|
||||
public function triggerAttachEvent(TenantWithDatabase&Model $tenant): void;
|
||||
|
||||
public function triggerDeleteEvent(bool $forceDelete = false): void;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||
use Illuminate\Database\Eloquent\Relations\MorphPivot;
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
use Stancl\Tenancy\Contracts\Tenant;
|
||||
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
||||
|
||||
/**
|
||||
* Used on pivot models.
|
||||
|
|
@ -30,7 +31,7 @@ trait TriggerSyncingEvents
|
|||
/**
|
||||
* @var static&Pivot $pivot
|
||||
* @var SyncMaster|null $centralResource
|
||||
* @var (Tenant&Model)|null $tenant
|
||||
* @var (TenantWithDatabase&Model)|null $tenant
|
||||
*/
|
||||
[$centralResource, $tenant] = $pivot->getCentralResourceAndTenant();
|
||||
|
||||
|
|
@ -43,7 +44,7 @@ trait TriggerSyncingEvents
|
|||
/**
|
||||
* @var static&Pivot $pivot
|
||||
* @var SyncMaster|null $centralResource
|
||||
* @var (Tenant&Model)|null $tenant
|
||||
* @var (TenantWithDatabase&Model)|null $tenant
|
||||
*/
|
||||
[$centralResource, $tenant] = $pivot->getCentralResourceAndTenant();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue