mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 01:42:32 +00:00
Fix code quality with rector [skip ci]
This commit is contained in:
@@ -167,7 +167,7 @@ class AccountEnrichment implements EnrichmentInterface
|
||||
|
||||
private function appendCollectedData(): void
|
||||
{
|
||||
$this->collection = $this->collection->map(function (Account $item) {
|
||||
$this->collection = $this->collection->map(function (Account $item): Account {
|
||||
$id = (int)$item->id;
|
||||
$item->full_account_type = $this->accountTypes[(int)$item->account_type_id] ?? null;
|
||||
$meta = [
|
||||
|
||||
@@ -52,8 +52,6 @@ class AvailableBudgetEnrichment implements EnrichmentInterface
|
||||
private readonly BudgetRepositoryInterface $repository;
|
||||
private array $spentInBudgets = [];
|
||||
private array $spentOutsideBudgets = [];
|
||||
private User $user;
|
||||
private UserGroup $userGroup;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -91,14 +89,12 @@ class AvailableBudgetEnrichment implements EnrichmentInterface
|
||||
#[Override]
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->setUserGroup($user->userGroup);
|
||||
}
|
||||
|
||||
#[Override]
|
||||
public function setUserGroup(UserGroup $userGroup): void
|
||||
{
|
||||
$this->userGroup = $userGroup;
|
||||
$this->noBudgetRepository->setUserGroup($userGroup);
|
||||
$this->opsRepository->setUserGroup($userGroup);
|
||||
$this->repository->setUserGroup($userGroup);
|
||||
@@ -106,7 +102,7 @@ class AvailableBudgetEnrichment implements EnrichmentInterface
|
||||
|
||||
private function appendCollectedData(): void
|
||||
{
|
||||
$this->collection = $this->collection->map(function (AvailableBudget $item) {
|
||||
$this->collection = $this->collection->map(function (AvailableBudget $item): AvailableBudget {
|
||||
$id = (int)$item->id;
|
||||
$currencyId = $this->currencyIds[$id];
|
||||
$currency = $this->currencies[$currencyId];
|
||||
@@ -158,7 +154,7 @@ class AvailableBudgetEnrichment implements EnrichmentInterface
|
||||
$this->spentInBudgets[$id] = array_values($filteredSpentInBudgets);
|
||||
$this->spentOutsideBudgets[$id] = array_values($filteredSpentOutsideBudgets);
|
||||
|
||||
if (true === $this->convertToPrimary) {
|
||||
if ($this->convertToPrimary) {
|
||||
$pcFilteredSpentInBudgets = $this->opsRepository->sumCollectedExpenses($spentInBudgets, $availableBudget->start_date, $availableBudget->end_date, $currency, true);
|
||||
$pcFilteredSpentOutsideBudgets = $this->opsRepository->sumCollectedExpenses($spentOutsideBudgets, $availableBudget->start_date, $availableBudget->end_date, $currency, true);
|
||||
$this->pcSpentInBudgets[$id] = array_values($pcFilteredSpentInBudgets);
|
||||
|
||||
@@ -54,8 +54,6 @@ class BudgetEnrichment implements EnrichmentInterface
|
||||
private User $user;
|
||||
private UserGroup $userGroup;
|
||||
|
||||
public function __construct() {}
|
||||
|
||||
public function enrich(Collection $collection): Collection
|
||||
{
|
||||
$this->collection = $collection;
|
||||
@@ -102,7 +100,7 @@ class BudgetEnrichment implements EnrichmentInterface
|
||||
|
||||
private function appendCollectedData(): void
|
||||
{
|
||||
$this->collection = $this->collection->map(function (Budget $item) {
|
||||
$this->collection = $this->collection->map(function (Budget $item): Budget {
|
||||
$id = (int)$item->id;
|
||||
$meta = [
|
||||
'object_group_id' => null,
|
||||
|
||||
@@ -41,7 +41,7 @@ use Illuminate\Support\Facades\Log;
|
||||
class BudgetLimitEnrichment implements EnrichmentInterface
|
||||
{
|
||||
private Collection $collection;
|
||||
private bool $convertToPrimary; // @phpstan-ignore-line
|
||||
private readonly bool $convertToPrimary; // @phpstan-ignore-line
|
||||
private array $currencies = [];
|
||||
private array $currencyIds = [];
|
||||
private Carbon $end;
|
||||
@@ -52,7 +52,6 @@ class BudgetLimitEnrichment implements EnrichmentInterface
|
||||
private readonly TransactionCurrency $primaryCurrency;
|
||||
private Carbon $start;
|
||||
private User $user;
|
||||
private UserGroup $userGroup;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -85,17 +84,15 @@ class BudgetLimitEnrichment implements EnrichmentInterface
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->userGroup = $user->userGroup;
|
||||
}
|
||||
|
||||
public function setUserGroup(UserGroup $userGroup): void
|
||||
{
|
||||
$this->userGroup = $userGroup;
|
||||
}
|
||||
|
||||
private function appendCollectedData(): void
|
||||
{
|
||||
$this->collection = $this->collection->map(function (BudgetLimit $item) {
|
||||
$this->collection = $this->collection->map(function (BudgetLimit $item): BudgetLimit {
|
||||
$id = (int)$item->id;
|
||||
$currencyId = (int)$item->transaction_currency_id;
|
||||
if (0 === $currencyId) {
|
||||
@@ -130,11 +127,11 @@ class BudgetLimitEnrichment implements EnrichmentInterface
|
||||
$filteredExpenses = $repository->sumCollectedExpenses($filteredExpenses, $budgetLimit->start_date, $budgetLimit->end_date, $budgetLimit->transactionCurrency);
|
||||
$this->expenses[$id] = array_values($filteredExpenses);
|
||||
|
||||
if (true === $this->convertToPrimary && $budgetLimit->transactionCurrency->id !== $this->primaryCurrency->id) {
|
||||
if ($this->convertToPrimary && $budgetLimit->transactionCurrency->id !== $this->primaryCurrency->id) {
|
||||
$pcFilteredExpenses = $repository->sumCollectedExpenses($expenses, $budgetLimit->start_date, $budgetLimit->end_date, $budgetLimit->transactionCurrency, true);
|
||||
$this->pcExpenses[$id] = array_values($pcFilteredExpenses);
|
||||
}
|
||||
if (true === $this->convertToPrimary && $budgetLimit->transactionCurrency->id === $this->primaryCurrency->id) {
|
||||
if ($this->convertToPrimary && $budgetLimit->transactionCurrency->id === $this->primaryCurrency->id) {
|
||||
$this->pcExpenses[$id] = $this->expenses[$id] ?? [];
|
||||
}
|
||||
}
|
||||
@@ -184,7 +181,7 @@ class BudgetLimitEnrichment implements EnrichmentInterface
|
||||
|
||||
private function filterToBudget(array $expenses, int $budget): array
|
||||
{
|
||||
$result = array_filter($expenses, fn (array $item) => (int)$item['budget_id'] === $budget);
|
||||
$result = array_filter($expenses, fn (array $item): bool => (int)$item['budget_id'] === $budget);
|
||||
Log::debug(sprintf('filterToBudget for budget #%d, from %d to %d items', $budget, count($expenses), count($result)));
|
||||
|
||||
return $result;
|
||||
@@ -192,14 +189,14 @@ class BudgetLimitEnrichment implements EnrichmentInterface
|
||||
|
||||
private function stringifyIds(): void
|
||||
{
|
||||
$this->expenses = array_map(fn ($first) => array_map(function ($second) {
|
||||
$this->expenses = array_map(fn ($first): array => array_map(function (array $second): array {
|
||||
$second['currency_id'] = (string)($second['currency_id'] ?? 0);
|
||||
|
||||
return $second;
|
||||
}, $first), $this->expenses);
|
||||
|
||||
$this->pcExpenses = array_map(fn ($first) => array_map(function ($second) {
|
||||
$second['currency_id'] = (string)($second['currency_id'] ?? 0);
|
||||
$this->pcExpenses = array_map(fn (array $first): array => array_map(function (array $second): array {
|
||||
$second['currency_id'] ??= 0;
|
||||
|
||||
return $second;
|
||||
}, $first), $this->expenses);
|
||||
|
||||
@@ -94,7 +94,7 @@ class CategoryEnrichment implements EnrichmentInterface
|
||||
|
||||
private function appendCollectedData(): void
|
||||
{
|
||||
$this->collection = $this->collection->map(function (Category $item) {
|
||||
$this->collection = $this->collection->map(function (Category $item): Category {
|
||||
$id = (int)$item->id;
|
||||
$meta = [
|
||||
'notes' => $this->notes[$id] ?? null,
|
||||
|
||||
@@ -55,8 +55,6 @@ class PiggyBankEnrichment implements EnrichmentInterface
|
||||
private array $notes = [];
|
||||
private array $objectGroups = [];
|
||||
private readonly TransactionCurrency $primaryCurrency;
|
||||
private User $user;
|
||||
private UserGroup $userGroup;
|
||||
private ?Carbon $date;
|
||||
|
||||
public function __construct()
|
||||
@@ -89,18 +87,16 @@ class PiggyBankEnrichment implements EnrichmentInterface
|
||||
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->setUserGroup($user->userGroup);
|
||||
}
|
||||
|
||||
public function setUserGroup(UserGroup $userGroup): void
|
||||
{
|
||||
$this->userGroup = $userGroup;
|
||||
}
|
||||
|
||||
private function appendCollectedData(): void
|
||||
{
|
||||
$this->collection = $this->collection->map(function (PiggyBank $item) {
|
||||
$this->collection = $this->collection->map(function (PiggyBank $item): PiggyBank {
|
||||
$id = (int)$item->id;
|
||||
$currencyId = (int)$item->transaction_currency_id;
|
||||
$currency = $this->currencies[$currencyId] ?? $this->primaryCurrency;
|
||||
|
||||
@@ -46,8 +46,6 @@ class PiggyBankEventEnrichment implements EnrichmentInterface
|
||||
private array $ids = [];
|
||||
private array $journalIds = [];
|
||||
private array $piggyBankIds = [];
|
||||
private User $user;
|
||||
private UserGroup $userGroup;
|
||||
// private bool $convertToPrimary = false;
|
||||
// private TransactionCurrency $primaryCurrency;
|
||||
|
||||
@@ -77,18 +75,16 @@ class PiggyBankEventEnrichment implements EnrichmentInterface
|
||||
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->setUserGroup($user->userGroup);
|
||||
}
|
||||
|
||||
public function setUserGroup(UserGroup $userGroup): void
|
||||
{
|
||||
$this->userGroup = $userGroup;
|
||||
}
|
||||
|
||||
private function appendCollectedData(): void
|
||||
{
|
||||
$this->collection = $this->collection->map(function (PiggyBankEvent $item) {
|
||||
$this->collection = $this->collection->map(function (PiggyBankEvent $item): PiggyBankEvent {
|
||||
$id = (int)$item->id;
|
||||
$piggyId = (int)$item->piggy_bank_id;
|
||||
$journalId = (int)$item->transaction_journal_id;
|
||||
|
||||
@@ -60,7 +60,7 @@ class RecurringEnrichment implements EnrichmentInterface
|
||||
private Collection $collection;
|
||||
// private array $transactionTypeIds = [];
|
||||
// private array $transactionTypes = [];
|
||||
private bool $convertToPrimary;
|
||||
private readonly bool $convertToPrimary;
|
||||
private array $currencies = [];
|
||||
private array $currencyIds = [];
|
||||
private array $destinationAccountIds = [];
|
||||
@@ -171,7 +171,7 @@ class RecurringEnrichment implements EnrichmentInterface
|
||||
|
||||
private function appendCollectedData(): void
|
||||
{
|
||||
$this->collection = $this->collection->map(function (Recurrence $item) {
|
||||
$this->collection = $this->collection->map(function (Recurrence $item): Recurrence {
|
||||
$id = (int)$item->id;
|
||||
$meta = [
|
||||
'notes' => $this->notes[$id] ?? null,
|
||||
@@ -341,7 +341,7 @@ class RecurringEnrichment implements EnrichmentInterface
|
||||
|
||||
/** @var RecurrenceRepetition $repetition */
|
||||
foreach ($set as $repetition) {
|
||||
$recurrence = $this->collection->filter(fn (Recurrence $item) => (int)$item->id === (int)$repetition->recurrence_id)->first();
|
||||
$recurrence = $this->collection->filter(fn (Recurrence $item): bool => (int)$item->id === (int)$repetition->recurrence_id)->first();
|
||||
$fromDate = clone ($recurrence->latest_date ?? $recurrence->first_date);
|
||||
$id = (int)$repetition->recurrence_id;
|
||||
$repId = (int)$repetition->id;
|
||||
@@ -549,11 +549,11 @@ class RecurringEnrichment implements EnrichmentInterface
|
||||
$pcAmount = null;
|
||||
$pcForeignAmount = null;
|
||||
// set the same amount in the primary currency, if both are the same anyway.
|
||||
if (true === $this->convertToPrimary && $currencyId === (int)$this->primaryCurrency->id) {
|
||||
if ($this->convertToPrimary && $currencyId === (int)$this->primaryCurrency->id) {
|
||||
$pcAmount = $transaction['amount'];
|
||||
}
|
||||
// convert the amount to the primary currency, if it is not the same.
|
||||
if (true === $this->convertToPrimary && $currencyId !== (int)$this->primaryCurrency->id) {
|
||||
if ($this->convertToPrimary && $currencyId !== (int)$this->primaryCurrency->id) {
|
||||
$pcAmount = $converter->convert($this->currencies[$currencyId], $this->primaryCurrency, today(), $transaction['amount']);
|
||||
}
|
||||
if (null !== $transaction['foreign_amount'] && null !== $transaction['foreign_currency_id']) {
|
||||
|
||||
@@ -59,7 +59,6 @@ class SubscriptionEnrichment implements EnrichmentInterface
|
||||
private ?Carbon $start = null;
|
||||
private array $subscriptionIds = [];
|
||||
private User $user;
|
||||
private UserGroup $userGroup;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -84,7 +83,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
|
||||
$notes = $this->notes;
|
||||
$paidDates = $this->paidDates;
|
||||
$payDates = $this->payDates;
|
||||
$this->collection = $this->collection->map(function (Bill $item) use ($notes, $paidDates, $payDates) {
|
||||
$this->collection = $this->collection->map(function (Bill $item) use ($notes, $paidDates, $payDates): Bill {
|
||||
$id = (int)$item->id;
|
||||
$currency = $item->transactionCurrency;
|
||||
$nem = $this->getNextExpectedMatch($payDates[$id] ?? []);
|
||||
@@ -165,12 +164,10 @@ class SubscriptionEnrichment implements EnrichmentInterface
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->userGroup = $user->userGroup;
|
||||
}
|
||||
|
||||
public function setUserGroup(UserGroup $userGroup): void
|
||||
{
|
||||
$this->userGroup = $userGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,7 +175,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
|
||||
*/
|
||||
protected function lastPaidDate(Bill $subscription, Collection $dates, Carbon $default): Carbon
|
||||
{
|
||||
$filtered = $dates->filter(fn (TransactionJournal $journal) => (int)$journal->bill_id === (int)$subscription->id);
|
||||
$filtered = $dates->filter(fn (TransactionJournal $journal): bool => (int)$journal->bill_id === (int)$subscription->id);
|
||||
Log::debug(sprintf('Filtered down from %d to %d entries for bill #%d.', $dates->count(), $filtered->count(), $subscription->id));
|
||||
if (0 === $filtered->count()) {
|
||||
return $default;
|
||||
@@ -299,7 +296,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
|
||||
|
||||
// At this point the "next match" is exactly after the last time the bill was paid.
|
||||
$result = [];
|
||||
$filtered = $set->filter(fn (TransactionJournal $journal) => (int)$journal->bill_id === (int)$subscription->id);
|
||||
$filtered = $set->filter(fn (TransactionJournal $journal): bool => (int)$journal->bill_id === (int)$subscription->id);
|
||||
foreach ($filtered as $entry) {
|
||||
$array = [
|
||||
'transaction_group_id' => (string)$entry->transaction_group_id,
|
||||
@@ -390,7 +387,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
|
||||
|
||||
private function filterPaidDates(array $entries): array
|
||||
{
|
||||
return array_map(function (array $entry) {
|
||||
return array_map(function (array $entry): array {
|
||||
unset($entry['date_object']);
|
||||
|
||||
return $entry;
|
||||
|
||||
@@ -54,8 +54,6 @@ class TransactionGroupEnrichment implements EnrichmentInterface
|
||||
private array $notes = [];
|
||||
private readonly TransactionCurrency $primaryCurrency;
|
||||
private array $tags = []; // @phpstan-ignore-line
|
||||
private User $user;
|
||||
private UserGroup $userGroup; // @phpstan-ignore-line
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -98,13 +96,10 @@ class TransactionGroupEnrichment implements EnrichmentInterface
|
||||
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->userGroup = $user->userGroup;
|
||||
}
|
||||
|
||||
public function setUserGroup(UserGroup $userGroup): void
|
||||
{
|
||||
$this->userGroup = $userGroup;
|
||||
}
|
||||
|
||||
private function appendCollectedData(): void
|
||||
@@ -116,12 +111,12 @@ class TransactionGroupEnrichment implements EnrichmentInterface
|
||||
$attachmentCount = $this->attachmentCount;
|
||||
$primaryCurrency = $this->primaryCurrency;
|
||||
|
||||
$this->collection = $this->collection->map(function (array $item) use ($primaryCurrency, $notes, $tags, $metaData, $locations, $attachmentCount) {
|
||||
$this->collection = $this->collection->map(function (array $item) use ($primaryCurrency, $notes, $tags, $metaData, $locations, $attachmentCount): array {
|
||||
foreach ($item['transactions'] as $index => $transaction) {
|
||||
$journalId = (int)$transaction['transaction_journal_id'];
|
||||
|
||||
// attach notes if they exist:
|
||||
$item['transactions'][$index]['notes'] = array_key_exists($journalId, $notes) ? $notes[$journalId] : null;
|
||||
$item['transactions'][$index]['notes'] = $notes[$journalId] ?? null;
|
||||
|
||||
// attach tags if they exist:
|
||||
$item['transactions'][$index]['tags'] = array_key_exists($journalId, $tags) ? $tags[$journalId] : [];
|
||||
|
||||
@@ -47,8 +47,6 @@ class WebhookEnrichment implements EnrichmentInterface
|
||||
private array $ids = []; // @phpstan-ignore-line
|
||||
private array $responses = [];
|
||||
private array $triggers = [];
|
||||
private User $user;
|
||||
private UserGroup $userGroup;
|
||||
private array $webhookDeliveries = [];
|
||||
private array $webhookResponses = [];
|
||||
private array $webhookTriggers = [];
|
||||
@@ -77,17 +75,15 @@ class WebhookEnrichment implements EnrichmentInterface
|
||||
|
||||
public function setUser(User $user): void
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function setUserGroup(UserGroup $userGroup): void
|
||||
{
|
||||
$this->userGroup = $userGroup;
|
||||
}
|
||||
|
||||
private function appendCollectedInfo(): void
|
||||
{
|
||||
$this->collection = $this->collection->map(function (Webhook $item) {
|
||||
$this->collection = $this->collection->map(function (Webhook $item): Webhook {
|
||||
$meta = [
|
||||
'deliveries' => $this->webhookDeliveries[$item->id] ?? [],
|
||||
'responses' => $this->webhookResponses[$item->id] ?? [],
|
||||
|
||||
Reference in New Issue
Block a user