Code cleanup

This commit is contained in:
James Cole
2023-11-04 14:18:49 +01:00
parent 5a35960434
commit ba0843d0bb
211 changed files with 566 additions and 568 deletions

View File

@@ -108,8 +108,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
*/
class Account extends Model
{
use SoftDeletes;
use HasFactory;
use SoftDeletes;
/**
* The attributes that should be casted to native types.
@@ -139,7 +139,7 @@ class Account extends Model
* @return Account
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): Account
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$accountId = (int)$value;
@@ -300,7 +300,7 @@ class Account extends Model
protected function virtualBalance(): Attribute
{
return Attribute::make(
get: fn ($value) => (string)$value,
get: static fn ($value) => (string)$value,
);
}
}

View File

@@ -109,7 +109,7 @@ class Attachment extends Model
* @return Attachment
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): Attachment
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$attachmentId = (int)$value;

View File

@@ -94,7 +94,7 @@ class AutoBudget extends Model
protected function amount(): Attribute
{
return Attribute::make(
get: fn ($value) => (string)$value,
get: static fn ($value) => (string)$value,
);
}
}

View File

@@ -95,7 +95,7 @@ class AvailableBudget extends Model
* @return AvailableBudget
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): AvailableBudget
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$availableBudgetId = (int)$value;
@@ -132,7 +132,7 @@ class AvailableBudget extends Model
protected function amount(): Attribute
{
return Attribute::make(
get: fn ($value) => (string)$value,
get: static fn ($value) => (string)$value,
);
}
}

View File

@@ -154,7 +154,7 @@ class Bill extends Model
* @return Bill
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): Bill
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$billId = (int)$value;
@@ -244,7 +244,7 @@ class Bill extends Model
protected function amountMax(): Attribute
{
return Attribute::make(
get: fn ($value) => (string)$value,
get: static fn ($value) => (string)$value,
);
}
@@ -256,7 +256,7 @@ class Bill extends Model
protected function amountMin(): Attribute
{
return Attribute::make(
get: fn ($value) => (string)$value,
get: static fn ($value) => (string)$value,
);
}
}

View File

@@ -111,7 +111,7 @@ class Budget extends Model
* @return Budget
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): Budget
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$budgetId = (int)$value;

View File

@@ -97,7 +97,7 @@ class BudgetLimit extends Model
* @return BudgetLimit
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): BudgetLimit
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$budgetLimitId = (int)$value;
@@ -136,7 +136,7 @@ class BudgetLimit extends Model
protected function amount(): Attribute
{
return Attribute::make(
get: fn ($value) => (string)$value,
get: static fn ($value) => (string)$value,
);
}
}

View File

@@ -101,7 +101,7 @@ class Category extends Model
* @return Category
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): Category
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$categoryId = (int)$value;

View File

@@ -114,7 +114,7 @@ class CurrencyExchangeRate extends Model
protected function rate(): Attribute
{
return Attribute::make(
get: fn ($value) => (string)$value,
get: static fn ($value) => (string)$value,
);
}
@@ -124,7 +124,7 @@ class CurrencyExchangeRate extends Model
protected function userRate(): Attribute
{
return Attribute::make(
get: fn ($value) => (string)$value,
get: static fn ($value) => (string)$value,
);
}
}

View File

@@ -73,7 +73,7 @@ class InvitedUser extends Model
*
* @return InvitedUser
*/
public static function routeBinder(string $value): InvitedUser
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$attemptId = (int)$value;

View File

@@ -91,7 +91,7 @@ class LinkType extends Model
*
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): LinkType
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$linkTypeId = (int)$value;

View File

@@ -89,7 +89,7 @@ class ObjectGroup extends Model
* @return ObjectGroup
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): ObjectGroup
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$objectGroupId = (int)$value;

View File

@@ -115,7 +115,7 @@ class PiggyBank extends Model
* @return PiggyBank
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): PiggyBank
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$piggyBankId = (int)$value;
@@ -194,7 +194,7 @@ class PiggyBank extends Model
protected function targetamount(): Attribute
{
return Attribute::make(
get: fn ($value) => (string)$value,
get: static fn ($value) => (string)$value,
);
}
}

View File

@@ -105,7 +105,7 @@ class PiggyBankEvent extends Model
protected function amount(): Attribute
{
return Attribute::make(
get: fn ($value) => (string)$value,
get: static fn ($value) => (string)$value,
);
}
}

View File

@@ -103,13 +103,13 @@ class PiggyBankRepetition extends Model
public function scopeRelevantOnDate(EloquentBuilder $query, Carbon $date)
{
return $query->where(
function (EloquentBuilder $q) use ($date) {
static function (EloquentBuilder $q) use ($date) {
$q->where('startdate', '<=', $date->format('Y-m-d 00:00:00'));
$q->orWhereNull('startdate');
}
)
->where(
function (EloquentBuilder $q) use ($date) {
static function (EloquentBuilder $q) use ($date) {
$q->where('targetdate', '>=', $date->format('Y-m-d 00:00:00'));
$q->orWhereNull('targetdate');
}
@@ -133,7 +133,7 @@ class PiggyBankRepetition extends Model
protected function currentamount(): Attribute
{
return Attribute::make(
get: fn ($value) => (string)$value,
get: static fn ($value) => (string)$value,
);
}
}

View File

@@ -77,7 +77,7 @@ class Preference extends Model
* @return Preference
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): Preference
public static function routeBinder(string $value): self
{
if (auth()->check()) {
/** @var User $user */
@@ -92,7 +92,7 @@ class Preference extends Model
}
$default = config('firefly.default_preferences');
if (array_key_exists($value, $default)) {
$preference = new Preference();
$preference = new self();
$preference->name = $value;
$preference->data = $default[$value];
$preference->user_id = $user->id;

View File

@@ -127,7 +127,7 @@ class Recurrence extends Model
* @return Recurrence
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): Recurrence
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$recurrenceId = (int)$value;

View File

@@ -173,7 +173,7 @@ class RecurrenceTransaction extends Model
protected function amount(): Attribute
{
return Attribute::make(
get: fn ($value) => (string)$value,
get: static fn ($value) => (string)$value,
);
}
@@ -183,7 +183,7 @@ class RecurrenceTransaction extends Model
protected function foreignAmount(): Attribute
{
return Attribute::make(
get: fn ($value) => (string)$value,
get: static fn ($value) => (string)$value,
);
}
}

View File

@@ -110,7 +110,7 @@ class Rule extends Model
* @return Rule
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): Rule
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$ruleId = (int)$value;

View File

@@ -100,7 +100,7 @@ class RuleGroup extends Model
* @return RuleGroup
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): RuleGroup
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$ruleGroupId = (int)$value;

View File

@@ -111,7 +111,7 @@ class Tag extends Model
* @return Tag
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): Tag
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$tagId = (int)$value;

View File

@@ -89,8 +89,8 @@ use Illuminate\Database\Eloquent\SoftDeletes;
*/
class Transaction extends Model
{
use SoftDeletes;
use HasFactory;
use SoftDeletes;
/**
* The attributes that should be casted to native types.
@@ -264,7 +264,7 @@ class Transaction extends Model
protected function amount(): Attribute
{
return Attribute::make(
get: fn ($value) => (string)$value,
get: static fn ($value) => (string)$value,
);
}
@@ -276,7 +276,7 @@ class Transaction extends Model
protected function foreignAmount(): Attribute
{
return Attribute::make(
get: fn ($value) => (string)$value,
get: static fn ($value) => (string)$value,
);
}
}

View File

@@ -103,7 +103,7 @@ class TransactionCurrency extends Model
* @return TransactionCurrency
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): TransactionCurrency
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$currencyId = (int)$value;

View File

@@ -93,7 +93,7 @@ class TransactionGroup extends Model
* @return TransactionGroup
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): TransactionGroup
public static function routeBinder(string $value): self
{
app('log')->debug(sprintf('Now in %s("%s")', __METHOD__, $value));
if (auth()->check()) {

View File

@@ -123,8 +123,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
*/
class TransactionJournal extends Model
{
use SoftDeletes;
use HasFactory;
use SoftDeletes;
/**
* The attributes that should be casted to native types.
@@ -171,7 +171,7 @@ class TransactionJournal extends Model
* @return TransactionJournal
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): TransactionJournal
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$journalId = (int)$value;

View File

@@ -85,7 +85,7 @@ class TransactionJournalLink extends Model
*
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): TransactionJournalLink
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$linkId = (int)$value;

View File

@@ -83,7 +83,7 @@ class TransactionType extends Model
* @return TransactionType
* @throws NotFoundHttpException
*/
public static function routeBinder(string $type): TransactionType
public static function routeBinder(string $type): self
{
if (!auth()->check()) {
throw new NotFoundHttpException();

View File

@@ -102,14 +102,14 @@ class UserGroup extends Model
* @return UserGroup
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): UserGroup
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$userGroupId = (int)$value;
/** @var User $user */
$user = auth()->user();
/** @var UserGroup|null $userGroup */
$userGroup = UserGroup::find($userGroupId);
$userGroup = self::find($userGroupId);
if (null === $userGroup) {
throw new NotFoundHttpException();
}

View File

@@ -179,7 +179,7 @@ class Webhook extends Model
* @return Webhook
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): Webhook
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$webhookId = (int)$value;

View File

@@ -72,7 +72,7 @@ class WebhookAttempt extends Model
* @return WebhookAttempt
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): WebhookAttempt
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$attemptId = (int)$value;

View File

@@ -86,7 +86,7 @@ class WebhookMessage extends Model
* @return WebhookMessage
* @throws NotFoundHttpException
*/
public static function routeBinder(string $value): WebhookMessage
public static function routeBinder(string $value): self
{
if (auth()->check()) {
$messageId = (int)$value;
@@ -125,7 +125,7 @@ class WebhookMessage extends Model
protected function sent(): Attribute
{
return Attribute::make(
get: fn ($value) => (bool)$value,
get: static fn ($value) => (bool)$value,
);
}
}