diff --git a/src/app/Entitlement.php b/src/app/Entitlement.php index ac719eaa..58b6a5fd 100644 --- a/src/app/Entitlement.php +++ b/src/app/Entitlement.php @@ -1,137 +1,137 @@ The attributes that are mass assignable */ protected $fillable = [ 'sku_id', 'wallet_id', 'entitleable_id', 'entitleable_type', 'cost', 'description', 'fee', ]; /** @var array The attributes that should be cast */ protected $casts = [ 'cost' => 'integer', 'fee' => 'integer' ]; /** * Create a transaction record for this entitlement. * * @param string $type The type of transaction ('created', 'billed', 'deleted'), but use the * \App\Transaction constants. * @param int $amount The amount involved in cents * * @return string The transaction ID */ public function createTransaction($type, $amount = null) { $transaction = Transaction::create( [ 'object_id' => $this->id, 'object_type' => Entitlement::class, 'type' => $type, 'amount' => $amount ] ); return $transaction->id; } /** * Principally entitleable object such as Domain, User, Group. * Note that it may be trashed (soft-deleted). * * @return mixed */ public function entitleable() { - return $this->morphTo()->withTrashed(); // @phpstan-ignore-line + return $this->morphTo()->withTrashed(); } /** * Simplified Entitlement/SKU information for a specified entitleable object * * @param object $object Entitleable object * * @return array Skus list with some metadata */ public static function objectEntitlementsSummary($object): array { $skus = []; // TODO: I agree this format may need to be extended in future foreach ($object->entitlements as $ent) { $sku = $ent->sku; if (!isset($skus[$sku->id])) { $skus[$sku->id] = ['costs' => [], 'count' => 0]; } $skus[$sku->id]['count']++; $skus[$sku->id]['costs'][] = $ent->cost; } return $skus; } /** * The SKU concerned. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function sku() { return $this->belongsTo(Sku::class); } /** * The wallet this entitlement is being billed to * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function wallet() { return $this->belongsTo(Wallet::class); } /** * Cost mutator. Make sure cost is integer. */ public function setCostAttribute($cost): void { $this->attributes['cost'] = round($cost); } } diff --git a/src/app/EventLog.php b/src/app/EventLog.php index 2c695653..92ed887e 100644 --- a/src/app/EventLog.php +++ b/src/app/EventLog.php @@ -1,134 +1,134 @@ The attributes that are mass assignable */ protected $fillable = [ 'comment', // extra event info (json) 'data', 'type', // user, domain, etc. 'object_id', 'object_type', // actor, if any 'user_email', ]; /** @var array Casts properties as type */ protected $casts = [ 'created_at' => 'datetime:Y-m-d H:i:s', 'data' => 'array', 'type' => 'integer', ]; /** @var array The attributes that can be not set */ protected $nullable = ['comment', 'data', 'user_email']; /** @var string Database table name */ protected $table = 'eventlog'; /** @var bool Indicates if the model should be timestamped. */ public $timestamps = false; /** * Create an eventlog object for a specified object. * * @param object $object Object (User, Domain, etc.) * @param int $type Event type (use one of EventLog::TYPE_* consts) * @param ?string $comment Event description * @param ?array $data Extra information * * @return EventLog */ public static function createFor($object, int $type, string $comment = null, array $data = null): EventLog { $event = self::create([ 'object_id' => $object->id, 'object_type' => get_class($object), 'type' => $type, 'comment' => $comment, 'data' => $data, ]); return $event; } /** * Principally an object such as Domain, User, Group. * Note that it may be trashed (soft-deleted). * * @return mixed */ public function object() { - return $this->morphTo()->withTrashed(); // @phpstan-ignore-line + return $this->morphTo()->withTrashed(); } /** * Get an event type name. * * @return ?string Event type name */ public function eventName(): ?string { switch ($this->type) { case self::TYPE_SUSPENDED: return \trans('app.event-suspended'); case self::TYPE_UNSUSPENDED: return \trans('app.event-unsuspended'); case self::TYPE_COMMENT: return \trans('app.event-comment'); case self::TYPE_MAILSENT: return \trans('app.event-mailsent'); default: return null; } } /** * Event type mutator * * @throws \Exception */ public function setTypeAttribute($type) { if (!is_numeric($type)) { throw new \Exception("Expecting an event type to be numeric"); } $type = (int) $type; if ($type < 0 || $type > 255) { throw new \Exception("Expecting an event type between 0 and 255"); } $this->attributes['type'] = $type; } } diff --git a/src/app/Permission.php b/src/app/Permission.php index 68743916..d812e426 100644 --- a/src/app/Permission.php +++ b/src/app/Permission.php @@ -1,57 +1,57 @@ The attributes that are mass assignable */ protected $fillable = [ 'permissible_id', 'permissible_type', 'rights', 'user', ]; /** @var array The attributes that should be cast */ protected $casts = [ 'rights' => 'integer', ]; /** * Principally permissible object such as Room. * Note that it may be trashed (soft-deleted). * * @return mixed */ public function permissible() { - return $this->morphTo()->withTrashed(); // @phpstan-ignore-line + return $this->morphTo()->withTrashed(); } /** * Rights mutator. Make sure rights is integer. */ public function setRightsAttribute($rights): void { $this->attributes['rights'] = (int) $rights; } }