mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 01:42:32 +00:00
Code cleanup
This commit is contained in:
@@ -116,7 +116,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
|
||||
->where('accounts.active', true)
|
||||
->where(
|
||||
function (EloquentBuilder $q1) use ($number) { // @phpstan-ignore-line
|
||||
static function (EloquentBuilder $q1) use ($number) { /** @phpstan-ignore-line */
|
||||
$json = json_encode($number);
|
||||
$q1->where('account_meta.name', '=', 'account_number');
|
||||
$q1->where('account_meta.data', '=', $json);
|
||||
@@ -219,7 +219,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
$query = $this->user->accounts()->with(
|
||||
[
|
||||
'accountmeta' => function (HasMany $query) {
|
||||
'accountmeta' => static function (HasMany $query) {
|
||||
$query->where('name', 'account_role');
|
||||
},
|
||||
'attachments',
|
||||
@@ -305,7 +305,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
{
|
||||
$query = $this->user->accounts()->with(
|
||||
[
|
||||
'accountmeta' => function (HasMany $query) {
|
||||
'accountmeta' => static function (HasMany $query) {
|
||||
$query->where('name', 'account_role');
|
||||
},
|
||||
]
|
||||
@@ -493,7 +493,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
public function getMetaValue(Account $account, string $field): ?string
|
||||
{
|
||||
$result = $account->accountMeta->filter(
|
||||
function (AccountMeta $meta) use ($field) {
|
||||
static function (AccountMeta $meta) use ($field) {
|
||||
return strtolower($meta->name) === strtolower($field);
|
||||
}
|
||||
);
|
||||
@@ -728,10 +728,10 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
foreach ($parts as $part) {
|
||||
$search = sprintf('%%%s%%', $part);
|
||||
$dbQuery->where(
|
||||
function (EloquentBuilder $q1) use ($search) { // @phpstan-ignore-line
|
||||
static function (EloquentBuilder $q1) use ($search) { // @phpstan-ignore-line
|
||||
$q1->where('accounts.iban', 'LIKE', $search);
|
||||
$q1->orWhere(
|
||||
function (EloquentBuilder $q2) use ($search) {
|
||||
static function (EloquentBuilder $q2) use ($search) {
|
||||
$q2->where('account_meta.name', '=', 'account_number');
|
||||
$q2->where('account_meta.data', 'LIKE', $search);
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ class JournalAPIRepository implements JournalAPIRepositoryInterface
|
||||
{
|
||||
$events = $journal->piggyBankEvents()->get();
|
||||
$events->each(
|
||||
function (PiggyBankEvent $event) {
|
||||
static function (PiggyBankEvent $event) {
|
||||
$event->piggyBank = $event->piggyBank()->withTrashed()->first();
|
||||
}
|
||||
);
|
||||
|
||||
@@ -198,7 +198,7 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
|
||||
$merged = $outward->merge($inward);
|
||||
|
||||
return $merged->filter(
|
||||
function (TransactionJournalLink $link) {
|
||||
static function (TransactionJournalLink $link) {
|
||||
return null !== $link->source && null !== $link->destination;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -68,14 +68,14 @@ class RecurringRepository implements RecurringRepositoryInterface
|
||||
{
|
||||
// if not, loop set and try to read the recurrence_date. If it matches start or end, return it as well.
|
||||
$set
|
||||
= TransactionJournalMeta::where(function (Builder $q1) use ($recurrence) {
|
||||
= TransactionJournalMeta::where(static function (Builder $q1) use ($recurrence) {
|
||||
$q1->where('name', 'recurrence_id');
|
||||
$q1->where('data', json_encode((string)$recurrence->id));
|
||||
})->get(['journal_meta.transaction_journal_id']);
|
||||
|
||||
// there are X journals made for this recurrence. Any of them meant for today?
|
||||
foreach ($set as $journalMeta) {
|
||||
$count = TransactionJournalMeta::where(function (Builder $q2) use ($date) {
|
||||
$count = TransactionJournalMeta::where(static function (Builder $q2) use ($date) {
|
||||
$string = (string)$date;
|
||||
app('log')->debug(sprintf('Search for date: %s', json_encode($string)));
|
||||
$q2->where('name', 'recurrence_date');
|
||||
|
||||
@@ -321,11 +321,11 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
app('log')->debug(sprintf('Will filter getRuleGroupsWithRules on "%s".', $filter));
|
||||
|
||||
return $groups->map(
|
||||
function (RuleGroup $group) use ($filter) {
|
||||
static function (RuleGroup $group) use ($filter) {
|
||||
app('log')->debug(sprintf('Now filtering group #%d', $group->id));
|
||||
// filter the rules in the rule group:
|
||||
$group->rules = $group->rules->filter(
|
||||
function (Rule $rule) use ($filter) {
|
||||
static function (Rule $rule) use ($filter) {
|
||||
app('log')->debug(sprintf('Now filtering rule #%d', $rule->id));
|
||||
foreach ($rule->ruleTriggers as $trigger) {
|
||||
if ('user_action' === $trigger->trigger_type && $filter === $trigger->trigger_value) {
|
||||
@@ -384,11 +384,11 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
|
||||
app('log')->debug(sprintf('Will filter getRuleGroupsWithRules on "%s".', $filter));
|
||||
|
||||
return $groups->map(
|
||||
function (RuleGroup $group) use ($filter) {
|
||||
static function (RuleGroup $group) use ($filter) {
|
||||
app('log')->debug(sprintf('Now filtering group #%d', $group->id));
|
||||
// filter the rules in the rule group:
|
||||
$group->rules = $group->rules->filter(
|
||||
function (Rule $rule) use ($filter) {
|
||||
static function (Rule $rule) use ($filter) {
|
||||
app('log')->debug(sprintf('Now filtering rule #%d', $rule->id));
|
||||
foreach ($rule->ruleTriggers as $trigger) {
|
||||
if ('user_action' === $trigger->trigger_type && $filter === $trigger->trigger_value) {
|
||||
|
||||
@@ -277,11 +277,11 @@ class UserGroupRepository implements UserGroupRepositoryInterface
|
||||
private function simplifyListByName(array $roles): array
|
||||
{
|
||||
if (in_array(UserRoleEnum::OWNER->value, $roles, true)) {
|
||||
app('log')->debug(sprintf('List of roles is [%1$s] but this includes "%2$s", so return [%2$s]', join(',', $roles), UserRoleEnum::OWNER->value));
|
||||
app('log')->debug(sprintf('List of roles is [%1$s] but this includes "%2$s", so return [%2$s]', implode(',', $roles), UserRoleEnum::OWNER->value));
|
||||
return [UserRoleEnum::OWNER->value];
|
||||
}
|
||||
if (in_array(UserRoleEnum::FULL->value, $roles, true)) {
|
||||
app('log')->debug(sprintf('List of roles is [%1$s] but this includes "%2$s", so return [%2$s]', join(',', $roles), UserRoleEnum::FULL->value));
|
||||
app('log')->debug(sprintf('List of roles is [%1$s] but this includes "%2$s", so return [%2$s]', implode(',', $roles), UserRoleEnum::FULL->value));
|
||||
return [UserRoleEnum::FULL->value];
|
||||
}
|
||||
return $roles;
|
||||
|
||||
@@ -98,7 +98,7 @@ class AccountRepository implements AccountRepositoryInterface
|
||||
public function getMetaValue(Account $account, string $field): ?string
|
||||
{
|
||||
$result = $account->accountMeta->filter(
|
||||
function (AccountMeta $meta) use ($field) {
|
||||
static function (AccountMeta $meta) use ($field) {
|
||||
return strtolower($meta->name) === strtolower($field);
|
||||
}
|
||||
);
|
||||
|
||||
@@ -179,11 +179,11 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
{
|
||||
$all = TransactionCurrency::orderBy('code', 'ASC')->get();
|
||||
$local = $this->get();
|
||||
return $all->map(function (TransactionCurrency $current) use ($local) {
|
||||
$hasId = $local->contains(function (TransactionCurrency $entry) use ($current) {
|
||||
return $all->map(static function (TransactionCurrency $current) use ($local) {
|
||||
$hasId = $local->contains(static function (TransactionCurrency $entry) use ($current) {
|
||||
return (int)$entry->id === (int)$current->id;
|
||||
});
|
||||
$isDefault = $local->contains(function (TransactionCurrency $entry) use ($current) {
|
||||
$isDefault = $local->contains(static function (TransactionCurrency $entry) use ($current) {
|
||||
return 1 === (int)$entry->pivot->group_default && (int)$entry->id === (int)$current->id;
|
||||
});
|
||||
$current->userEnabled = $hasId;
|
||||
@@ -200,7 +200,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
public function get(): Collection
|
||||
{
|
||||
$all = $this->userGroup->currencies()->orderBy('code', 'ASC')->withPivot(['group_default'])->get();
|
||||
$all->map(function (TransactionCurrency $current) {
|
||||
$all->map(static function (TransactionCurrency $current) {
|
||||
$current->userEnabled = true;
|
||||
$current->userDefault = 1 === (int)$current->pivot->group_default;
|
||||
return $current;
|
||||
|
||||
@@ -98,7 +98,7 @@ class WebhookRepository implements WebhookRepositoryInterface
|
||||
->where('webhook_messages.errored', 0)
|
||||
->get(['webhook_messages.*'])
|
||||
->filter(
|
||||
function (WebhookMessage $message) {
|
||||
static function (WebhookMessage $message) {
|
||||
return $message->webhookAttempts()->count() <= 2;
|
||||
}
|
||||
)->splice(0, 3);
|
||||
|
||||
Reference in New Issue
Block a user