Move some service\type::class methods into __get(), no functional changes

This commit is contained in:
2025-05-22 17:57:39 +10:00
parent 1e496a2863
commit 72b11172c8
11 changed files with 50 additions and 94 deletions

View File

@@ -6,13 +6,6 @@ use Carbon\Carbon;
interface ServiceItem
{
/**
* Months the service is contracted for.
*
* @return int
*/
public function getContractTermAttribute(): int;
/**
* Return the Service Description.
*
@@ -20,29 +13,10 @@ interface ServiceItem
*/
public function getServiceDescriptionAttribute(): string;
/**
* Date the service expires
*/
public function getServiceExpireAttribute(): ?Carbon;
/**
* Return the Service Name.
*
* @return string
*/
public function getServiceNameAttribute(): string;
/**
* Has this service expired
*
* @return bool
*/
public function hasExpired(): bool;
/**
* Is this service in a contract
*
* @return bool
*/
public function inContract(): bool;
}

View File

@@ -44,6 +44,8 @@ class Broadband extends Type implements ServiceUsage
return $this->service_number ?: ($this->service_address ?: '-');
}
/* RELATIONS */
/**
* The usage information for broadband
*

View File

@@ -17,6 +17,15 @@ class SSL extends Type
protected $public_key = NULL;
protected $crt_parse = NULL;
public function __get($key): mixed
{
return match ($key) {
'in_contract' => FALSE,
default => parent::__get($key),
};
}
/* STATIC METHODS */
public static function boot()
@@ -82,25 +91,4 @@ class SSL extends Type
? Arr::get($this->crt_parse,'subject.CN')
: Arr::get(openssl_csr_get_subject($this->csr),'CN','');
}
/**
* Certificates have no contract and can be cancelled anytime.
*
* @return bool
*/
public function inContract(): bool
{
return FALSE;
}
/* METHODS */
/**
* @return Carbon|null
* @deprecated use getServiceExpireAttribute()
*/
public function getValidToAttribute()
{
abort(500,'use getServiceExpireAttribute');
}
}

View File

@@ -22,6 +22,17 @@ abstract class Type extends Model implements ServiceItem
public $timestamps = FALSE;
public function __get($key): mixed
{
return match ($key) {
'contract_term' => $this->service->offering->contract_term,
'has_expired' => (! $this->in_contract) && ($this->service->invoice_next && $this->service->invoice_next->isPast()),
'in_contract' => $this->expire_at && $this->expire_at->isFuture(),
default => parent::__get($key),
};
}
/* RELATIONS */
/**
@@ -50,11 +61,17 @@ abstract class Type extends Model implements ServiceItem
->where('site_id',$this->site_id);
}
/* INTERFACE */
/* ATTRIBUTES */
public function getContractTermAttribute(): int
/**
* We need to cast some dates to LeenooksCarbon to get access to startOfHalf()/endOfHalf() methods
*
* @param $value
* @return LeenooksCarbon|null
*/
public function getExpireAtAttribute($value): ?LeenooksCarbon
{
return $this->service->offering->contract_term;
return $value ? LeenooksCarbon::create($value) : NULL;
}
public function getServiceExpireAttribute(): ?LeenooksCarbon
@@ -62,43 +79,8 @@ abstract class Type extends Model implements ServiceItem
return $this->expire_at ?: $this->service->invoice_next_at;
}
public function hasExpired(): bool
{
return (! $this->inContract())
&& ($this->service->invoice_next && $this->service->invoice_next->isPast());
}
public function inContract(): bool
{
return $this->expire_at
&& $this->expire_at->isFuture();
}
/* ATTRIBUTES */
/**
* We need to cast some dates to LeenooksCarbon to get access to startOfHalf()/endOfHalf() methods
*
* @param $value
* @return LeenooksCarbon
*/
public function getExpireAtAttribute($value): ?LeenooksCarbon
{
return $value ? LeenooksCarbon::create($value) : NULL;
}
/* METHODS */
/**
* Validation used to accept form input
*
* @return mixed
*/
public function validation(): array
{
return [];
}
/**
* The supplier's service that we provide
*
@@ -119,4 +101,14 @@ abstract class Type extends Model implements ServiceItem
{
return collect();
}
/**
* Validation used to accept form input
*
* @return mixed
*/
public function validation(): array
{
return [];
}
}