Skip to content

Commit e3701f1

Browse files
authored
[4.x] Add more relation type annotations (#1424)
This pull request adds improved PHPDoc type annotations to several Eloquent relationship methods, enhancing static analysis and developer experience. These changes clarify the expected return types for relationships, making the codebase easier to understand and work with. Relationship method type annotations: * Added a detailed return type annotation to the `tenant` method in the `BelongsToTenant` trait, specifying the related model and the current class. * Added a detailed return type annotation to the `domains` method in the `HasDomains` trait, specifying the related model and the current class. * Added a detailed return type annotation to the `tenants` method in the `ResourceSyncing` class, specifying the related model and the current class.
1 parent 3c0e21b commit e3701f1

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/Database/Concerns/BelongsToTenant.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ trait BelongsToTenant
1717
{
1818
use FillsCurrentTenant;
1919

20+
/**
21+
* @return BelongsTo<\Illuminate\Database\Eloquent\Model&\Stancl\Tenancy\Contracts\Tenant, $this>
22+
*/
2023
public function tenant(): BelongsTo
2124
{
2225
return $this->belongsTo(config('tenancy.models.tenant'), Tenancy::tenantKeyColumn());

src/Database/Concerns/HasDomains.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Stancl\Tenancy\Database\Concerns;
66

7+
use Illuminate\Database\Eloquent\Relations\HasMany;
78
use Stancl\Tenancy\Contracts\Domain;
89
use Stancl\Tenancy\Tenancy;
910

@@ -14,7 +15,10 @@
1415
*/
1516
trait HasDomains
1617
{
17-
public function domains()
18+
/**
19+
* @return HasMany<\Illuminate\Database\Eloquent\Model&\Stancl\Tenancy\Contracts\Domain, $this>
20+
*/
21+
public function domains(): HasMany
1822
{
1923
return $this->hasMany(config('tenancy.models.domain'), Tenancy::tenantKeyColumn());
2024
}

src/ResourceSyncing/ResourceSyncing.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ public function shouldSync(): bool
105105
return true;
106106
}
107107

108+
/**
109+
* @return BelongsToMany<\Illuminate\Database\Eloquent\Model&\Stancl\Tenancy\Database\Contracts\TenantWithDatabase, $this>
110+
*/
108111
public function tenants(): BelongsToMany
109112
{
110113
return $this->morphToMany(config('tenancy.models.tenant'), 'tenant_resources', 'tenant_resources', 'resource_global_id', 'tenant_id', $this->getGlobalIdentifierKeyName())

0 commit comments

Comments
 (0)