Various PSR12 code cleanup

This commit is contained in:
James Cole
2022-12-29 19:41:57 +01:00
parent 0022009dd5
commit dbf3e76ecc
340 changed files with 4079 additions and 3816 deletions

View File

@@ -74,39 +74,39 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
* Class User.
*
* @property int $id
* @property string $email
* @property bool $isAdmin
* @property bool $has2FA
* @property array $prefs
* @property string $password
* @property string $mfa_secret
* @property Collection $roles
* @property string $blocked_code
* @property bool $blocked
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property string|null $remember_token
* @property string|null $reset
* @property-read \Illuminate\Database\Eloquent\Collection|Account[] $accounts
* @property-read \Illuminate\Database\Eloquent\Collection|Attachment[] $attachments
* @property-read \Illuminate\Database\Eloquent\Collection|AvailableBudget[] $availableBudgets
* @property-read \Illuminate\Database\Eloquent\Collection|Bill[] $bills
* @property-read \Illuminate\Database\Eloquent\Collection|Budget[] $budgets
* @property-read \Illuminate\Database\Eloquent\Collection|Category[] $categories
* @property-read \Illuminate\Database\Eloquent\Collection|Client[] $clients
* @property int $id
* @property string $email
* @property bool $isAdmin
* @property bool $has2FA
* @property array $prefs
* @property string $password
* @property string $mfa_secret
* @property Collection $roles
* @property string $blocked_code
* @property bool $blocked
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property string|null $remember_token
* @property string|null $reset
* @property-read \Illuminate\Database\Eloquent\Collection|Account[] $accounts
* @property-read \Illuminate\Database\Eloquent\Collection|Attachment[] $attachments
* @property-read \Illuminate\Database\Eloquent\Collection|AvailableBudget[] $availableBudgets
* @property-read \Illuminate\Database\Eloquent\Collection|Bill[] $bills
* @property-read \Illuminate\Database\Eloquent\Collection|Budget[] $budgets
* @property-read \Illuminate\Database\Eloquent\Collection|Category[] $categories
* @property-read \Illuminate\Database\Eloquent\Collection|Client[] $clients
* @property-read \Illuminate\Database\Eloquent\Collection|CurrencyExchangeRate[] $currencyExchangeRates
* @property-read DatabaseNotificationCollection|DatabaseNotification[] $notifications
* @property-read \Illuminate\Database\Eloquent\Collection|PiggyBank[] $piggyBanks
* @property-read \Illuminate\Database\Eloquent\Collection|Preference[] $preferences
* @property-read \Illuminate\Database\Eloquent\Collection|Recurrence[] $recurrences
* @property-read \Illuminate\Database\Eloquent\Collection|RuleGroup[] $ruleGroups
* @property-read \Illuminate\Database\Eloquent\Collection|Rule[] $rules
* @property-read \Illuminate\Database\Eloquent\Collection|Tag[] $tags
* @property-read \Illuminate\Database\Eloquent\Collection|Token[] $tokens
* @property-read \Illuminate\Database\Eloquent\Collection|TransactionGroup[] $transactionGroups
* @property-read \Illuminate\Database\Eloquent\Collection|TransactionJournal[] $transactionJournals
* @property-read \Illuminate\Database\Eloquent\Collection|Transaction[] $transactions
* @property-read DatabaseNotificationCollection|DatabaseNotification[] $notifications
* @property-read \Illuminate\Database\Eloquent\Collection|PiggyBank[] $piggyBanks
* @property-read \Illuminate\Database\Eloquent\Collection|Preference[] $preferences
* @property-read \Illuminate\Database\Eloquent\Collection|Recurrence[] $recurrences
* @property-read \Illuminate\Database\Eloquent\Collection|RuleGroup[] $ruleGroups
* @property-read \Illuminate\Database\Eloquent\Collection|Rule[] $rules
* @property-read \Illuminate\Database\Eloquent\Collection|Tag[] $tags
* @property-read \Illuminate\Database\Eloquent\Collection|Token[] $tokens
* @property-read \Illuminate\Database\Eloquent\Collection|TransactionGroup[] $transactionGroups
* @property-read \Illuminate\Database\Eloquent\Collection|TransactionJournal[] $transactionJournals
* @property-read \Illuminate\Database\Eloquent\Collection|Transaction[] $transactions
* @method static Builder|User newModelQuery()
* @method static Builder|User newQuery()
* @method static Builder|User query()
@@ -120,47 +120,47 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @method static Builder|User whereReset($value)
* @method static Builder|User whereUpdatedAt($value)
* @mixin Eloquent
* @property string|null $objectguid
* @property-read int|null $accounts_count
* @property-read int|null $attachments_count
* @property-read int|null $available_budgets_count
* @property-read int|null $bills_count
* @property-read int|null $budgets_count
* @property-read int|null $categories_count
* @property-read int|null $clients_count
* @property-read int|null $currency_exchange_rates_count
* @property-read int|null $notifications_count
* @property-read int|null $piggy_banks_count
* @property-read int|null $preferences_count
* @property-read int|null $recurrences_count
* @property-read int|null $roles_count
* @property-read int|null $rule_groups_count
* @property-read int|null $rules_count
* @property-read int|null $tags_count
* @property-read int|null $tokens_count
* @property-read int|null $transaction_groups_count
* @property-read int|null $transaction_journals_count
* @property-read int|null $transactions_count
* @property string|null $objectguid
* @property-read int|null $accounts_count
* @property-read int|null $attachments_count
* @property-read int|null $available_budgets_count
* @property-read int|null $bills_count
* @property-read int|null $budgets_count
* @property-read int|null $categories_count
* @property-read int|null $clients_count
* @property-read int|null $currency_exchange_rates_count
* @property-read int|null $notifications_count
* @property-read int|null $piggy_banks_count
* @property-read int|null $preferences_count
* @property-read int|null $recurrences_count
* @property-read int|null $roles_count
* @property-read int|null $rule_groups_count
* @property-read int|null $rules_count
* @property-read int|null $tags_count
* @property-read int|null $tokens_count
* @property-read int|null $transaction_groups_count
* @property-read int|null $transaction_journals_count
* @property-read int|null $transactions_count
* @method static Builder|User whereMfaSecret($value)
* @method static Builder|User whereObjectguid($value)
* @property string|null $provider
* @property string|null $provider
* @method static Builder|User whereProvider($value)
* @property-read \Illuminate\Database\Eloquent\Collection|ObjectGroup[] $objectGroups
* @property-read int|null $object_groups_count
* @property-read \Illuminate\Database\Eloquent\Collection|Webhook[] $webhooks
* @property-read int|null $webhooks_count
* @property string|null $two_factor_secret
* @property string|null $two_factor_recovery_codes
* @property string|null $guid
* @property string|null $domain
* @property-read \Illuminate\Database\Eloquent\Collection|ObjectGroup[] $objectGroups
* @property-read int|null $object_groups_count
* @property-read \Illuminate\Database\Eloquent\Collection|Webhook[] $webhooks
* @property-read int|null $webhooks_count
* @property string|null $two_factor_secret
* @property string|null $two_factor_recovery_codes
* @property string|null $guid
* @property string|null $domain
* @method static Builder|User whereDomain($value)
* @method static Builder|User whereGuid($value)
* @method static Builder|User whereTwoFactorRecoveryCodes($value)
* @method static Builder|User whereTwoFactorSecret($value)
* @property int|null $user_group_id
* @property-read \Illuminate\Database\Eloquent\Collection|GroupMembership[] $groupMemberships
* @property-read int|null $group_memberships_count
* @property-read UserGroup|null $userGroup
* @property int|null $user_group_id
* @property-read \Illuminate\Database\Eloquent\Collection|GroupMembership[] $groupMemberships
* @property-read int|null $group_memberships_count
* @property-read UserGroup|null $userGroup
* @method static Builder|User whereUserGroupId($value)
*/
class User extends Authenticatable
@@ -199,7 +199,7 @@ class User extends Authenticatable
protected $table = 'users';
/**
* @param string $value
* @param string $value
*
* @return User
* @throws NotFoundHttpException
@@ -207,7 +207,7 @@ class User extends Authenticatable
public static function routeBinder(string $value): User
{
if (auth()->check()) {
$userId = (int) $value;
$userId = (int)$value;
$user = self::find($userId);
if (null !== $user) {
return $user;
@@ -361,27 +361,6 @@ class User extends Authenticatable
return $this->hasMany(GroupMembership::class)->with(['userGroup', 'userRole']);
}
/**
* @param string $role
*
* @return bool
*/
public function hasRole(string $role): bool
{
return $this->roles()->where('name', $role)->count() === 1;
}
/**
* @codeCoverageIgnore
* Link to roles.
*
* @return BelongsToMany
*/
public function roles(): BelongsToMany
{
return $this->belongsToMany(Role::class);
}
/**
* @codeCoverageIgnore
* Link to object groups.
@@ -426,6 +405,81 @@ class User extends Authenticatable
return $this->hasMany(Recurrence::class);
}
/**
* Get the notification routing information for the given driver.
*
* @param string $driver
* @param Notification|null $notification
* @return mixed
*/
public function routeNotificationFor($driver, $notification = null)
{
if (method_exists($this, $method = 'routeNotificationFor'.Str::studly($driver))) {
return $this->{$method}($notification);
}
$email = $this->email;
// see if user has alternative email address:
$pref = app('preferences')->getForUser($this, 'remote_guard_alt_email');
if (null !== $pref) {
$email = $pref->data;
}
// if user is demo user, send to owner:
if ($this->hasRole('demo')) {
$email = config('firefly.site_owner');
}
return match ($driver) {
'database' => $this->notifications(),
'mail' => $email,
default => null,
};
}
/**
* @param string $role
*
* @return bool
*/
public function hasRole(string $role): bool
{
return $this->roles()->where('name', $role)->count() === 1;
}
/**
* @codeCoverageIgnore
* Link to roles.
*
* @return BelongsToMany
*/
public function roles(): BelongsToMany
{
return $this->belongsToMany(Role::class);
}
/**
* Route notifications for the Slack channel.
*
* @param Notification $notification
* @return string
*/
public function routeNotificationForSlack(Notification $notification): string
{
// this check does not validate if the user is owner, Should be done by notification itself.
if ($notification instanceof TestNotification) {
return app('fireflyconfig')->get('slack_webhook_url', '')->data;
}
if ($notification instanceof UserRegistration) {
return app('fireflyconfig')->get('slack_webhook_url', '')->data;
}
if ($notification instanceof VersionCheckResult) {
return app('fireflyconfig')->get('slack_webhook_url', '')->data;
}
if ($notification instanceof UserInvitation) {
return app('fireflyconfig')->get('slack_webhook_url', '')->data;
}
return app('preferences')->getForUser($this, 'slack_webhook_url', '')->data;
}
/**
* @codeCoverageIgnore
* Link to rule groups.
@@ -452,7 +506,7 @@ class User extends Authenticatable
* @codeCoverageIgnore
* Send the password reset notification.
*
* @param string $token
* @param string $token
*/
public function sendPasswordResetNotification($token): void
{
@@ -461,9 +515,11 @@ class User extends Authenticatable
event(new RequestedNewPassword($this, $token, $ipAddress));
}
// start LDAP related code
/**
* Set the models LDAP domain.
* @param string $domain
* @param string $domain
*
* @return void
* @deprecated
@@ -476,7 +532,7 @@ class User extends Authenticatable
/**
* Set the models LDAP GUID.
* @param string $guid
* @param string $guid
*
* @return void
* @deprecated
@@ -486,8 +542,6 @@ class User extends Authenticatable
$this->{$this->getLdapGuidColumn()} = $guid;
}
// start LDAP related code
/**
* @codeCoverageIgnore
* Link to tags.
@@ -552,58 +606,4 @@ class User extends Authenticatable
{
return $this->hasMany(Webhook::class);
}
/**
* Get the notification routing information for the given driver.
*
* @param string $driver
* @param Notification|null $notification
* @return mixed
*/
public function routeNotificationFor($driver, $notification = null)
{
if (method_exists($this, $method = 'routeNotificationFor' . Str::studly($driver))) {
return $this->{$method}($notification);
}
$email = $this->email;
// see if user has alternative email address:
$pref = app('preferences')->getForUser($this, 'remote_guard_alt_email');
if (null !== $pref) {
$email = $pref->data;
}
// if user is demo user, send to owner:
if ($this->hasRole('demo')) {
$email = config('firefly.site_owner');
}
return match ($driver) {
'database' => $this->notifications(),
'mail' => $email,
default => null,
};
}
/**
* Route notifications for the Slack channel.
*
* @param Notification $notification
* @return string
*/
public function routeNotificationForSlack(Notification $notification): string
{
// this check does not validate if the user is owner, Should be done by notification itself.
if ($notification instanceof TestNotification) {
return app('fireflyconfig')->get('slack_webhook_url', '')->data;
}
if ($notification instanceof UserRegistration) {
return app('fireflyconfig')->get('slack_webhook_url', '')->data;
}
if ($notification instanceof VersionCheckResult) {
return app('fireflyconfig')->get('slack_webhook_url', '')->data;
}
if ($notification instanceof UserInvitation) {
return app('fireflyconfig')->get('slack_webhook_url', '')->data;
}
return app('preferences')->getForUser($this, 'slack_webhook_url', '')->data;
}
}