diff --git a/app/Transformers/BudgetLimitTransformer.php b/app/Transformers/BudgetLimitTransformer.php index 6850d09487..1afb62ae2b 100644 --- a/app/Transformers/BudgetLimitTransformer.php +++ b/app/Transformers/BudgetLimitTransformer.php @@ -42,7 +42,7 @@ class BudgetLimitTransformer extends AbstractTransformer /** * Include Budget * - * @param BudgetLimit $limit + * @param BudgetLimit $limit * * @return Item */ @@ -54,7 +54,7 @@ class BudgetLimitTransformer extends AbstractTransformer /** * Transform the note. * - * @param BudgetLimit $budgetLimit + * @param BudgetLimit $budgetLimit * * @return array */ @@ -78,7 +78,7 @@ class BudgetLimitTransformer extends AbstractTransformer $currencySymbol = null; if (null !== $currency) { $amount = $budgetLimit->amount; - $currencyId = (int) $currency->id; + $currencyId = (int)$currency->id; $currencyName = $currency->name; $currencyCode = $currency->code; $currencySymbol = $currency->symbol; @@ -87,13 +87,13 @@ class BudgetLimitTransformer extends AbstractTransformer $amount = app('steam')->bcround($amount, $currencyDecimalPlaces); return [ - 'id' => (string) $budgetLimit->id, + 'id' => (string)$budgetLimit->id, 'created_at' => $budgetLimit->created_at->toAtomString(), 'updated_at' => $budgetLimit->updated_at->toAtomString(), 'start' => $budgetLimit->start_date->toAtomString(), 'end' => $budgetLimit->end_date->endOfDay()->toAtomString(), - 'budget_id' => (string) $budgetLimit->budget_id, - 'currency_id' => (string) $currencyId, + 'budget_id' => (string)$budgetLimit->budget_id, + 'currency_id' => (string)$currencyId, 'currency_code' => $currencyCode, 'currency_name' => $currencyName, 'currency_decimal_places' => $currencyDecimalPlaces, @@ -104,7 +104,7 @@ class BudgetLimitTransformer extends AbstractTransformer 'links' => [ [ 'rel' => 'self', - 'uri' => '/budgets/limits/' . $budgetLimit->id, + 'uri' => '/budgets/limits/'.$budgetLimit->id, ], ], ]; diff --git a/app/Transformers/BudgetTransformer.php b/app/Transformers/BudgetTransformer.php index e4b6f16dfc..2450415f83 100644 --- a/app/Transformers/BudgetTransformer.php +++ b/app/Transformers/BudgetTransformer.php @@ -53,7 +53,7 @@ class BudgetTransformer extends AbstractTransformer /** * Transform a budget. * - * @param Budget $budget + * @param Budget $budget * * @return array */ @@ -81,7 +81,7 @@ class BudgetTransformer extends AbstractTransformer ]; if (null !== $autoBudget) { - $abCurrencyId = (string) $autoBudget->transactionCurrency->id; + $abCurrencyId = (string)$autoBudget->transactionCurrency->id; $abCurrencyCode = $autoBudget->transactionCurrency->code; $abType = $types[$autoBudget->auto_budget_type]; $abAmount = app('steam')->bcround($autoBudget->amount, $autoBudget->transactionCurrency->decimal_places); @@ -89,7 +89,7 @@ class BudgetTransformer extends AbstractTransformer } return [ - 'id' => (string) $budget->id, + 'id' => (string)$budget->id, 'created_at' => $budget->created_at->toAtomString(), 'updated_at' => $budget->updated_at->toAtomString(), 'active' => $budget->active, @@ -105,14 +105,14 @@ class BudgetTransformer extends AbstractTransformer 'links' => [ [ 'rel' => 'self', - 'uri' => '/budgets/' . $budget->id, + 'uri' => '/budgets/'.$budget->id, ], ], ]; } /** - * @param array $array + * @param array $array * * @return array */ @@ -120,7 +120,7 @@ class BudgetTransformer extends AbstractTransformer { $return = []; foreach ($array as $data) { - $data['sum'] = app('steam')->bcround($data['sum'], (int) $data['currency_decimal_places']); + $data['sum'] = app('steam')->bcround($data['sum'], (int)$data['currency_decimal_places']); $return[] = $data; } diff --git a/app/Transformers/CategoryTransformer.php b/app/Transformers/CategoryTransformer.php index 81fe257bf8..739a025726 100644 --- a/app/Transformers/CategoryTransformer.php +++ b/app/Transformers/CategoryTransformer.php @@ -50,7 +50,7 @@ class CategoryTransformer extends AbstractTransformer /** * Convert category. * - * @param Category $category + * @param Category $category * * @return array */ @@ -70,7 +70,7 @@ class CategoryTransformer extends AbstractTransformer $notes = $this->repository->getNoteText($category); return [ - 'id' => (int) $category->id, + 'id' => (int)$category->id, 'created_at' => $category->created_at->toAtomString(), 'updated_at' => $category->updated_at->toAtomString(), 'name' => $category->name, @@ -80,14 +80,14 @@ class CategoryTransformer extends AbstractTransformer 'links' => [ [ 'rel' => 'self', - 'uri' => '/categories/' . $category->id, + 'uri' => '/categories/'.$category->id, ], ], ]; } /** - * @param array $array + * @param array $array * * @return array */ @@ -95,7 +95,7 @@ class CategoryTransformer extends AbstractTransformer { $return = []; foreach ($array as $data) { - $data['sum'] = app('steam')->bcround($data['sum'], (int) $data['currency_decimal_places']); + $data['sum'] = app('steam')->bcround($data['sum'], (int)$data['currency_decimal_places']); $return[] = $data; } diff --git a/app/Transformers/CurrencyTransformer.php b/app/Transformers/CurrencyTransformer.php index 34e35045aa..3d3afef4d2 100644 --- a/app/Transformers/CurrencyTransformer.php +++ b/app/Transformers/CurrencyTransformer.php @@ -33,7 +33,7 @@ class CurrencyTransformer extends AbstractTransformer /** * Transform the currency. * - * @param TransactionCurrency $currency + * @param TransactionCurrency $currency * * @return array */ @@ -42,11 +42,11 @@ class CurrencyTransformer extends AbstractTransformer $isDefault = false; $defaultCurrency = $this->parameters->get('defaultCurrency'); if (null !== $defaultCurrency) { - $isDefault = (int) $defaultCurrency->id === (int) $currency->id; + $isDefault = (int)$defaultCurrency->id === (int)$currency->id; } return [ - 'id' => (int) $currency->id, + 'id' => (int)$currency->id, 'created_at' => $currency->created_at->toAtomString(), 'updated_at' => $currency->updated_at->toAtomString(), 'default' => $isDefault, @@ -54,11 +54,11 @@ class CurrencyTransformer extends AbstractTransformer 'name' => $currency->name, 'code' => $currency->code, 'symbol' => $currency->symbol, - 'decimal_places' => (int) $currency->decimal_places, + 'decimal_places' => (int)$currency->decimal_places, 'links' => [ [ 'rel' => 'self', - 'uri' => '/currencies/' . $currency->id, + 'uri' => '/currencies/'.$currency->id, ], ], ]; diff --git a/app/Transformers/LinkTypeTransformer.php b/app/Transformers/LinkTypeTransformer.php index b1e1097ed5..6fd860acc6 100644 --- a/app/Transformers/LinkTypeTransformer.php +++ b/app/Transformers/LinkTypeTransformer.php @@ -34,14 +34,14 @@ class LinkTypeTransformer extends AbstractTransformer /** * Transform the currency. * - * @param LinkType $linkType + * @param LinkType $linkType * * @return array */ public function transform(LinkType $linkType): array { return [ - 'id' => (int) $linkType->id, + 'id' => (int)$linkType->id, 'created_at' => $linkType->created_at->toAtomString(), 'updated_at' => $linkType->updated_at->toAtomString(), 'name' => $linkType->name, @@ -51,7 +51,7 @@ class LinkTypeTransformer extends AbstractTransformer 'links' => [ [ 'rel' => 'self', - 'uri' => '/link_types/' . $linkType->id, + 'uri' => '/link_types/'.$linkType->id, ], ], ]; diff --git a/app/Transformers/ObjectGroupTransformer.php b/app/Transformers/ObjectGroupTransformer.php index 6de992cea0..86f7d1e37a 100644 --- a/app/Transformers/ObjectGroupTransformer.php +++ b/app/Transformers/ObjectGroupTransformer.php @@ -47,7 +47,7 @@ class ObjectGroupTransformer extends AbstractTransformer /** * Transform the account. * - * @param ObjectGroup $objectGroup + * @param ObjectGroup $objectGroup * * @return array */ @@ -56,15 +56,15 @@ class ObjectGroupTransformer extends AbstractTransformer $this->repository->setUser($objectGroup->user); return [ - 'id' => (string) $objectGroup->id, + 'id' => (string)$objectGroup->id, 'created_at' => $objectGroup->created_at?->toAtomString(), 'updated_at' => $objectGroup->updated_at?->toAtomString(), 'title' => $objectGroup->title, - 'order' => (int) $objectGroup->order, + 'order' => (int)$objectGroup->order, 'links' => [ [ 'rel' => 'self', - 'uri' => '/object_groups/' . $objectGroup->id, + 'uri' => '/object_groups/'.$objectGroup->id, ], ], ]; diff --git a/app/Transformers/PiggyBankEventTransformer.php b/app/Transformers/PiggyBankEventTransformer.php index 5a925c6428..78dc72f53b 100644 --- a/app/Transformers/PiggyBankEventTransformer.php +++ b/app/Transformers/PiggyBankEventTransformer.php @@ -23,10 +23,12 @@ declare(strict_types=1); namespace FireflyIII\Transformers; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\PiggyBankEvent; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; +use JsonException; /** * Class PiggyBankEventTransformer @@ -52,11 +54,11 @@ class PiggyBankEventTransformer extends AbstractTransformer /** * Convert piggy bank event. * - * @param PiggyBankEvent $event + * @param PiggyBankEvent $event * * @return array - * @throws \FireflyIII\Exceptions\FireflyException - * @throws \JsonException + * @throws FireflyException + * @throws JsonException */ public function transform(PiggyBankEvent $event): array { @@ -74,26 +76,26 @@ class PiggyBankEventTransformer extends AbstractTransformer // get associated journal and transaction, if any: $journalId = $event->transaction_journal_id; $groupId = null; - if (0 !== (int) $journalId) { - $groupId = (int) $event->transactionJournal->transaction_group_id; - $journalId = (int) $journalId; + if (0 !== (int)$journalId) { + $groupId = (int)$event->transactionJournal->transaction_group_id; + $journalId = (int)$journalId; } return [ - 'id' => (string) $event->id, + 'id' => (string)$event->id, 'created_at' => $event->created_at->toAtomString(), 'updated_at' => $event->updated_at->toAtomString(), 'amount' => app('steam')->bcround($event->amount, $currency->decimal_places), - 'currency_id' => (string) $currency->id, + 'currency_id' => (string)$currency->id, 'currency_code' => $currency->code, 'currency_symbol' => $currency->symbol, - 'currency_decimal_places' => (int) $currency->decimal_places, - 'transaction_journal_id' => $journalId ? (string) $journalId : null, - 'transaction_group_id' => $groupId ? (string) $groupId : null, + 'currency_decimal_places' => (int)$currency->decimal_places, + 'transaction_journal_id' => $journalId ? (string)$journalId : null, + 'transaction_group_id' => $groupId ? (string)$groupId : null, 'links' => [ [ 'rel' => 'self', - 'uri' => '/piggy_bank_events/' . $event->id, + 'uri' => '/piggy_bank_events/'.$event->id, ], ], ]; diff --git a/app/Transformers/PiggyBankTransformer.php b/app/Transformers/PiggyBankTransformer.php index 016a0d5481..4b97997ce6 100644 --- a/app/Transformers/PiggyBankTransformer.php +++ b/app/Transformers/PiggyBankTransformer.php @@ -23,11 +23,13 @@ declare(strict_types=1); namespace FireflyIII\Transformers; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\ObjectGroup; use FireflyIII\Models\PiggyBank; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; +use JsonException; /** * Class PiggyBankTransformer @@ -56,8 +58,8 @@ class PiggyBankTransformer extends AbstractTransformer * @param PiggyBank $piggyBank * * @return array - * @throws \FireflyIII\Exceptions\FireflyException - * @throws \JsonException + * @throws FireflyException + * @throws JsonException */ public function transform(PiggyBank $piggyBank): array { diff --git a/app/Transformers/PreferenceTransformer.php b/app/Transformers/PreferenceTransformer.php index 5a6421050f..34298d9b4f 100644 --- a/app/Transformers/PreferenceTransformer.php +++ b/app/Transformers/PreferenceTransformer.php @@ -33,14 +33,14 @@ class PreferenceTransformer extends AbstractTransformer /** * Transform the preference * - * @param Preference $preference + * @param Preference $preference * * @return array */ public function transform(Preference $preference): array { return [ - 'id' => (int) $preference->id, + 'id' => (int)$preference->id, 'created_at' => $preference->created_at->toAtomString(), 'updated_at' => $preference->updated_at->toAtomString(), 'name' => $preference->name, diff --git a/app/Transformers/RecurrenceTransformer.php b/app/Transformers/RecurrenceTransformer.php index be829e8e4e..c6571aba99 100644 --- a/app/Transformers/RecurrenceTransformer.php +++ b/app/Transformers/RecurrenceTransformer.php @@ -65,7 +65,7 @@ class RecurrenceTransformer extends AbstractTransformer /** * Transform the recurring transaction. * - * @param Recurrence $recurrence + * @param Recurrence $recurrence * * @return array * @throws FireflyException @@ -79,14 +79,14 @@ class RecurrenceTransformer extends AbstractTransformer $this->budgetRepos->setUser($recurrence->user); Log::debug('Set user.'); - $shortType = (string) config(sprintf('firefly.transactionTypesToShort.%s', $recurrence->transactionType->type)); + $shortType = (string)config(sprintf('firefly.transactionTypesToShort.%s', $recurrence->transactionType->type)); $notes = $this->repository->getNoteText($recurrence); - $reps = 0 === (int) $recurrence->repetitions ? null : (int) $recurrence->repetitions; + $reps = 0 === (int)$recurrence->repetitions ? null : (int)$recurrence->repetitions; Log::debug('Get basic data.'); // basic data. return [ - 'id' => (string) $recurrence->id, + 'id' => (string)$recurrence->id, 'created_at' => $recurrence->created_at->toAtomString(), 'updated_at' => $recurrence->updated_at->toAtomString(), 'type' => $shortType, @@ -104,14 +104,14 @@ class RecurrenceTransformer extends AbstractTransformer 'links' => [ [ 'rel' => 'self', - 'uri' => '/recurring/' . $recurrence->id, + 'uri' => '/recurring/'.$recurrence->id, ], ], ]; } /** - * @param Recurrence $recurrence + * @param Recurrence $recurrence * * @return array * @throws FireflyException @@ -125,13 +125,13 @@ class RecurrenceTransformer extends AbstractTransformer /** @var RecurrenceRepetition $repetition */ foreach ($recurrence->recurrenceRepetitions as $repetition) { $repetitionArray = [ - 'id' => (string) $repetition->id, + 'id' => (string)$repetition->id, 'created_at' => $repetition->created_at->toAtomString(), 'updated_at' => $repetition->updated_at->toAtomString(), 'type' => $repetition->repetition_type, 'moment' => $repetition->repetition_moment, - 'skip' => (int) $repetition->repetition_skip, - 'weekend' => (int) $repetition->weekend, + 'skip' => (int)$repetition->repetition_skip, + 'weekend' => (int)$repetition->weekend, 'description' => $this->repository->repetitionDescription($repetition), 'occurrences' => [], ]; @@ -150,7 +150,7 @@ class RecurrenceTransformer extends AbstractTransformer } /** - * @param Recurrence $recurrence + * @param Recurrence $recurrence * * @return array * @throws FireflyException @@ -169,10 +169,10 @@ class RecurrenceTransformer extends AbstractTransformer $foreignCurrencyDp = null; $foreignCurrencyId = null; if (null !== $transaction->foreign_currency_id) { - $foreignCurrencyId = (int) $transaction->foreign_currency_id; + $foreignCurrencyId = (int)$transaction->foreign_currency_id; $foreignCurrencyCode = $transaction->foreignCurrency->code; $foreignCurrencySymbol = $transaction->foreignCurrency->symbol; - $foreignCurrencyDp = (int) $transaction->foreignCurrency->decimal_places; + $foreignCurrencyDp = (int)$transaction->foreignCurrency->decimal_places; } // source info: @@ -182,7 +182,7 @@ class RecurrenceTransformer extends AbstractTransformer $sourceIban = null; if (null !== $sourceAccount) { $sourceName = $sourceAccount->name; - $sourceId = (int) $sourceAccount->id; + $sourceId = (int)$sourceAccount->id; $sourceType = $sourceAccount->accountType->type; $sourceIban = $sourceAccount->iban; } @@ -192,7 +192,7 @@ class RecurrenceTransformer extends AbstractTransformer $destinationIban = null; if (null !== $destinationAccount) { $destinationName = $destinationAccount->name; - $destinationId = (int) $destinationAccount->id; + $destinationId = (int)$destinationAccount->id; $destinationType = $destinationAccount->accountType->type; $destinationIban = $destinationAccount->iban; } @@ -202,19 +202,19 @@ class RecurrenceTransformer extends AbstractTransformer $foreignAmount = app('steam')->bcround($transaction->foreign_amount, $foreignCurrencyDp); } $transactionArray = [ - 'currency_id' => (string) $transaction->transaction_currency_id, + 'currency_id' => (string)$transaction->transaction_currency_id, 'currency_code' => $transaction->transactionCurrency->code, 'currency_symbol' => $transaction->transactionCurrency->symbol, - 'currency_decimal_places' => (int) $transaction->transactionCurrency->decimal_places, - 'foreign_currency_id' => null === $foreignCurrencyId ? null : (string) $foreignCurrencyId, + 'currency_decimal_places' => (int)$transaction->transactionCurrency->decimal_places, + 'foreign_currency_id' => null === $foreignCurrencyId ? null : (string)$foreignCurrencyId, 'foreign_currency_code' => $foreignCurrencyCode, 'foreign_currency_symbol' => $foreignCurrencySymbol, 'foreign_currency_decimal_places' => $foreignCurrencyDp, - 'source_id' => (string) $sourceId, + 'source_id' => (string)$sourceId, 'source_name' => $sourceName, 'source_iban' => $sourceIban, 'source_type' => $sourceType, - 'destination_id' => (string) $destinationId, + 'destination_id' => (string)$destinationId, 'destination_name' => $destinationName, 'destination_iban' => $destinationIban, 'destination_type' => $destinationType, @@ -237,8 +237,8 @@ class RecurrenceTransformer extends AbstractTransformer } /** - * @param RecurrenceTransaction $transaction - * @param array $array + * @param RecurrenceTransaction $transaction + * @param array $array * * @return array * @throws FireflyException @@ -262,9 +262,9 @@ class RecurrenceTransformer extends AbstractTransformer default: throw new FireflyException(sprintf('Recurrence transformer cant handle field "%s"', $transactionMeta->name)); case 'bill_id': - $bill = $this->billRepos->find((int) $transactionMeta->value); + $bill = $this->billRepos->find((int)$transactionMeta->value); if (null !== $bill) { - $array['bill_id'] = (string) $bill->id; + $array['bill_id'] = (string)$bill->id; $array['bill_name'] = $bill->name; } break; @@ -272,30 +272,30 @@ class RecurrenceTransformer extends AbstractTransformer $array['tags'] = json_decode($transactionMeta->value); break; case 'piggy_bank_id': - $piggy = $this->piggyRepos->find((int) $transactionMeta->value); + $piggy = $this->piggyRepos->find((int)$transactionMeta->value); if (null !== $piggy) { - $array['piggy_bank_id'] = (string) $piggy->id; + $array['piggy_bank_id'] = (string)$piggy->id; $array['piggy_bank_name'] = $piggy->name; } break; case 'category_id': - $category = $this->factory->findOrCreate((int) $transactionMeta->value, null); + $category = $this->factory->findOrCreate((int)$transactionMeta->value, null); if (null !== $category) { - $array['category_id'] = (string) $category->id; + $array['category_id'] = (string)$category->id; $array['category_name'] = $category->name; } break; case 'category_name': $category = $this->factory->findOrCreate(null, $transactionMeta->value); if (null !== $category) { - $array['category_id'] = (string) $category->id; + $array['category_id'] = (string)$category->id; $array['category_name'] = $category->name; } break; case 'budget_id': - $budget = $this->budgetRepos->find((int) $transactionMeta->value); + $budget = $this->budgetRepos->find((int)$transactionMeta->value); if (null !== $budget) { - $array['budget_id'] = (string) $budget->id; + $array['budget_id'] = (string)$budget->id; $array['budget_name'] = $budget->name; } break; diff --git a/app/Transformers/RuleGroupTransformer.php b/app/Transformers/RuleGroupTransformer.php index cd57727424..0c7f4ba1c1 100644 --- a/app/Transformers/RuleGroupTransformer.php +++ b/app/Transformers/RuleGroupTransformer.php @@ -33,14 +33,14 @@ class RuleGroupTransformer extends AbstractTransformer /** * Transform the rule group * - * @param RuleGroup $ruleGroup + * @param RuleGroup $ruleGroup * * @return array */ public function transform(RuleGroup $ruleGroup): array { return [ - 'id' => (int) $ruleGroup->id, + 'id' => (int)$ruleGroup->id, 'created_at' => $ruleGroup->created_at->toAtomString(), 'updated_at' => $ruleGroup->updated_at->toAtomString(), 'title' => $ruleGroup->title, @@ -50,7 +50,7 @@ class RuleGroupTransformer extends AbstractTransformer 'links' => [ [ 'rel' => 'self', - 'uri' => '/rule_groups/' . $ruleGroup->id, + 'uri' => '/rule_groups/'.$ruleGroup->id, ], ], ]; diff --git a/app/Transformers/RuleTransformer.php b/app/Transformers/RuleTransformer.php index b338bb767b..459dce79fe 100644 --- a/app/Transformers/RuleTransformer.php +++ b/app/Transformers/RuleTransformer.php @@ -50,7 +50,7 @@ class RuleTransformer extends AbstractTransformer /** * Transform the rule. * - * @param Rule $rule + * @param Rule $rule * * @return array * @throws FireflyException @@ -60,14 +60,14 @@ class RuleTransformer extends AbstractTransformer $this->ruleRepository->setUser($rule->user); return [ - 'id' => (string) $rule->id, + 'id' => (string)$rule->id, 'created_at' => $rule->created_at->toAtomString(), 'updated_at' => $rule->updated_at->toAtomString(), - 'rule_group_id' => (string) $rule->rule_group_id, - 'rule_group_title' => (string) $rule->ruleGroup->title, + 'rule_group_id' => (string)$rule->rule_group_id, + 'rule_group_title' => (string)$rule->ruleGroup->title, 'title' => $rule->title, 'description' => $rule->description, - 'order' => (int) $rule->order, + 'order' => (int)$rule->order, 'active' => $rule->active, 'strict' => $rule->strict, 'stop_processing' => $rule->stop_processing, @@ -77,14 +77,14 @@ class RuleTransformer extends AbstractTransformer 'links' => [ [ 'rel' => 'self', - 'uri' => '/rules/' . $rule->id, + 'uri' => '/rules/'.$rule->id, ], ], ]; } /** - * @param Rule $rule + * @param Rule $rule * * @return string * @throws FireflyException @@ -107,7 +107,7 @@ class RuleTransformer extends AbstractTransformer } /** - * @param Rule $rule + * @param Rule $rule * * @return array */ @@ -121,7 +121,7 @@ class RuleTransformer extends AbstractTransformer continue; } $result[] = [ - 'id' => (string) $ruleTrigger->id, + 'id' => (string)$ruleTrigger->id, 'created_at' => $ruleTrigger->created_at->toAtomString(), 'updated_at' => $ruleTrigger->updated_at->toAtomString(), 'type' => $ruleTrigger->trigger_type, @@ -136,7 +136,7 @@ class RuleTransformer extends AbstractTransformer } /** - * @param Rule $rule + * @param Rule $rule * * @return array */ @@ -147,7 +147,7 @@ class RuleTransformer extends AbstractTransformer /** @var RuleAction $ruleAction */ foreach ($actions as $ruleAction) { $result[] = [ - 'id' => (string) $ruleAction->id, + 'id' => (string)$ruleAction->id, 'created_at' => $ruleAction->created_at->toAtomString(), 'updated_at' => $ruleAction->updated_at->toAtomString(), 'type' => $ruleAction->action_type, diff --git a/app/Transformers/TagTransformer.php b/app/Transformers/TagTransformer.php index 99d81fb1c5..ca650b4463 100644 --- a/app/Transformers/TagTransformer.php +++ b/app/Transformers/TagTransformer.php @@ -36,7 +36,7 @@ class TagTransformer extends AbstractTransformer * * TODO add spent, earned, transferred, etc. * - * @param Tag $tag + * @param Tag $tag * * @return array */ @@ -51,11 +51,11 @@ class TagTransformer extends AbstractTransformer if (null !== $location) { $latitude = $location->latitude; $longitude = $location->longitude; - $zoomLevel = (int) $location->zoom_level; + $zoomLevel = (int)$location->zoom_level; } return [ - 'id' => (int) $tag->id, + 'id' => (int)$tag->id, 'created_at' => $tag->created_at->toAtomString(), 'updated_at' => $tag->updated_at->toAtomString(), 'tag' => $tag->tag, @@ -67,7 +67,7 @@ class TagTransformer extends AbstractTransformer 'links' => [ [ 'rel' => 'self', - 'uri' => '/tags/' . $tag->id, + 'uri' => '/tags/'.$tag->id, ], ], ]; diff --git a/app/Transformers/TransactionGroupTransformer.php b/app/Transformers/TransactionGroupTransformer.php index adf222c03a..0f055f1382 100644 --- a/app/Transformers/TransactionGroupTransformer.php +++ b/app/Transformers/TransactionGroupTransformer.php @@ -56,16 +56,29 @@ class TransactionGroupTransformer extends AbstractTransformer { $this->groupRepos = app(TransactionGroupRepositoryInterface::class); $this->metaFields = [ - 'sepa_cc', 'sepa_ct_op', 'sepa_ct_id', 'sepa_db', 'sepa_country', 'sepa_ep', - 'sepa_ci', 'sepa_batch_id', 'internal_reference', 'bunq_payment_id', 'import_hash_v2', - 'recurrence_id', 'external_id', 'original_source', 'external_url', - 'recurrence_count', 'recurrence_total', + 'sepa_cc', + 'sepa_ct_op', + 'sepa_ct_id', + 'sepa_db', + 'sepa_country', + 'sepa_ep', + 'sepa_ci', + 'sepa_batch_id', + 'internal_reference', + 'bunq_payment_id', + 'import_hash_v2', + 'recurrence_id', + 'external_id', + 'original_source', + 'external_url', + 'recurrence_count', + 'recurrence_total', ]; $this->metaDateFields = ['interest_date', 'book_date', 'process_date', 'due_date', 'payment_date', 'invoice_date']; } /** - * @param array $group + * @param array $group * * @return array */ @@ -75,23 +88,23 @@ class TransactionGroupTransformer extends AbstractTransformer $first = new NullArrayObject(reset($group['transactions'])); return [ - 'id' => (int) $first['transaction_group_id'], + 'id' => (int)$first['transaction_group_id'], 'created_at' => $first['created_at']->toAtomString(), 'updated_at' => $first['updated_at']->toAtomString(), - 'user' => (string) $data['user_id'], + 'user' => (string)$data['user_id'], 'group_title' => $data['title'], 'transactions' => $this->transformTransactions($data), 'links' => [ [ 'rel' => 'self', - 'uri' => '/transactions/' . $first['transaction_group_id'], + 'uri' => '/transactions/'.$first['transaction_group_id'], ], ], ]; } /** - * @param NullArrayObject $data + * @param NullArrayObject $data * * @return array */ @@ -107,7 +120,7 @@ class TransactionGroupTransformer extends AbstractTransformer } /** - * @param array $transaction + * @param array $transaction * * @return array */ @@ -116,21 +129,21 @@ class TransactionGroupTransformer extends AbstractTransformer $row = new NullArrayObject($transaction); // amount: - $amount = app('steam')->positive((string) ($row['amount'] ?? '0')); + $amount = app('steam')->positive((string)($row['amount'] ?? '0')); $foreignAmount = null; if (null !== $row['foreign_amount'] && '' !== $row['foreign_amount'] && bccomp('0', $row['foreign_amount']) !== 0) { $foreignAmount = app('steam')->positive($row['foreign_amount']); } - $metaFieldData = $this->groupRepos->getMetaFields((int) $row['transaction_journal_id'], $this->metaFields); - $metaDateData = $this->groupRepos->getMetaDateFields((int) $row['transaction_journal_id'], $this->metaDateFields); + $metaFieldData = $this->groupRepos->getMetaFields((int)$row['transaction_journal_id'], $this->metaFields); + $metaDateData = $this->groupRepos->getMetaDateFields((int)$row['transaction_journal_id'], $this->metaDateFields); $type = $this->stringFromArray($transaction, 'transaction_type_type', TransactionType::WITHDRAWAL); $longitude = null; $latitude = null; $zoomLevel = null; - $location = $this->getLocationById((int) $row['transaction_journal_id']); + $location = $this->getLocationById((int)$row['transaction_journal_id']); if (null !== $location) { $longitude = $location->longitude; $latitude = $location->latitude; @@ -138,17 +151,17 @@ class TransactionGroupTransformer extends AbstractTransformer } return [ - 'user' => (string) $row['user_id'], - 'transaction_journal_id' => (string) $row['transaction_journal_id'], + 'user' => (string)$row['user_id'], + 'transaction_journal_id' => (string)$row['transaction_journal_id'], 'type' => strtolower($type), 'date' => $row['date']->toAtomString(), 'order' => $row['order'], - 'currency_id' => (string) $row['currency_id'], + 'currency_id' => (string)$row['currency_id'], 'currency_code' => $row['currency_code'], 'currency_name' => $row['currency_name'], 'currency_symbol' => $row['currency_symbol'], - 'currency_decimal_places' => (int) $row['currency_decimal_places'], + 'currency_decimal_places' => (int)$row['currency_decimal_places'], 'foreign_currency_id' => $this->stringFromArray($transaction, 'foreign_currency_id', null), 'foreign_currency_code' => $row['foreign_currency_code'], @@ -160,12 +173,12 @@ class TransactionGroupTransformer extends AbstractTransformer 'description' => $row['description'], - 'source_id' => (string) $row['source_account_id'], + 'source_id' => (string)$row['source_account_id'], 'source_name' => $row['source_account_name'], 'source_iban' => $row['source_account_iban'], 'source_type' => $row['source_account_type'], - 'destination_id' => (string) $row['destination_account_id'], + 'destination_id' => (string)$row['destination_account_id'], 'destination_name' => $row['destination_account_name'], 'destination_iban' => $row['destination_account_iban'], 'destination_type' => $row['destination_account_type'], @@ -180,8 +193,8 @@ class TransactionGroupTransformer extends AbstractTransformer 'bill_name' => $row['bill_name'], 'reconciled' => $row['reconciled'], - 'notes' => $this->groupRepos->getNoteText((int) $row['transaction_journal_id']), - 'tags' => $this->groupRepos->getTags((int) $row['transaction_journal_id']), + 'notes' => $this->groupRepos->getNoteText((int)$row['transaction_journal_id']), + 'tags' => $this->groupRepos->getTags((int)$row['transaction_journal_id']), 'internal_reference' => $metaFieldData['internal_reference'], 'external_id' => $metaFieldData['external_id'], @@ -214,14 +227,14 @@ class TransactionGroupTransformer extends AbstractTransformer 'latitude' => $latitude, 'zoom_level' => $zoomLevel, - 'has_attachments' => $this->hasAttachments((int) $row['transaction_journal_id']), + 'has_attachments' => $this->hasAttachments((int)$row['transaction_journal_id']), ]; } /** - * @param array $array - * @param string $key - * @param string|null $default + * @param array $array + * @param string $key + * @param string|null $default * * @return string|null */ @@ -231,18 +244,18 @@ class TransactionGroupTransformer extends AbstractTransformer return null; } if (array_key_exists($key, $array) && null !== $array[$key]) { - return (string) $array[$key]; + return (string)$array[$key]; } if (null !== $default) { - return (string) $default; + return (string)$default; } return null; } /** - * @param int $journalId + * @param int $journalId * * @return Location|null */ @@ -252,23 +265,33 @@ class TransactionGroupTransformer extends AbstractTransformer } /** - * @param array $array - * @param string $key + * @param TransactionJournal $journal + * + * @return Location|null + */ + private function getLocation(TransactionJournal $journal): ?Location + { + return $journal->locations()->first(); + } + + /** + * @param array $array + * @param string $key * * @return int|null */ private function integerFromArray(array $array, string $key): ?int { if (array_key_exists($key, $array)) { - return (int) $array[$key]; + return (int)$array[$key]; } return null; } /** - * @param NullArrayObject $object - * @param string $key + * @param NullArrayObject $object + * @param string $key * * @return string|null */ @@ -282,7 +305,7 @@ class TransactionGroupTransformer extends AbstractTransformer } /** - * @param int $journalId + * @param int $journalId * * @return bool */ @@ -292,7 +315,7 @@ class TransactionGroupTransformer extends AbstractTransformer } /** - * @param TransactionGroup $group + * @param TransactionGroup $group * * @return array * @throws FireflyException @@ -301,16 +324,16 @@ class TransactionGroupTransformer extends AbstractTransformer { try { $result = [ - 'id' => (int) $group->id, + 'id' => (int)$group->id, 'created_at' => $group->created_at->toAtomString(), 'updated_at' => $group->updated_at->toAtomString(), - 'user' => (int) $group->user_id, + 'user' => (int)$group->user_id, 'group_title' => $group->title, 'transactions' => $this->transformJournals($group->transactionJournals), 'links' => [ [ 'rel' => 'self', - 'uri' => '/transactions/' . $group->id, + 'uri' => '/transactions/'.$group->id, ], ], ]; @@ -326,7 +349,7 @@ class TransactionGroupTransformer extends AbstractTransformer } /** - * @param Collection $transactionJournals + * @param Collection $transactionJournals * * @return array * @throws FireflyException @@ -343,7 +366,7 @@ class TransactionGroupTransformer extends AbstractTransformer } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return array * @throws FireflyException @@ -353,8 +376,8 @@ class TransactionGroupTransformer extends AbstractTransformer $source = $this->getSourceTransaction($journal); $destination = $this->getDestinationTransaction($journal); $type = $journal->transactionType->type; - $amount = $this->getAmount($type, (string) $source->amount); - $foreignAmount = $this->getForeignAmount($type, null === $source->foreign_amount ? null : (string) $source->foreign_amount); + $amount = $this->getAmount($type, (string)$source->amount); + $foreignAmount = $this->getForeignAmount($type, null === $source->foreign_amount ? null : (string)$source->foreign_amount); $metaFieldData = $this->groupRepos->getMetaFields($journal->id, $this->metaFields); $metaDates = $this->getDates($this->groupRepos->getMetaDateFields($journal->id, $this->metaDateFields)); $currency = $source->transactionCurrency; @@ -378,16 +401,16 @@ class TransactionGroupTransformer extends AbstractTransformer } return [ - 'user' => (int) $journal->user_id, - 'transaction_journal_id' => (int) $journal->id, + 'user' => (int)$journal->user_id, + 'transaction_journal_id' => (int)$journal->id, 'type' => strtolower($type), 'date' => $journal->date->toAtomString(), 'order' => $journal->order, - 'currency_id' => (int) $currency->id, + 'currency_id' => (int)$currency->id, 'currency_code' => $currency->code, 'currency_symbol' => $currency->symbol, - 'currency_decimal_places' => (int) $currency->decimal_places, + 'currency_decimal_places' => (int)$currency->decimal_places, 'foreign_currency_id' => $foreignCurrency['id'], 'foreign_currency_code' => $foreignCurrency['code'], @@ -399,12 +422,12 @@ class TransactionGroupTransformer extends AbstractTransformer 'description' => $journal->description, - 'source_id' => (int) $source->account_id, + 'source_id' => (int)$source->account_id, 'source_name' => $source->account->name, 'source_iban' => $source->account->iban, 'source_type' => $source->account->accountType->type, - 'destination_id' => (int) $destination->account_id, + 'destination_id' => (int)$destination->account_id, 'destination_name' => $destination->account->name, 'destination_iban' => $destination->account->iban, 'destination_type' => $destination->account->accountType->type, @@ -453,7 +476,7 @@ class TransactionGroupTransformer extends AbstractTransformer } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return Transaction * @throws FireflyException @@ -462,7 +485,7 @@ class TransactionGroupTransformer extends AbstractTransformer { $result = $journal->transactions->first( static function (Transaction $transaction) { - return (float) $transaction->amount < 0; // lame but it works. + return (float)$transaction->amount < 0; // lame but it works. } ); if (null === $result) { @@ -473,7 +496,7 @@ class TransactionGroupTransformer extends AbstractTransformer } /** - * @param TransactionJournal $journal + * @param TransactionJournal $journal * * @return Transaction * @throws FireflyException @@ -482,7 +505,7 @@ class TransactionGroupTransformer extends AbstractTransformer { $result = $journal->transactions->first( static function (Transaction $transaction) { - return (float) $transaction->amount > 0; // lame but it works + return (float)$transaction->amount > 0; // lame but it works } ); if (null === $result) { @@ -493,8 +516,8 @@ class TransactionGroupTransformer extends AbstractTransformer } /** - * @param string $type - * @param string $amount + * @param string $type + * @param string $amount * * @return string */ @@ -509,8 +532,8 @@ class TransactionGroupTransformer extends AbstractTransformer } /** - * @param string $type - * @param string|null $foreignAmount + * @param string $type + * @param string|null $foreignAmount * * @return string|null */ @@ -525,7 +548,7 @@ class TransactionGroupTransformer extends AbstractTransformer } /** - * @param NullArrayObject $dates + * @param NullArrayObject $dates * * @return array */ @@ -551,7 +574,7 @@ class TransactionGroupTransformer extends AbstractTransformer } /** - * @param TransactionCurrency|null $currency + * @param TransactionCurrency|null $currency * * @return array */ @@ -566,16 +589,16 @@ class TransactionGroupTransformer extends AbstractTransformer if (null === $currency) { return $array; } - $array['id'] = (int) $currency->id; + $array['id'] = (int)$currency->id; $array['code'] = $currency->code; $array['symbol'] = $currency->symbol; - $array['decimal_places'] = (int) $currency->decimal_places; + $array['decimal_places'] = (int)$currency->decimal_places; return $array; } /** - * @param Budget|null $budget + * @param Budget|null $budget * * @return array */ @@ -588,14 +611,14 @@ class TransactionGroupTransformer extends AbstractTransformer if (null === $budget) { return $array; } - $array['id'] = (int) $budget->id; + $array['id'] = (int)$budget->id; $array['name'] = $budget->name; return $array; } /** - * @param Category|null $category + * @param Category|null $category * * @return array */ @@ -608,14 +631,14 @@ class TransactionGroupTransformer extends AbstractTransformer if (null === $category) { return $array; } - $array['id'] = (int) $category->id; + $array['id'] = (int)$category->id; $array['name'] = $category->name; return $array; } /** - * @param Bill|null $bill + * @param Bill|null $bill * * @return array */ @@ -628,19 +651,9 @@ class TransactionGroupTransformer extends AbstractTransformer if (null === $bill) { return $array; } - $array['id'] = (string) $bill->id; + $array['id'] = (string)$bill->id; $array['name'] = $bill->name; return $array; } - - /** - * @param TransactionJournal $journal - * - * @return Location|null - */ - private function getLocation(TransactionJournal $journal): ?Location - { - return $journal->locations()->first(); - } } diff --git a/app/Transformers/TransactionLinkTransformer.php b/app/Transformers/TransactionLinkTransformer.php index e8a865e93d..47185d812d 100644 --- a/app/Transformers/TransactionLinkTransformer.php +++ b/app/Transformers/TransactionLinkTransformer.php @@ -46,7 +46,7 @@ class TransactionLinkTransformer extends AbstractTransformer } /** - * @param TransactionJournalLink $link + * @param TransactionJournalLink $link * * @return array */ @@ -55,17 +55,17 @@ class TransactionLinkTransformer extends AbstractTransformer $notes = $this->repository->getLinkNoteText($link); return [ - 'id' => (string) $link->id, + 'id' => (string)$link->id, 'created_at' => $link->created_at->toAtomString(), 'updated_at' => $link->updated_at->toAtomString(), - 'inward_id' => (string) $link->source_id, - 'outward_id' => (string) $link->destination_id, - 'link_type_id' => (string) $link->link_type_id, + 'inward_id' => (string)$link->source_id, + 'outward_id' => (string)$link->destination_id, + 'link_type_id' => (string)$link->link_type_id, 'notes' => '' === $notes ? null : $notes, 'links' => [ [ 'rel' => 'self', - 'uri' => '/transaction_links/' . $link->id, + 'uri' => '/transaction_links/'.$link->id, ], ], ]; diff --git a/app/Transformers/UserTransformer.php b/app/Transformers/UserTransformer.php index 6180f96462..a24f521251 100644 --- a/app/Transformers/UserTransformer.php +++ b/app/Transformers/UserTransformer.php @@ -37,7 +37,7 @@ class UserTransformer extends AbstractTransformer /** * Transform user. * - * @param User $user + * @param User $user * * @return array */ @@ -46,17 +46,17 @@ class UserTransformer extends AbstractTransformer $this->repository = $this->repository ?? app(UserRepositoryInterface::class); return [ - 'id' => (int) $user->id, + 'id' => (int)$user->id, 'created_at' => $user->created_at->toAtomString(), 'updated_at' => $user->updated_at->toAtomString(), 'email' => $user->email, - 'blocked' => 1 === (int) $user->blocked, + 'blocked' => 1 === (int)$user->blocked, 'blocked_code' => '' === $user->blocked_code ? null : $user->blocked_code, 'role' => $this->repository->getRoleByUser($user), 'links' => [ [ 'rel' => 'self', - 'uri' => '/users/' . $user->id, + 'uri' => '/users/'.$user->id, ], ], ]; diff --git a/app/Transformers/V2/AbstractTransformer.php b/app/Transformers/V2/AbstractTransformer.php index b2ef77d2c7..6a46d8f1b5 100644 --- a/app/Transformers/V2/AbstractTransformer.php +++ b/app/Transformers/V2/AbstractTransformer.php @@ -36,7 +36,7 @@ abstract class AbstractTransformer extends TransformerAbstract protected ParameterBag $parameters; /** - * @param Collection $objects + * @param Collection $objects * @return void */ abstract public function collectMetaData(Collection $objects): void; @@ -51,7 +51,7 @@ abstract class AbstractTransformer extends TransformerAbstract } /** - * @param ParameterBag $parameters + * @param ParameterBag $parameters */ final public function setParameters(ParameterBag $parameters): void { diff --git a/app/Transformers/V2/AccountTransformer.php b/app/Transformers/V2/AccountTransformer.php index 16db6e4a9d..4c534a5dd0 100644 --- a/app/Transformers/V2/AccountTransformer.php +++ b/app/Transformers/V2/AccountTransformer.php @@ -37,15 +37,46 @@ use Illuminate\Support\Collection; */ class AccountTransformer extends AbstractTransformer { - private array $currencies; private array $accountMeta; - private ?TransactionCurrency $currency; private array $balances; + private array $currencies; + private ?TransactionCurrency $currency; + + /** + * @inheritDoc + * @throws FireflyException + */ + public function collectMetaData(Collection $objects): void + { + $this->currency = null; + $this->currencies = []; + $this->accountMeta = []; + $this->balances = app('steam')->balancesByAccounts($objects, $this->getDate()); + $repository = app(CurrencyRepositoryInterface::class); + $this->currency = app('amount')->getDefaultCurrency(); + + // get currencies: + $accountIds = $objects->pluck('id')->toArray(); + $meta = AccountMeta::whereIn('account_id', $accountIds) + ->where('name', 'currency_id') + ->get(['account_meta.id', 'account_meta.account_id', 'account_meta.name', 'account_meta.data']); + $currencyIds = $meta->pluck('data')->toArray(); + + $currencies = $repository->getByIds($currencyIds); + foreach ($currencies as $currency) { + $id = (int)$currency->id; + $this->currencies[$id] = $currency; + } + foreach ($meta as $entry) { + $id = (int)$entry->account_id; + $this->accountMeta[$id][$entry->name] = $entry->data; + } + } /** * Transform the account. * - * @param Account $account + * @param Account $account * * @return array */ @@ -53,16 +84,16 @@ class AccountTransformer extends AbstractTransformer { //$fullType = $account->accountType->type; //$accountType = (string) config(sprintf('firefly.shortNamesByFullName.%s', $fullType)); - $id = (int) $account->id; + $id = (int)$account->id; // no currency? use default $currency = $this->currency; - if (0 !== (int) $this->accountMeta[$id]['currency_id']) { - $currency = $this->currencies[(int) $this->accountMeta[$id]['currency_id']]; + if (0 !== (int)$this->accountMeta[$id]['currency_id']) { + $currency = $this->currencies[(int)$this->accountMeta[$id]['currency_id']]; } return [ - 'id' => (string) $account->id, + 'id' => (string)$account->id, 'created_at' => $account->created_at->toAtomString(), 'updated_at' => $account->updated_at->toAtomString(), 'active' => $account->active, @@ -97,7 +128,7 @@ class AccountTransformer extends AbstractTransformer 'links' => [ [ 'rel' => 'self', - 'uri' => '/accounts/' . $account->id, + 'uri' => '/accounts/'.$account->id, ], ], ]; @@ -115,35 +146,4 @@ class AccountTransformer extends AbstractTransformer return $date; } - - /** - * @inheritDoc - * @throws FireflyException - */ - public function collectMetaData(Collection $objects): void - { - $this->currency = null; - $this->currencies = []; - $this->accountMeta = []; - $this->balances = app('steam')->balancesByAccounts($objects, $this->getDate()); - $repository = app(CurrencyRepositoryInterface::class); - $this->currency = app('amount')->getDefaultCurrency(); - - // get currencies: - $accountIds = $objects->pluck('id')->toArray(); - $meta = AccountMeta::whereIn('account_id', $accountIds) - ->where('name', 'currency_id') - ->get(['account_meta.id', 'account_meta.account_id', 'account_meta.name', 'account_meta.data']); - $currencyIds = $meta->pluck('data')->toArray(); - - $currencies = $repository->getByIds($currencyIds); - foreach ($currencies as $currency) { - $id = (int) $currency->id; - $this->currencies[$id] = $currency; - } - foreach ($meta as $entry) { - $id = (int) $entry->account_id; - $this->accountMeta[$id][$entry->name] = $entry->data; - } - } } diff --git a/app/Transformers/V2/BudgetLimitTransformer.php b/app/Transformers/V2/BudgetLimitTransformer.php index 792ead66ea..470410cab7 100644 --- a/app/Transformers/V2/BudgetLimitTransformer.php +++ b/app/Transformers/V2/BudgetLimitTransformer.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace FireflyIII\Transformers\V2; use FireflyIII\Models\BudgetLimit; -use FireflyIII\Repositories\Budget\OperationsRepository; use Illuminate\Support\Collection; use League\Fractal\Resource\Item; @@ -39,10 +38,18 @@ class BudgetLimitTransformer extends AbstractTransformer 'budget', ]; + /** + * @inheritDoc + */ + public function collectMetaData(Collection $objects): void + { + // TODO: Implement collectMetaData() method. + } + /** * Include Budget * - * @param BudgetLimit $limit + * @param BudgetLimit $limit * * @return Item */ @@ -54,7 +61,7 @@ class BudgetLimitTransformer extends AbstractTransformer /** * Transform the note. * - * @param BudgetLimit $budgetLimit + * @param BudgetLimit $budgetLimit * * @return array */ @@ -74,22 +81,22 @@ class BudgetLimitTransformer extends AbstractTransformer $currencySymbol = null; if (null !== $currency) { $amount = $budgetLimit->amount; - $currencyId = (int) $currency->id; + $currencyId = (int)$currency->id; $currencyName = $currency->name; $currencyCode = $currency->code; $currencySymbol = $currency->symbol; $currencyDecimalPlaces = $currency->decimal_places; } - $amount = number_format((float) $amount, $currencyDecimalPlaces, '.', ''); + $amount = number_format((float)$amount, $currencyDecimalPlaces, '.', ''); return [ - 'id' => (string) $budgetLimit->id, + 'id' => (string)$budgetLimit->id, 'created_at' => $budgetLimit->created_at->toAtomString(), 'updated_at' => $budgetLimit->updated_at->toAtomString(), 'start' => $budgetLimit->start_date->toAtomString(), 'end' => $budgetLimit->end_date->endOfDay()->toAtomString(), - 'budget_id' => (string) $budgetLimit->budget_id, - 'currency_id' => (string) $currencyId, + 'budget_id' => (string)$budgetLimit->budget_id, + 'currency_id' => (string)$currencyId, 'currency_code' => $currencyCode, 'currency_name' => $currencyName, 'currency_decimal_places' => $currencyDecimalPlaces, @@ -105,12 +112,4 @@ class BudgetLimitTransformer extends AbstractTransformer ], ]; } - - /** - * @inheritDoc - */ - public function collectMetaData(Collection $objects): void - { - // TODO: Implement collectMetaData() method. - } } diff --git a/app/Transformers/V2/BudgetTransformer.php b/app/Transformers/V2/BudgetTransformer.php index e9df826dba..80793dd5d0 100644 --- a/app/Transformers/V2/BudgetTransformer.php +++ b/app/Transformers/V2/BudgetTransformer.php @@ -44,13 +44,21 @@ class BudgetTransformer extends AbstractTransformer { //$this->opsRepository = app(OperationsRepositoryInterface::class); //$this->repository = app(BudgetRepositoryInterface::class); - $this->parameters = new ParameterBag(); + $this->parameters = new ParameterBag(); + } + + /** + * @inheritDoc + */ + public function collectMetaData(Collection $objects): void + { + // TODO: Implement collectMetaData() method. } /** * Transform a budget. * - * @param Budget $budget + * @param Budget $budget * * @return array */ @@ -86,7 +94,7 @@ class BudgetTransformer extends AbstractTransformer // } return [ - 'id' => (string) $budget->id, + 'id' => (string)$budget->id, 'created_at' => $budget->created_at->toAtomString(), 'updated_at' => $budget->updated_at->toAtomString(), 'active' => $budget->active, @@ -109,7 +117,7 @@ class BudgetTransformer extends AbstractTransformer } /** - * @param array $array + * @param array $array * * @return array */ @@ -117,18 +125,10 @@ class BudgetTransformer extends AbstractTransformer { $return = []; foreach ($array as $data) { - $data['sum'] = number_format((float) $data['sum'], (int) $data['currency_decimal_places'], '.', ''); + $data['sum'] = number_format((float)$data['sum'], (int)$data['currency_decimal_places'], '.', ''); $return[] = $data; } return $return; } - - /** - * @inheritDoc - */ - public function collectMetaData(Collection $objects): void - { - // TODO: Implement collectMetaData() method. - } } diff --git a/app/Transformers/V2/PreferenceTransformer.php b/app/Transformers/V2/PreferenceTransformer.php index cbf3501bf2..20e8fc1671 100644 --- a/app/Transformers/V2/PreferenceTransformer.php +++ b/app/Transformers/V2/PreferenceTransformer.php @@ -31,24 +31,6 @@ use Illuminate\Support\Collection; */ class PreferenceTransformer extends AbstractTransformer { - /** - * Transform the preference - * - * @param Preference $preference - * - * @return array - */ - public function transform(Preference $preference): array - { - return [ - 'id' => (int) $preference->id, - 'created_at' => $preference->created_at->toAtomString(), - 'updated_at' => $preference->updated_at->toAtomString(), - 'name' => $preference->name, - 'data' => $preference->data, - ]; - } - /** * @inheritDoc */ @@ -56,4 +38,22 @@ class PreferenceTransformer extends AbstractTransformer { // TODO: Implement collectMetaData() method. } + + /** + * Transform the preference + * + * @param Preference $preference + * + * @return array + */ + public function transform(Preference $preference): array + { + return [ + 'id' => (int)$preference->id, + 'created_at' => $preference->created_at->toAtomString(), + 'updated_at' => $preference->updated_at->toAtomString(), + 'name' => $preference->name, + 'data' => $preference->data, + ]; + } } diff --git a/app/Transformers/V2/TransactionGroupTransformer.php b/app/Transformers/V2/TransactionGroupTransformer.php index 830d995fc0..86aba03780 100644 --- a/app/Transformers/V2/TransactionGroupTransformer.php +++ b/app/Transformers/V2/TransactionGroupTransformer.php @@ -25,8 +25,6 @@ declare(strict_types=1); namespace FireflyIII\Transformers\V2; use Carbon\Carbon; -use FireflyIII\Factory\TransactionFactory; -use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionJournalMeta; use FireflyIII\Models\TransactionType; @@ -46,7 +44,42 @@ class TransactionGroupTransformer extends AbstractTransformer private array $meta; /** - * @param array $group + * @inheritDoc + */ + public function collectMetaData(Collection $objects): void + { + // start with currencies: + $currencies = []; + $journals = []; + /** @var array $object */ + foreach ($objects as $object) { + foreach ($object['sums'] as $sum) { + $id = $sum['currency_id']; + if (!array_key_exists($id, $currencies)) { + $currencyObject = TransactionCurrency::find($sum['currency_id']); + $currencies[$id] = $currencyObject; + } + } + /** @var array $transaction */ + foreach ($object['transactions'] as $transaction) { + $id = $transaction['transaction_journal_id']; + $journals[$id] = []; + } + } + $this->currencies = $currencies; + $this->default = app('amount')->getDefaultCurrency(); + + // grab meta for all journals: + $meta = TransactionJournalMeta::whereIn('transaction_journal_id', array_keys($journals))->get(); + /** @var TransactionJournalMeta $entry */ + foreach ($meta as $entry) { + $id = (int)$entry->transaction_journal_id; + $this->meta[$id][$entry->name] = $entry->data; + } + } + + /** + * @param array $group * * @return array */ @@ -54,10 +87,10 @@ class TransactionGroupTransformer extends AbstractTransformer { $first = reset($group['transactions']); return [ - 'id' => (string) $group['id'], + 'id' => (string)$group['id'], 'created_at' => $first['created_at']->toAtomString(), 'updated_at' => $first['updated_at']->toAtomString(), - 'user' => (string) $first['user_id'], + 'user' => (string)$first['user_id'], 'group_title' => $group['title'] ?? null, 'transactions' => $this->transformTransactions($group['transactions'] ?? []), 'links' => [ @@ -70,7 +103,7 @@ class TransactionGroupTransformer extends AbstractTransformer } /** - * @param array $transactions + * @param array $transactions * @return array */ private function transformTransactions(array $transactions): array @@ -86,10 +119,10 @@ class TransactionGroupTransformer extends AbstractTransformer private function transformTransaction(array $transaction): array { $transaction = new NullArrayObject($transaction); - $journalId = (int) $transaction['transaction_journal_id']; + $journalId = (int)$transaction['transaction_journal_id']; $meta = new NullArrayObject($this->meta[$journalId] ?? []); $type = $this->stringFromArray($transaction, 'transaction_type_type', TransactionType::WITHDRAWAL); - $amount = app('steam')->positive((string) ($transaction['amount'] ?? '0')); + $amount = app('steam')->positive((string)($transaction['amount'] ?? '0')); $foreignAmount = null; $nativeForeignAmount = null; if (null !== $transaction['foreign_amount']) { @@ -108,24 +141,24 @@ class TransactionGroupTransformer extends AbstractTransformer } return [ - 'user' => (string) $transaction['user_id'], - 'transaction_journal_id' => (string) $transaction['transaction_journal_id'], + 'user' => (string)$transaction['user_id'], + 'transaction_journal_id' => (string)$transaction['transaction_journal_id'], 'type' => strtolower($type), 'date' => $transaction['date']->toAtomString(), 'order' => $transaction['order'], - 'currency_id' => (string) $transaction['currency_id'], + 'currency_id' => (string)$transaction['currency_id'], 'currency_code' => $transaction['currency_code'], 'currency_name' => $transaction['currency_name'], 'currency_symbol' => $transaction['currency_symbol'], - 'currency_decimal_places' => (int) $transaction['currency_decimal_places'], + 'currency_decimal_places' => (int)$transaction['currency_decimal_places'], // converted to native currency 'native_currency_converted' => $transaction['currency_id'] !== $this->default->id, - 'native_currency_id' => (string) $this->default->id, + 'native_currency_id' => (string)$this->default->id, 'native_currency_code' => $this->default->code, 'native_currency_name' => $this->default->name, 'native_currency_symbol' => $this->default->symbol, - 'native_currency_decimal_places' => (int) $this->default->decimal_places, + 'native_currency_decimal_places' => (int)$this->default->decimal_places, 'foreign_currency_id' => $this->stringFromArray($transaction, 'foreign_currency_id', null), 'foreign_currency_code' => $transaction['foreign_currency_code'], @@ -141,11 +174,11 @@ class TransactionGroupTransformer extends AbstractTransformer 'foreign_amount' => $foreignAmount, 'native_foreign_amount' => $nativeForeignAmount, 'description' => $transaction['description'], - 'source_id' => (string) $transaction['source_account_id'], + 'source_id' => (string)$transaction['source_account_id'], 'source_name' => $transaction['source_account_name'], 'source_iban' => $transaction['source_account_iban'], 'source_type' => $transaction['source_account_type'], - 'destination_id' => (string) $transaction['destination_account_id'], + 'destination_id' => (string)$transaction['destination_account_id'], 'destination_name' => $transaction['destination_account_name'], 'destination_iban' => $transaction['destination_account_iban'], 'destination_type' => $transaction['destination_account_type'], @@ -197,9 +230,9 @@ class TransactionGroupTransformer extends AbstractTransformer /** * TODO also in the old transformer. * - * @param NullArrayObject $array - * @param string $key - * @param string|null $default + * @param NullArrayObject $array + * @param string $key + * @param string|null $default * * @return string|null */ @@ -209,7 +242,7 @@ class TransactionGroupTransformer extends AbstractTransformer return null; } if (null !== $array[$key]) { - return (string) $array[$key]; + return (string)$array[$key]; } if (null !== $default) { @@ -220,42 +253,7 @@ class TransactionGroupTransformer extends AbstractTransformer } /** - * @inheritDoc - */ - public function collectMetaData(Collection $objects): void - { - // start with currencies: - $currencies = []; - $journals = []; - /** @var array $object */ - foreach ($objects as $object) { - foreach ($object['sums'] as $sum) { - $id = $sum['currency_id']; - if (!array_key_exists($id, $currencies)) { - $currencyObject = TransactionCurrency::find($sum['currency_id']); - $currencies[$id] = $currencyObject; - } - } - /** @var array $transaction */ - foreach ($object['transactions'] as $transaction) { - $id = $transaction['transaction_journal_id']; - $journals[$id] = []; - } - } - $this->currencies = $currencies; - $this->default = app('amount')->getDefaultCurrency(); - - // grab meta for all journals: - $meta = TransactionJournalMeta::whereIn('transaction_journal_id', array_keys($journals))->get(); - /** @var TransactionJournalMeta $entry */ - foreach ($meta as $entry) { - $id = (int) $entry->transaction_journal_id; - $this->meta[$id][$entry->name] = $entry->data; - } - } - - /** - * @param string|null $string + * @param string|null $string * @return Carbon|null */ private function date(?string $string): ?Carbon diff --git a/app/Transformers/WebhookAttemptTransformer.php b/app/Transformers/WebhookAttemptTransformer.php index 3dceadb913..00fcb767d8 100644 --- a/app/Transformers/WebhookAttemptTransformer.php +++ b/app/Transformers/WebhookAttemptTransformer.php @@ -33,18 +33,18 @@ class WebhookAttemptTransformer extends AbstractTransformer /** * Transform the preference * - * @param WebhookAttempt $attempt + * @param WebhookAttempt $attempt * * @return array */ public function transform(WebhookAttempt $attempt): array { return [ - 'id' => (string) $attempt->id, + 'id' => (string)$attempt->id, 'created_at' => $attempt->created_at->toAtomString(), 'updated_at' => $attempt->updated_at->toAtomString(), - 'webhook_message_id' => (string) $attempt->webhook_message_id, - 'status_code' => (int) $attempt->status_code, + 'webhook_message_id' => (string)$attempt->webhook_message_id, + 'status_code' => (int)$attempt->status_code, 'logs' => $attempt->logs, 'response' => $attempt->response, ]; diff --git a/app/Transformers/WebhookMessageTransformer.php b/app/Transformers/WebhookMessageTransformer.php index e779665b7d..599738e2de 100644 --- a/app/Transformers/WebhookMessageTransformer.php +++ b/app/Transformers/WebhookMessageTransformer.php @@ -35,7 +35,7 @@ class WebhookMessageTransformer extends AbstractTransformer /** * Transform the preference * - * @param WebhookMessage $message + * @param WebhookMessage $message * * @return array */ @@ -49,12 +49,12 @@ class WebhookMessageTransformer extends AbstractTransformer } return [ - 'id' => (string) $message->id, + 'id' => (string)$message->id, 'created_at' => $message->created_at->toAtomString(), 'updated_at' => $message->updated_at->toAtomString(), 'sent' => $message->sent, 'errored' => $message->errored, - 'webhook_id' => (string) $message->webhook_id, + 'webhook_id' => (string)$message->webhook_id, 'uuid' => $message->uuid, 'message' => $json, ]; diff --git a/app/Transformers/WebhookTransformer.php b/app/Transformers/WebhookTransformer.php index add97a29c5..63bc4a8dfa 100644 --- a/app/Transformers/WebhookTransformer.php +++ b/app/Transformers/WebhookTransformer.php @@ -46,14 +46,14 @@ class WebhookTransformer extends AbstractTransformer /** * Transform webhook. * - * @param Webhook $webhook + * @param Webhook $webhook * * @return array */ public function transform(Webhook $webhook): array { return [ - 'id' => (int) $webhook->id, + 'id' => (int)$webhook->id, 'created_at' => $webhook->created_at->toAtomString(), 'updated_at' => $webhook->updated_at->toAtomString(), 'active' => $webhook->active, @@ -73,8 +73,8 @@ class WebhookTransformer extends AbstractTransformer } /** - * @param string $type - * @param int $value + * @param string $type + * @param int $value * @return string */ private function getEnum(string $type, int $value): string diff --git a/app/Validation/Account/DepositValidation.php b/app/Validation/Account/DepositValidation.php index 1746123286..917b80b0d4 100644 --- a/app/Validation/Account/DepositValidation.php +++ b/app/Validation/Account/DepositValidation.php @@ -33,22 +33,7 @@ use Log; trait DepositValidation { /** - * @param array $accountTypes - * - * @return bool - */ - abstract protected function canCreateTypes(array $accountTypes): bool; - - /** - * @param array $validTypes - * @param array $data - * - * @return Account|null - */ - abstract protected function findExistingAccount(array $validTypes, array $data): ?Account; - - /** - * @param array $array + * @param array $array * * @return bool */ @@ -65,7 +50,7 @@ trait DepositValidation if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) { // if both values are NULL we return false, // because the destination of a deposit can't be created. - $this->destError = (string) trans('validation.deposit_dest_need_data'); + $this->destError = (string)trans('validation.deposit_dest_need_data'); Log::error('Both values are NULL, cant create deposit destination.'); $result = false; } @@ -80,7 +65,7 @@ trait DepositValidation $search = $this->findExistingAccount($validTypes, $array); if (null === $search) { Log::debug('findExistingAccount() returned NULL, so the result is false.'); - $this->destError = (string) trans('validation.deposit_dest_bad_data', ['id' => $accountId, 'name' => $accountName]); + $this->destError = (string)trans('validation.deposit_dest_bad_data', ['id' => $accountId, 'name' => $accountName]); $result = false; } if (null !== $search) { @@ -96,7 +81,22 @@ trait DepositValidation } /** - * @param array $array + * @param array $accountTypes + * + * @return bool + */ + abstract protected function canCreateTypes(array $accountTypes): bool; + + /** + * @param array $validTypes + * @param array $data + * + * @return Account|null + */ + abstract protected function findExistingAccount(array $validTypes, array $data): ?Account; + + /** + * @param array $array * * @return bool */ @@ -114,7 +114,7 @@ trait DepositValidation // if both values are NULL return false, // because the source of a deposit can't be created. // (this never happens). - $this->sourceError = (string) trans('validation.deposit_source_need_data'); + $this->sourceError = (string)trans('validation.deposit_source_need_data'); $result = false; } diff --git a/app/Validation/Account/OBValidation.php b/app/Validation/Account/OBValidation.php index b422455eeb..bf58b9cee0 100644 --- a/app/Validation/Account/OBValidation.php +++ b/app/Validation/Account/OBValidation.php @@ -34,14 +34,7 @@ use Log; trait OBValidation { /** - * @param array $accountTypes - * - * @return bool - */ - abstract protected function canCreateTypes(array $accountTypes): bool; - - /** - * @param array $array + * @param array $array * * @return bool */ @@ -57,7 +50,7 @@ trait OBValidation if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) { // if both values are NULL we return false, // because the destination of a deposit can't be created. - $this->destError = (string) trans('validation.ob_dest_need_data'); + $this->destError = (string)trans('validation.ob_dest_need_data'); Log::error('Both values are NULL, cant create OB destination.'); $result = false; } @@ -72,7 +65,7 @@ trait OBValidation $search = $this->findExistingAccount($validTypes, $array); if (null === $search) { Log::debug('findExistingAccount() returned NULL, so the result is false.', $validTypes); - $this->destError = (string) trans('validation.ob_dest_bad_data', ['id' => $accountId, 'name' => $accountName]); + $this->destError = (string)trans('validation.ob_dest_bad_data', ['id' => $accountId, 'name' => $accountName]); $result = false; } if (null !== $search) { @@ -87,11 +80,18 @@ trait OBValidation return $result; } + /** + * @param array $accountTypes + * + * @return bool + */ + abstract protected function canCreateTypes(array $accountTypes): bool; + /** * Source of an opening balance can either be an asset account * or an "initial balance account". The latter can be created. * - * @param array $array + * @param array $array * * @return bool */ @@ -108,7 +108,7 @@ trait OBValidation // if both values are NULL return false, // because the source of a deposit can't be created. // (this never happens). - $this->sourceError = (string) trans('validation.ob_source_need_data'); + $this->sourceError = (string)trans('validation.ob_source_need_data'); $result = false; } diff --git a/app/Validation/Account/ReconciliationValidation.php b/app/Validation/Account/ReconciliationValidation.php index 6831a92648..f964a01585 100644 --- a/app/Validation/Account/ReconciliationValidation.php +++ b/app/Validation/Account/ReconciliationValidation.php @@ -25,7 +25,6 @@ declare(strict_types=1); namespace FireflyIII\Validation\Account; use FireflyIII\Models\Account; -use FireflyIII\Models\AccountType; use Log; /** @@ -37,7 +36,7 @@ trait ReconciliationValidation public ?Account $source; /** - * @param array $array + * @param array $array * * @return bool */ @@ -60,7 +59,7 @@ trait ReconciliationValidation $validTypes = array_keys($this->combinations[$this->transactionType]); $search = $this->findExistingAccount($validTypes, $array); if (null === $search) { - $this->sourceError = (string) trans('validation.reconciliation_source_bad_data', ['id' => $accountId, 'name' => $accountName]); + $this->sourceError = (string)trans('validation.reconciliation_source_bad_data', ['id' => $accountId, 'name' => $accountName]); app('log')->warning('Not a valid source. Cant find it.', $validTypes); return false; @@ -73,7 +72,7 @@ trait ReconciliationValidation /** * Basically the same check - * @param array $array + * @param array $array * * @return bool */ @@ -97,7 +96,7 @@ trait ReconciliationValidation $validTypes = array_keys($this->combinations[$this->transactionType]); $search = $this->findExistingAccount($validTypes, $array); if (null === $search) { - $this->sourceError = (string) trans('validation.reconciliation_source_bad_data', ['id' => $accountId, 'name' => $accountName]); + $this->sourceError = (string)trans('validation.reconciliation_source_bad_data', ['id' => $accountId, 'name' => $accountName]); app('log')->warning('Not a valid source. Cant find it.', $validTypes); return false; diff --git a/app/Validation/Account/TransferValidation.php b/app/Validation/Account/TransferValidation.php index 0c186dcb5a..9daa1c7bf4 100644 --- a/app/Validation/Account/TransferValidation.php +++ b/app/Validation/Account/TransferValidation.php @@ -32,22 +32,7 @@ use Log; trait TransferValidation { /** - * @param array $accountTypes - * - * @return bool - */ - abstract protected function canCreateTypes(array $accountTypes): bool; - - /** - * @param array $validTypes - * @param array $data - * - * @return Account|null - */ - abstract protected function findExistingAccount(array $validTypes, array $data): ?Account; - - /** - * @param array $array + * @param array $array * * @return bool */ @@ -61,7 +46,7 @@ trait TransferValidation if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) { // if both values are NULL we return false, // because the destination of a transfer can't be created. - $this->destError = (string) trans('validation.transfer_dest_need_data'); + $this->destError = (string)trans('validation.transfer_dest_need_data'); Log::error('Both values are NULL, cant create transfer destination.'); return false; @@ -70,7 +55,7 @@ trait TransferValidation // or try to find the account: $search = $this->findExistingAccount($validTypes, $array); if (null === $search) { - $this->destError = (string) trans('validation.transfer_dest_bad_data', ['id' => $accountId, 'name' => $accountName]); + $this->destError = (string)trans('validation.transfer_dest_bad_data', ['id' => $accountId, 'name' => $accountName]); return false; } @@ -88,7 +73,22 @@ trait TransferValidation } /** - * @param array $array + * @param array $accountTypes + * + * @return bool + */ + abstract protected function canCreateTypes(array $accountTypes): bool; + + /** + * @param array $validTypes + * @param array $data + * + * @return Account|null + */ + abstract protected function findExistingAccount(array $validTypes, array $data): ?Account; + + /** + * @param array $array * * @return bool */ @@ -102,7 +102,7 @@ trait TransferValidation if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) { // if both values are NULL we return false, // because the source of a withdrawal can't be created. - $this->sourceError = (string) trans('validation.transfer_source_need_data'); + $this->sourceError = (string)trans('validation.transfer_source_need_data'); app('log')->warning('Not a valid source, need more data.'); return false; @@ -111,7 +111,7 @@ trait TransferValidation // otherwise try to find the account: $search = $this->findExistingAccount($validTypes, $array); if (null === $search) { - $this->sourceError = (string) trans('validation.transfer_source_bad_data', ['id' => $accountId, 'name' => $accountName]); + $this->sourceError = (string)trans('validation.transfer_source_bad_data', ['id' => $accountId, 'name' => $accountName]); app('log')->warning('Not a valid source, cant find it.', $validTypes); return false; diff --git a/app/Validation/Account/WithdrawalValidation.php b/app/Validation/Account/WithdrawalValidation.php index de11ac8cf3..bb5d758f76 100644 --- a/app/Validation/Account/WithdrawalValidation.php +++ b/app/Validation/Account/WithdrawalValidation.php @@ -33,22 +33,7 @@ use Log; trait WithdrawalValidation { /** - * @param array $accountTypes - * - * @return bool - */ - abstract protected function canCreateTypes(array $accountTypes): bool; - - /** - * @param array $validTypes - * @param array $data - * - * @return Account|null - */ - abstract protected function findExistingAccount(array $validTypes, array $data): ?Account; - - /** - * @param array $array + * @param array $array * * @return bool */ @@ -62,7 +47,7 @@ trait WithdrawalValidation if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) { // if both values are NULL we return TRUE // because we assume the user doesnt want to submit / change anything. - $this->sourceError = (string) trans('validation.withdrawal_source_need_data'); + $this->sourceError = (string)trans('validation.withdrawal_source_need_data'); app('log')->warning('[a] Not a valid source. Need more data.'); return false; @@ -71,7 +56,7 @@ trait WithdrawalValidation // otherwise try to find the account: $search = $this->findExistingAccount($validTypes, $array); if (null === $search) { - $this->sourceError = (string) trans('validation.withdrawal_source_bad_data', ['id' => $accountId, 'name' => $accountName]); + $this->sourceError = (string)trans('validation.withdrawal_source_bad_data', ['id' => $accountId, 'name' => $accountName]); app('log')->warning('Not a valid source. Cant find it.', $validTypes); return false; @@ -83,7 +68,22 @@ trait WithdrawalValidation } /** - * @param array $array + * @param array $accountTypes + * + * @return bool + */ + abstract protected function canCreateTypes(array $accountTypes): bool; + + /** + * @param array $validTypes + * @param array $data + * + * @return Account|null + */ + abstract protected function findExistingAccount(array $validTypes, array $data): ?Account; + + /** + * @param array $array * * @return bool */ @@ -97,7 +97,7 @@ trait WithdrawalValidation if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) { // if both values are NULL return false, // because the destination of a withdrawal can never be created automatically. - $this->destError = (string) trans('validation.withdrawal_dest_need_data'); + $this->destError = (string)trans('validation.withdrawal_dest_need_data'); return false; } @@ -110,7 +110,7 @@ trait WithdrawalValidation if (in_array($type, $validTypes, true)) { return true; } - $this->destError = (string) trans('validation.withdrawal_dest_bad_data', ['id' => $accountId, 'name' => $accountName]); + $this->destError = (string)trans('validation.withdrawal_dest_bad_data', ['id' => $accountId, 'name' => $accountName]); return false; } @@ -121,7 +121,7 @@ trait WithdrawalValidation } /** - * @param array $array + * @param array $array * * @return bool */ @@ -136,7 +136,7 @@ trait WithdrawalValidation if (null === $accountId && null === $accountName && false === $this->canCreateTypes($validTypes)) { // if both values are NULL we return false, // because the source of a withdrawal can't be created. - $this->sourceError = (string) trans('validation.withdrawal_source_need_data'); + $this->sourceError = (string)trans('validation.withdrawal_source_need_data'); app('log')->warning('[b] Not a valid source. Need more data.'); return false; @@ -145,7 +145,7 @@ trait WithdrawalValidation // otherwise try to find the account: $search = $this->findExistingAccount($validTypes, $array); if (null === $search) { - $this->sourceError = (string) trans('validation.withdrawal_source_bad_data', ['id' => $accountId, 'name' => $accountName]); + $this->sourceError = (string)trans('validation.withdrawal_source_bad_data', ['id' => $accountId, 'name' => $accountName]); app('log')->warning('Not a valid source. Cant find it.', $validTypes); return false; diff --git a/app/Validation/AccountValidator.php b/app/Validation/AccountValidator.php index 803234c38e..a91ad2c261 100644 --- a/app/Validation/AccountValidator.php +++ b/app/Validation/AccountValidator.php @@ -83,7 +83,7 @@ class AccountValidator } /** - * @param string $transactionType + * @param string $transactionType */ public function setTransactionType(string $transactionType): void { @@ -92,7 +92,7 @@ class AccountValidator } /** - * @param User $user + * @param User $user */ public function setUser(User $user): void { @@ -101,7 +101,7 @@ class AccountValidator } /** - * @param array $array + * @param array $array * * @return bool */ @@ -146,7 +146,7 @@ class AccountValidator } /** - * @param array $array + * @param array $array * * @return bool */ @@ -184,7 +184,7 @@ class AccountValidator } /** - * @param array $accountTypes + * @param array $accountTypes * * @return bool */ @@ -205,7 +205,7 @@ class AccountValidator } /** - * @param string $accountType + * @param string $accountType * * @return bool */ @@ -220,8 +220,8 @@ class AccountValidator } /** - * @param array $validTypes - * @param array $data + * @param array $validTypes + * @param array $data * * @return Account|null */ @@ -242,7 +242,7 @@ class AccountValidator } // find by iban - if (null !== $accountIban && '' !== (string) $accountIban) { + if (null !== $accountIban && '' !== (string)$accountIban) { $first = $this->accountRepository->findByIbanNull($accountIban, $validTypes); if ((null !== $first) && in_array($first->accountType->type, $validTypes, true)) { return $first; @@ -250,7 +250,7 @@ class AccountValidator } // find by number - if (null !== $accountNumber && '' !== (string) $accountNumber) { + if (null !== $accountNumber && '' !== (string)$accountNumber) { $first = $this->accountRepository->findByAccountNumber($accountNumber, $validTypes); if ((null !== $first) && in_array($first->accountType->type, $validTypes, true)) { return $first; @@ -258,7 +258,7 @@ class AccountValidator } // find by name: - if ('' !== (string) $accountName) { + if ('' !== (string)$accountName) { return $this->accountRepository->findByName($accountName, $validTypes); } diff --git a/app/Validation/Api/Data/Bulk/ValidatesBulkTransactionQuery.php b/app/Validation/Api/Data/Bulk/ValidatesBulkTransactionQuery.php index ca083d63fb..35126c6359 100644 --- a/app/Validation/Api/Data/Bulk/ValidatesBulkTransactionQuery.php +++ b/app/Validation/Api/Data/Bulk/ValidatesBulkTransactionQuery.php @@ -34,7 +34,7 @@ use JsonException; trait ValidatesBulkTransactionQuery { /** - * @param Validator $validator + * @param Validator $validator * * @throws JsonException */ @@ -50,26 +50,26 @@ trait ValidatesBulkTransactionQuery // find both accounts, must be same type. // already validated: belongs to this user. $repository = app(AccountRepositoryInterface::class); - $source = $repository->find((int) $json['where']['account_id']); - $dest = $repository->find((int) $json['update']['account_id']); + $source = $repository->find((int)$json['where']['account_id']); + $dest = $repository->find((int)$json['update']['account_id']); if (null === $source) { - $validator->errors()->add('query', sprintf((string) trans('validation.invalid_query_data'), 'where', 'account_id')); + $validator->errors()->add('query', sprintf((string)trans('validation.invalid_query_data'), 'where', 'account_id')); return; } if (null === $dest) { - $validator->errors()->add('query', sprintf((string) trans('validation.invalid_query_data'), 'update', 'account_id')); + $validator->errors()->add('query', sprintf((string)trans('validation.invalid_query_data'), 'update', 'account_id')); return; } if ($source->accountType->type !== $dest->accountType->type) { - $validator->errors()->add('query', (string) trans('validation.invalid_query_account_type')); + $validator->errors()->add('query', (string)trans('validation.invalid_query_account_type')); return; } // must have same currency: if ($repository->getAccountCurrency($source)->id !== $repository->getAccountCurrency($dest)->id) { - $validator->errors()->add('query', (string) trans('validation.invalid_query_currency')); + $validator->errors()->add('query', (string)trans('validation.invalid_query_currency')); } } } diff --git a/app/Validation/AutoBudget/ValidatesAutoBudgetRequest.php b/app/Validation/AutoBudget/ValidatesAutoBudgetRequest.php index e45ffe0d39..f35ca252ae 100644 --- a/app/Validation/AutoBudget/ValidatesAutoBudgetRequest.php +++ b/app/Validation/AutoBudget/ValidatesAutoBudgetRequest.php @@ -31,7 +31,7 @@ use Illuminate\Validation\Validator; trait ValidatesAutoBudgetRequest { /** - * @param Validator $validator + * @param Validator $validator */ protected function validateAutoBudgetAmount(Validator $validator): void { @@ -39,36 +39,36 @@ trait ValidatesAutoBudgetRequest $type = $data['auto_budget_type'] ?? ''; $amount = array_key_exists('auto_budget_amount', $data) ? $data['auto_budget_amount'] : null; $period = array_key_exists('auto_budget_period', $data) ? $data['auto_budget_period'] : null; - $currencyId = array_key_exists('auto_budget_currency_id', $data) ? (int) $data['auto_budget_currency_id'] : null; + $currencyId = array_key_exists('auto_budget_currency_id', $data) ? (int)$data['auto_budget_currency_id'] : null; $currencyCode = array_key_exists('auto_budget_currency_code', $data) ? $data['auto_budget_currency_code'] : null; if (is_numeric($type)) { - $type = (int) $type; + $type = (int)$type; } if ('' === $type || 0 === $type) { return; } // basic float check: if (!is_numeric($amount)) { - $validator->errors()->add('auto_budget_amount', (string) trans('validation.amount_required_for_auto_budget')); + $validator->errors()->add('auto_budget_amount', (string)trans('validation.amount_required_for_auto_budget')); return; } if ('' === $amount) { - $validator->errors()->add('auto_budget_amount', (string) trans('validation.amount_required_for_auto_budget')); + $validator->errors()->add('auto_budget_amount', (string)trans('validation.amount_required_for_auto_budget')); } - if (1 !== bccomp((string) $amount, '0')) { - $validator->errors()->add('auto_budget_amount', (string) trans('validation.auto_budget_amount_positive')); + if (1 !== bccomp((string)$amount, '0')) { + $validator->errors()->add('auto_budget_amount', (string)trans('validation.auto_budget_amount_positive')); } if ('' === $period) { - $validator->errors()->add('auto_budget_period', (string) trans('validation.auto_budget_period_mandatory')); + $validator->errors()->add('auto_budget_period', (string)trans('validation.auto_budget_period_mandatory')); } if (null !== $currencyId && null !== $currencyCode && '' === $currencyCode && 0 === $currencyId) { - $validator->errors()->add('auto_budget_amount', (string) trans('validation.require_currency_info')); + $validator->errors()->add('auto_budget_amount', (string)trans('validation.require_currency_info')); } // too big amount if ((int)$amount > 268435456) { - $validator->errors()->add('auto_budget_amount', (string) trans('validation.amount_required_for_auto_budget')); + $validator->errors()->add('auto_budget_amount', (string)trans('validation.amount_required_for_auto_budget')); return; } } diff --git a/app/Validation/CurrencyValidation.php b/app/Validation/CurrencyValidation.php index 331103dc6e..42037adfd4 100644 --- a/app/Validation/CurrencyValidation.php +++ b/app/Validation/CurrencyValidation.php @@ -37,7 +37,7 @@ trait CurrencyValidation /** * If the transactions contain foreign amounts, there must also be foreign currency information. * - * @param Validator $validator + * @param Validator $validator */ protected function validateForeignCurrencyInformation(Validator $validator): void { @@ -55,8 +55,8 @@ trait CurrencyValidation && 0 !== bccomp('0', $transaction['foreign_amount']) ) { $validator->errors()->add( - 'transactions.' . $index . '.foreign_amount', - (string) trans('validation.require_currency_info') + 'transactions.'.$index.'.foreign_amount', + (string)trans('validation.require_currency_info') ); } // if the currency is present, then the amount must be present as well. @@ -66,15 +66,15 @@ trait CurrencyValidation $transaction )) { $validator->errors()->add( - 'transactions.' . $index . '.foreign_amount', - (string) trans('validation.require_currency_amount') + 'transactions.'.$index.'.foreign_amount', + (string)trans('validation.require_currency_amount') ); } } } /** - * @param Validator $validator + * @param Validator $validator * * @return array */ diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php index d075158734..0139c8ecdd 100644 --- a/app/Validation/FireflyValidator.php +++ b/app/Validation/FireflyValidator.php @@ -1,4 +1,5 @@ where('user_id', auth()->user()->id)->where($field, $value)->count(); @@ -100,8 +101,8 @@ class FireflyValidator extends Validator } /** - * @param mixed $attribute - * @param mixed $value + * @param mixed $attribute + * @param mixed $value * * @return bool */ @@ -120,8 +121,8 @@ class FireflyValidator extends Validator } /** - * @param mixed $attribute - * @param mixed $value + * @param mixed $attribute + * @param mixed $value * * @return bool */ @@ -188,13 +189,40 @@ class FireflyValidator extends Validator // replace characters outside of ASCI range. $value = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $value); $search = [' ', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; - $replace = ['', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', - '32', '33', '34', '35',]; + $replace = [ + '', + '10', + '11', + '12', + '13', + '14', + '15', + '16', + '17', + '18', + '19', + '20', + '21', + '22', + '23', + '24', + '25', + '26', + '27', + '28', + '29', + '30', + '31', + '32', + '33', + '34', + '35', + ]; // take $first = substr($value, 0, 4); $last = substr($value, 4); - $iban = $last . $first; + $iban = $last.$first; $iban = trim(str_replace($search, $replace, $iban)); if (0 === strlen($iban)) { return false; @@ -209,13 +237,13 @@ class FireflyValidator extends Validator return false; } - return 1 === (int) $checksum; + return 1 === (int)$checksum; } /** - * @param mixed $attribute - * @param mixed $value - * @param mixed $parameters + * @param mixed $attribute + * @param mixed $value + * @param mixed $parameters * * @return bool */ @@ -224,13 +252,13 @@ class FireflyValidator extends Validator /** @var mixed $compare */ $compare = $parameters[0] ?? '0'; - return bccomp((string) $value, (string) $compare) < 0; + return bccomp((string)$value, (string)$compare) < 0; } /** - * @param mixed $attribute - * @param mixed $value - * @param mixed $parameters + * @param mixed $attribute + * @param mixed $value + * @param mixed $parameters * * @return bool */ @@ -239,13 +267,13 @@ class FireflyValidator extends Validator /** @var mixed $compare */ $compare = $parameters[0] ?? '0'; - return bccomp((string) $value, (string) $compare) > 0; + return bccomp((string)$value, (string)$compare) > 0; } /** - * @param mixed $attribute - * @param mixed $value - * @param mixed $parameters + * @param mixed $attribute + * @param mixed $value + * @param mixed $parameters * * @return bool */ @@ -253,7 +281,7 @@ class FireflyValidator extends Validator { $field = $parameters[1] ?? 'id'; - if (0 === (int) $value) { + if (0 === (int)$value) { return true; } $count = DB::table($parameters[0])->where($field, $value)->count(); @@ -262,9 +290,9 @@ class FireflyValidator extends Validator } /** - * @param string $attribute + * @param string $attribute * - * @param string|null $value + * @param string|null $value * * @return bool */ @@ -273,7 +301,7 @@ class FireflyValidator extends Validator // first, get the index from this string: $value = $value ?? ''; $parts = explode('.', $attribute); - $index = (int) ($parts[1] ?? '0'); + $index = (int)($parts[1] ?? '0'); // get the name of the trigger from the data array: $actionType = $this->data['actions'][$index]['type'] ?? 'invalid'; @@ -306,8 +334,14 @@ class FireflyValidator extends Validator $repository = app(AccountRepositoryInterface::class); $account = $repository->findByName( $value, - [AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE, - AccountType::CREDITCARD] + [ + AccountType::DEFAULT, + AccountType::ASSET, + AccountType::LOAN, + AccountType::DEBT, + AccountType::MORTGAGE, + AccountType::CREDITCARD, + ] ); return null !== $account; @@ -328,8 +362,8 @@ class FireflyValidator extends Validator /** * $attribute has the format triggers.%d.value. * - * @param string $attribute - * @param string|null $value + * @param string $attribute + * @param string|null $value * * @return bool */ @@ -337,7 +371,7 @@ class FireflyValidator extends Validator { // first, get the index from this string: $parts = explode('.', $attribute); - $index = (int) ($parts[1] ?? '0'); + $index = (int)($parts[1] ?? '0'); // get the name of the trigger from the data array: $triggerType = $this->data['triggers'][$index]['type'] ?? 'invalid'; @@ -354,18 +388,35 @@ class FireflyValidator extends Validator } // these trigger types need a simple strlen check: - $length = ['source_account_starts', 'source_account_ends', 'source_account_is', 'source_account_contains', 'destination_account_starts', - 'destination_account_ends', - 'destination_account_is', 'destination_account_contains', 'description_starts', 'description_ends', 'description_contains', 'description_is', - 'category_is', - 'budget_is', 'tag_is', 'currency_is', 'notes_contain', 'notes_start', 'notes_end', 'notes_are',]; + $length = [ + 'source_account_starts', + 'source_account_ends', + 'source_account_is', + 'source_account_contains', + 'destination_account_starts', + 'destination_account_ends', + 'destination_account_is', + 'destination_account_contains', + 'description_starts', + 'description_ends', + 'description_contains', + 'description_is', + 'category_is', + 'budget_is', + 'tag_is', + 'currency_is', + 'notes_contain', + 'notes_start', + 'notes_end', + 'notes_are', + ]; if (in_array($triggerType, $length, true)) { return '' !== $value; } // check if it's an existing account. if (in_array($triggerType, ['destination_account_id', 'source_account_id'], true)) { - return is_numeric($value) && (int) $value > 0; + return is_numeric($value) && (int)$value > 0; } // check transaction type. @@ -392,8 +443,8 @@ class FireflyValidator extends Validator } /** - * @param mixed $attribute - * @param mixed $value + * @param mixed $attribute + * @param mixed $value * * @return bool */ @@ -401,7 +452,7 @@ class FireflyValidator extends Validator { $verify = false; if (array_key_exists('verify_password', $this->data)) { - $verify = 1 === (int) $this->data['verify_password']; + $verify = 1 === (int)$this->data['verify_password']; } if ($verify) { /** @var Verifier $service */ @@ -414,9 +465,9 @@ class FireflyValidator extends Validator } /** - * @param mixed $attribute - * @param mixed $value - * @param mixed $parameters + * @param mixed $attribute + * @param mixed $value + * @param mixed $parameters * * @return bool */ @@ -430,14 +481,14 @@ class FireflyValidator extends Validator return $this->validateByAccountTypeString($value, $parameters, $this->data['objectType']); } if (array_key_exists('type', $this->data)) { - return $this->validateByAccountTypeString($value, $parameters, (string) $this->data['type']); + return $this->validateByAccountTypeString($value, $parameters, (string)$this->data['type']); } if (array_key_exists('account_type_id', $this->data)) { return $this->validateByAccountTypeId($value, $parameters); } $parameterId = $parameters[0] ?? null; if (null !== $parameterId) { - return $this->validateByParameterId((int) $parameterId, $value); + return $this->validateByParameterId((int)$parameterId, $value); } if (array_key_exists('id', $this->data)) { return $this->validateByAccountId($value); @@ -471,23 +522,23 @@ class FireflyValidator extends Validator } /** - * @param string $value - * @param array $parameters - * @param string $type + * @param string $value + * @param array $parameters + * @param string $type * * @return bool */ private function validateByAccountTypeString(string $value, array $parameters, string $type): bool { /** @var array|null $search */ - $search = Config::get('firefly.accountTypeByIdentifier.' . $type); + $search = Config::get('firefly.accountTypeByIdentifier.'.$type); if (null === $search) { return false; } $accountTypes = AccountType::whereIn('type', $search)->get(); - $ignore = (int) ($parameters[0] ?? 0.0); + $ignore = (int)($parameters[0] ?? 0.0); $accountTypeIds = $accountTypes->pluck('id')->toArray(); /** @var Collection $set */ $set = auth()->user()->accounts()->whereIn('account_type_id', $accountTypeIds)->where('id', '!=', $ignore)->get(); @@ -501,15 +552,15 @@ class FireflyValidator extends Validator } /** - * @param mixed $value - * @param mixed $parameters + * @param mixed $value + * @param mixed $parameters * * @return bool */ private function validateByAccountTypeId($value, $parameters): bool { $type = AccountType::find($this->data['account_type_id'])->first(); - $ignore = (int) ($parameters[0] ?? 0.0); + $ignore = (int)($parameters[0] ?? 0.0); /** @var Collection $set */ $set = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get(); @@ -524,8 +575,8 @@ class FireflyValidator extends Validator } /** - * @param int $accountId - * @param mixed $value + * @param int $accountId + * @param mixed $value * * @return bool */ @@ -545,7 +596,7 @@ class FireflyValidator extends Validator } /** - * @param mixed $value + * @param mixed $value * * @return bool */ @@ -565,7 +616,7 @@ class FireflyValidator extends Validator } /** - * @param string $value + * @param string $value * * @return bool */ @@ -575,17 +626,17 @@ class FireflyValidator extends Validator } /** - * @param mixed $attribute - * @param mixed $value - * @param mixed $parameters + * @param mixed $attribute + * @param mixed $value + * @param mixed $parameters * * @return bool */ public function validateUniqueAccountNumberForUser($attribute, $value, $parameters): bool { - $accountId = (int) ($this->data['id'] ?? 0.0); + $accountId = (int)($this->data['id'] ?? 0.0); if (0 === $accountId) { - $accountId = (int) ($parameters[0] ?? 0.0); + $accountId = (int)($parameters[0] ?? 0.0); } $query = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id') @@ -617,7 +668,7 @@ class FireflyValidator extends Validator /** @var AccountMeta $entry */ foreach ($set as $entry) { $otherAccount = $entry->account; - $otherType = (string) config(sprintf('firefly.shortNamesByFullName.%s', $otherAccount->accountType->type)); + $otherType = (string)config(sprintf('firefly.shortNamesByFullName.%s', $otherAccount->accountType->type)); if (('expense' === $otherType || 'revenue' === $otherType) && $otherType !== $type) { Log::debug(sprintf('The other account with this account number is a "%s" so return true.', $otherType)); return true; @@ -634,23 +685,13 @@ class FireflyValidator extends Validator */ public function validateUniqueCurrencyCode($attribute, $value): bool { - return $this->validateUniqueCurrency('code', (string) $attribute, (string) $value); + return $this->validateUniqueCurrency('code', (string)$attribute, (string)$value); } /** - * @param $attribute - * @param $value - * @return bool - */ - public function validateUniqueCurrencyName($attribute, $value): bool - { - return $this->validateUniqueCurrency('name', (string) $attribute, (string) $value); - } - - /** - * @param string $field - * @param string $attribute - * @param string $value + * @param string $field + * @param string $attribute + * @param string $value * @return bool */ public function validateUniqueCurrency(string $field, string $attribute, string $value): bool @@ -663,21 +704,31 @@ class FireflyValidator extends Validator * @param $value * @return bool */ - public function validateUniqueCurrencySymbol($attribute, $value): bool + public function validateUniqueCurrencyName($attribute, $value): bool { - return $this->validateUniqueCurrency('symbol', (string) $attribute, (string) $value); + return $this->validateUniqueCurrency('name', (string)$attribute, (string)$value); } /** - * @param mixed $value - * @param mixed $parameters - * @param mixed $something + * @param $attribute + * @param $value + * @return bool + */ + public function validateUniqueCurrencySymbol($attribute, $value): bool + { + return $this->validateUniqueCurrency('symbol', (string)$attribute, (string)$value); + } + + /** + * @param mixed $value + * @param mixed $parameters + * @param mixed $something * * @return bool */ public function validateUniqueExistingWebhook($value, $parameters, $something): bool { - $existingId = (int) ($something[0] ?? 0); + $existingId = (int)($something[0] ?? 0); $trigger = 0; $response = 0; $delivery = 0; @@ -724,24 +775,24 @@ class FireflyValidator extends Validator * parameter 1: the field * parameter 2: an id to ignore (when editing) * - * @param mixed $attribute - * @param mixed $value - * @param mixed $parameters + * @param mixed $attribute + * @param mixed $value + * @param mixed $parameters * * @return bool */ public function validateUniqueObjectForUser($attribute, $value, $parameters): bool { [$table, $field] = $parameters; - $exclude = (int) ($parameters[2] ?? 0.0); + $exclude = (int)($parameters[2] ?? 0.0); /* * If other data (in $this->getData()) contains * ID field, set that field to be the $exclude. */ $data = $this->getData(); - if (!array_key_exists(2, $parameters) && array_key_exists('id', $data) && (int) $data['id'] > 0) { - $exclude = (int) $data['id']; + if (!array_key_exists(2, $parameters) && array_key_exists('id', $data) && (int)$data['id'] > 0) { + $exclude = (int)$data['id']; } // get entries from table $set = DB::table($table)->where('user_id', auth()->user()->id)->whereNull('deleted_at') @@ -759,9 +810,9 @@ class FireflyValidator extends Validator } /** - * @param mixed $attribute - * @param mixed $value - * @param mixed $parameters + * @param mixed $attribute + * @param mixed $value + * @param mixed $parameters * * @return bool */ @@ -773,16 +824,16 @@ class FireflyValidator extends Validator ->where('object_groups.user_id', auth()->user()->id) ->where('object_groups.title', $value); if (null !== $exclude) { - $query->where('object_groups.id', '!=', (int) $exclude); + $query->where('object_groups.id', '!=', (int)$exclude); } return 0 === $query->count(); } /** - * @param mixed $attribute - * @param mixed $value - * @param mixed $parameters + * @param mixed $attribute + * @param mixed $value + * @param mixed $parameters * * @return bool */ @@ -792,7 +843,7 @@ class FireflyValidator extends Validator $query = DB::table('piggy_banks')->whereNull('piggy_banks.deleted_at') ->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', auth()->user()->id); if (null !== $exclude) { - $query->where('piggy_banks.id', '!=', (int) $exclude); + $query->where('piggy_banks.id', '!=', (int)$exclude); } $query->where('piggy_banks.name', $value); @@ -800,8 +851,8 @@ class FireflyValidator extends Validator } /** - * @param mixed $value - * @param mixed $parameters + * @param mixed $value + * @param mixed $parameters * * @return bool */ diff --git a/app/Validation/GroupValidation.php b/app/Validation/GroupValidation.php index c7b63bbcff..eede3b3b91 100644 --- a/app/Validation/GroupValidation.php +++ b/app/Validation/GroupValidation.php @@ -36,25 +36,27 @@ use Log; trait GroupValidation { /** - * @param Validator $validator - * - * @return array - */ - abstract protected function getTransactionsArray(Validator $validator): array; - - /** - * @param Validator $validator + * @param Validator $validator */ protected function preventNoAccountInfo(Validator $validator): void { $transactions = $this->getTransactionsArray($validator); - $keys = ['source_id', 'destination_id', 'source_name', 'destination_name', 'source_iban', 'destination_iban', 'source_number', 'destination_number']; + $keys = [ + 'source_id', + 'destination_id', + 'source_name', + 'destination_name', + 'source_iban', + 'destination_iban', + 'source_number', + 'destination_number', + ]; /** @var array $transaction */ foreach ($transactions as $index => $transaction) { $hasAccountInfo = false; $hasJournalId = array_key_exists('transaction_journal_id', $transaction); foreach ($keys as $key) { - if (array_key_exists($key, $transaction) && '' !== (string) $transaction[$key]) { + if (array_key_exists($key, $transaction) && '' !== (string)$transaction[$key]) { $hasAccountInfo = true; } } @@ -62,23 +64,29 @@ trait GroupValidation if (false === $hasAccountInfo && !$hasJournalId) { $validator->errors()->add( sprintf('transactions.%d.source_id', $index), - (string) trans('validation.generic_no_source') + (string)trans('validation.generic_no_source') ); $validator->errors()->add( sprintf('transactions.%d.destination_id', $index), - (string) trans('validation.generic_no_destination') + (string)trans('validation.generic_no_destination') ); } } - // only an issue if there is no transaction_journal_id } + /** + * @param Validator $validator + * + * @return array + */ + abstract protected function getTransactionsArray(Validator $validator): array; + /** * Adds an error to the "description" field when the user has submitted no descriptions and no * journal description. * - * @param Validator $validator + * @param Validator $validator */ protected function validateDescriptions(Validator $validator): void { @@ -86,7 +94,7 @@ trait GroupValidation $transactions = $this->getTransactionsArray($validator); $validDescriptions = 0; foreach ($transactions as $transaction) { - if ('' !== (string) ($transaction['description'] ?? null)) { + if ('' !== (string)($transaction['description'] ?? null)) { $validDescriptions++; } } @@ -95,13 +103,13 @@ trait GroupValidation if (0 === $validDescriptions) { $validator->errors()->add( 'transactions.0.description', - (string) trans('validation.filled', ['attribute' => (string) trans('validation.attributes.description')]) + (string)trans('validation.filled', ['attribute' => (string)trans('validation.attributes.description')]) ); } } /** - * @param Validator $validator + * @param Validator $validator */ protected function validateGroupDescription(Validator $validator): void { @@ -111,7 +119,7 @@ trait GroupValidation $groupTitle = $data['group_title'] ?? ''; if ('' === $groupTitle && count($transactions) > 1) { - $validator->errors()->add('group_title', (string) trans('validation.group_title_mandatory')); + $validator->errors()->add('group_title', (string)trans('validation.group_title_mandatory')); } } @@ -119,8 +127,8 @@ trait GroupValidation * This method validates if the user has submitted transaction journal ID's for each array they submit, if they've submitted more than 1 transaction * journal. This check is necessary because Firefly III isn't able to distinguish between journals without the ID. * - * @param Validator $validator - * @param TransactionGroup $transactionGroup + * @param Validator $validator + * @param TransactionGroup $transactionGroup */ protected function validateJournalIds(Validator $validator, TransactionGroup $transactionGroup): void { @@ -135,7 +143,7 @@ trait GroupValidation } // check each array: /** - * @var int $index + * @var int $index * @var array $transaction */ foreach ($transactions as $index => $transaction) { @@ -146,10 +154,10 @@ trait GroupValidation /** * Do the validation required by validateJournalIds. * - * @param Validator $validator - * @param int $index - * @param array $transaction - * @param TransactionGroup $transactionGroup + * @param Validator $validator + * @param int $index + * @param array $transaction + * @param TransactionGroup $transactionGroup * * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ @@ -169,7 +177,7 @@ trait GroupValidation if (null === $journalId || 0 === $count) { app('log')->warning(sprintf('Transaction group #%d has %d journals with ID %d', $transactionGroup->id, $count, $journalId)); app('log')->warning('Invalid submission: Each split must have transaction_journal_id (either valid ID or 0).'); - $validator->errors()->add(sprintf('transactions.%d.source_name', $index), (string) trans('validation.need_id_in_edit')); + $validator->errors()->add(sprintf('transactions.%d.source_name', $index), (string)trans('validation.need_id_in_edit')); } } } diff --git a/app/Validation/RecurrenceValidation.php b/app/Validation/RecurrenceValidation.php index 271f68ea04..81b437fac1 100644 --- a/app/Validation/RecurrenceValidation.php +++ b/app/Validation/RecurrenceValidation.php @@ -43,7 +43,7 @@ trait RecurrenceValidation * * TODO Must always trigger when the type of the recurrence changes. * - * @param Validator $validator + * @param Validator $validator */ public function valUpdateAccountInfo(Validator $validator): void { @@ -91,7 +91,7 @@ trait RecurrenceValidation continue; } // validate source account. - $sourceId = array_key_exists('source_id', $transaction) ? (int) $transaction['source_id'] : null; + $sourceId = array_key_exists('source_id', $transaction) ? (int)$transaction['source_id'] : null; $sourceName = $transaction['source_name'] ?? null; $validSource = $accountValidator->validateSource(['id' => $sourceId, 'name' => $sourceName]); @@ -103,7 +103,7 @@ trait RecurrenceValidation return; } // validate destination account - $destinationId = array_key_exists('destination_id', $transaction) ? (int) $transaction['destination_id'] : null; + $destinationId = array_key_exists('destination_id', $transaction) ? (int)$transaction['destination_id'] : null; $destinationName = $transaction['destination_name'] ?? null; $validDestination = $accountValidator->validateDestination(['id' => $destinationId, 'name' => $destinationName,]); // do something with result: @@ -119,7 +119,7 @@ trait RecurrenceValidation /** * Adds an error to the validator when there are no repetitions in the array of data. * - * @param Validator $validator + * @param Validator $validator */ public function validateOneRepetition(Validator $validator): void { @@ -127,14 +127,14 @@ trait RecurrenceValidation $repetitions = $data['repetitions'] ?? []; // need at least one transaction if (!is_countable($repetitions) || 0 === count($repetitions)) { - $validator->errors()->add('repetitions', (string) trans('validation.at_least_one_repetition')); + $validator->errors()->add('repetitions', (string)trans('validation.at_least_one_repetition')); } } /** * Adds an error to the validator when there are no repetitions in the array of data. * - * @param Validator $validator + * @param Validator $validator */ public function validateOneRepetitionUpdate(Validator $validator): void { @@ -145,7 +145,7 @@ trait RecurrenceValidation } // need at least one transaction if (0 === count($repetitions)) { - $validator->errors()->add('repetitions', (string) trans('validation.at_least_one_repetition')); + $validator->errors()->add('repetitions', (string)trans('validation.at_least_one_repetition')); } } @@ -153,7 +153,7 @@ trait RecurrenceValidation * Validates that the recurrence has valid repetition information. It either doesn't stop, * or stops after X times or at X date. Not both of them., * - * @param Validator $validator + * @param Validator $validator */ public function validateRecurrenceRepetition(Validator $validator): void { @@ -162,15 +162,15 @@ trait RecurrenceValidation $repeatUntil = $data['repeat_until'] ?? null; if (null !== $repetitions && null !== $repeatUntil) { // expect a date OR count: - $validator->errors()->add('repeat_until', (string) trans('validation.require_repeat_until')); - $validator->errors()->add('nr_of_repetitions', (string) trans('validation.require_repeat_until')); + $validator->errors()->add('repeat_until', (string)trans('validation.require_repeat_until')); + $validator->errors()->add('nr_of_repetitions', (string)trans('validation.require_repeat_until')); } } public function validateRecurringConfig(Validator $validator) { $data = $validator->getData(); - $reps = array_key_exists('nr_of_repetitions', $data) ? (int) $data['nr_of_repetitions'] : null; + $reps = array_key_exists('nr_of_repetitions', $data) ? (int)$data['nr_of_repetitions'] : null; $repeatUntil = array_key_exists('repeat_until', $data) ? new Carbon($data['repeat_until']) : null; if (null === $reps && null === $repeatUntil) { @@ -186,19 +186,19 @@ trait RecurrenceValidation } /** - * @param Validator $validator + * @param Validator $validator */ public function validateRepetitionMoment(Validator $validator): void { $data = $validator->getData(); $repetitions = $data['repetitions'] ?? []; if (!is_array($repetitions)) { - $validator->errors()->add(sprintf('repetitions.%d.type', 0), (string) trans('validation.valid_recurrence_rep_type')); + $validator->errors()->add(sprintf('repetitions.%d.type', 0), (string)trans('validation.valid_recurrence_rep_type')); return; } /** - * @var int $index + * @var int $index * @var array $repetition */ foreach ($repetitions as $index => $repetition) { @@ -211,23 +211,23 @@ trait RecurrenceValidation $repetition['moment'] = $repetition['moment'] ?? 'invalid'; switch ($repetition['type'] ?? 'empty') { default: - $validator->errors()->add(sprintf('repetitions.%d.type', $index), (string) trans('validation.valid_recurrence_rep_type')); + $validator->errors()->add(sprintf('repetitions.%d.type', $index), (string)trans('validation.valid_recurrence_rep_type')); return; case 'daily': - $this->validateDaily($validator, $index, (string) $repetition['moment']); + $this->validateDaily($validator, $index, (string)$repetition['moment']); break; case 'monthly': - $this->validateMonthly($validator, $index, (int) $repetition['moment']); + $this->validateMonthly($validator, $index, (int)$repetition['moment']); break; case 'ndom': - $this->validateNdom($validator, $index, (string) $repetition['moment']); + $this->validateNdom($validator, $index, (string)$repetition['moment']); break; case 'weekly': - $this->validateWeekly($validator, $index, (int) $repetition['moment']); + $this->validateWeekly($validator, $index, (int)$repetition['moment']); break; case 'yearly': - $this->validateYearly($validator, $index, (string) $repetition['moment']); + $this->validateYearly($validator, $index, (string)$repetition['moment']); break; } } @@ -236,28 +236,28 @@ trait RecurrenceValidation /** * If the repetition type is daily, the moment should be empty. * - * @param Validator $validator - * @param int $index - * @param string $moment + * @param Validator $validator + * @param int $index + * @param string $moment */ protected function validateDaily(Validator $validator, int $index, string $moment): void { if ('' !== $moment) { - $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment')); + $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment')); } } /** * If the repetition type is monthly, the moment should be a day between 1-31 (inclusive). * - * @param Validator $validator - * @param int $index - * @param int $dayOfMonth + * @param Validator $validator + * @param int $index + * @param int $dayOfMonth */ protected function validateMonthly(Validator $validator, int $index, int $dayOfMonth): void { if ($dayOfMonth < 1 || $dayOfMonth > 31) { - $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment')); + $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment')); } } @@ -265,50 +265,50 @@ trait RecurrenceValidation * If the repetition type is "ndom", the first part must be between 1-5 (inclusive), for the week in the month, * and the second one must be between 1-7 (inclusive) for the day of the week. * - * @param Validator $validator - * @param int $index - * @param string $moment + * @param Validator $validator + * @param int $index + * @param string $moment */ protected function validateNdom(Validator $validator, int $index, string $moment): void { $parameters = explode(',', $moment); if (2 !== count($parameters)) { - $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment')); + $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment')); return; } - $nthDay = (int) ($parameters[0] ?? 0.0); - $dayOfWeek = (int) ($parameters[1] ?? 0.0); + $nthDay = (int)($parameters[0] ?? 0.0); + $dayOfWeek = (int)($parameters[1] ?? 0.0); if ($nthDay < 1 || $nthDay > 5) { - $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment')); + $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment')); return; } if ($dayOfWeek < 1 || $dayOfWeek > 7) { - $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment')); + $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment')); } } /** * If the repetition type is weekly, the moment should be a day between 1-7 (inclusive). * - * @param Validator $validator - * @param int $index - * @param int $dayOfWeek + * @param Validator $validator + * @param int $index + * @param int $dayOfWeek */ protected function validateWeekly(Validator $validator, int $index, int $dayOfWeek): void { if ($dayOfWeek < 1 || $dayOfWeek > 7) { - $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment')); + $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment')); } } /** * If the repetition type is yearly, the moment should be a valid date. * - * @param Validator $validator - * @param int $index - * @param string $moment + * @param Validator $validator + * @param int $index + * @param string $moment */ protected function validateYearly(Validator $validator, int $index, string $moment): void { @@ -316,7 +316,7 @@ trait RecurrenceValidation Carbon::createFromFormat('Y-m-d', $moment); } catch (InvalidArgumentException $e) { Log::debug(sprintf('Invalid argument for Carbon: %s', $e->getMessage())); - $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string) trans('validation.valid_recurrence_rep_moment')); + $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment')); } } } diff --git a/app/Validation/TransactionValidation.php b/app/Validation/TransactionValidation.php index 0122fdfb6f..0c5dcfb61e 100644 --- a/app/Validation/TransactionValidation.php +++ b/app/Validation/TransactionValidation.php @@ -39,7 +39,7 @@ trait TransactionValidation /** * Validates the given account information. Switches on given transaction type. * - * @param Validator $validator + * @param Validator $validator */ public function validateAccountInformation(Validator $validator): void { @@ -51,7 +51,7 @@ trait TransactionValidation Log::debug(sprintf('Going to loop %d transaction(s)', count($transactions))); /** - * @var int $index + * @var int $index * @var array $transaction */ foreach ($transactions as $index => $transaction) { @@ -63,7 +63,7 @@ trait TransactionValidation } /** - * @param Validator $validator + * @param Validator $validator * * @return array */ @@ -87,10 +87,10 @@ trait TransactionValidation } /** - * @param Validator $validator - * @param int $index - * @param string $transactionType - * @param array $transaction + * @param Validator $validator + * @param int $index + * @param string $transactionType + * @param array $transaction */ protected function validateSingleAccount(Validator $validator, int $index, string $transactionType, array $transaction): void { @@ -101,10 +101,10 @@ trait TransactionValidation $accountValidator->setTransactionType($transactionType); // validate source account. - $sourceId = array_key_exists('source_id', $transaction) ? (int) $transaction['source_id'] : null; - $sourceName = array_key_exists('source_name', $transaction) ? (string) $transaction['source_name'] : null; - $sourceIban = array_key_exists('source_iban', $transaction) ? (string) $transaction['source_iban'] : null; - $sourceNumber = array_key_exists('source_number', $transaction) ? (string) $transaction['source_number'] : null; + $sourceId = array_key_exists('source_id', $transaction) ? (int)$transaction['source_id'] : null; + $sourceName = array_key_exists('source_name', $transaction) ? (string)$transaction['source_name'] : null; + $sourceIban = array_key_exists('source_iban', $transaction) ? (string)$transaction['source_iban'] : null; + $sourceNumber = array_key_exists('source_number', $transaction) ? (string)$transaction['source_number'] : null; $source = [ 'id' => $sourceId, 'name' => $sourceName, @@ -121,10 +121,10 @@ trait TransactionValidation return; } // validate destination account - $destinationId = array_key_exists('destination_id', $transaction) ? (int) $transaction['destination_id'] : null; - $destinationName = array_key_exists('destination_name', $transaction) ? (string) $transaction['destination_name'] : null; - $destinationIban = array_key_exists('destination_iban', $transaction) ? (string) $transaction['destination_iban'] : null; - $destinationNumber = array_key_exists('destination_number', $transaction) ? (string) $transaction['destination_number'] : null; + $destinationId = array_key_exists('destination_id', $transaction) ? (int)$transaction['destination_id'] : null; + $destinationName = array_key_exists('destination_name', $transaction) ? (string)$transaction['destination_name'] : null; + $destinationIban = array_key_exists('destination_iban', $transaction) ? (string)$transaction['destination_iban'] : null; + $destinationNumber = array_key_exists('destination_number', $transaction) ? (string)$transaction['destination_number'] : null; $destination = [ 'id' => $destinationId, 'name' => $destinationName, @@ -143,11 +143,11 @@ trait TransactionValidation } /** - * @param Validator $validator - * @param string $transactionType - * @param int $index - * @param array $source - * @param array $destination + * @param Validator $validator + * @param string $transactionType + * @param int $index + * @param array $source + * @param array $destination * @return void */ protected function sanityCheckReconciliation(Validator $validator, string $transactionType, int $index, array $source, array $destination): void @@ -177,8 +177,8 @@ trait TransactionValidation /** * Validates the given account information. Switches on given transaction type. * - * @param Validator $validator - * @param TransactionGroup $transactionGroup + * @param Validator $validator + * @param TransactionGroup $transactionGroup */ public function validateAccountInformationUpdate(Validator $validator, TransactionGroup $transactionGroup): void { @@ -186,7 +186,7 @@ trait TransactionValidation $transactions = $this->getTransactionsArray($validator); /** - * @var int $index + * @var int $index * @var array $transaction */ foreach ($transactions as $index => $transaction) { @@ -195,10 +195,10 @@ trait TransactionValidation } /** - * @param Validator $validator - * @param int $index - * @param array $transaction - * @param TransactionGroup $transactionGroup + * @param Validator $validator + * @param int $index + * @param array $transaction + * @param TransactionGroup $transactionGroup */ protected function validateSingleUpdate(Validator $validator, int $index, array $transaction, TransactionGroup $transactionGroup): void { @@ -224,7 +224,7 @@ trait TransactionValidation // validate if the submitted source and / or name are valid if (array_key_exists('source_id', $transaction) || array_key_exists('source_name', $transaction)) { Log::debug('Will try to validate source account information.'); - $sourceId = (int) ($transaction['source_id'] ?? 0); + $sourceId = (int)($transaction['source_id'] ?? 0); $sourceName = $transaction['source_name'] ?? null; $validSource = $accountValidator->validateSource(['id' => $sourceId, 'name' => $sourceName]); @@ -252,7 +252,7 @@ trait TransactionValidation $accountValidator->source = $source; } } - $destinationId = (int) ($transaction['destination_id'] ?? 0); + $destinationId = (int)($transaction['destination_id'] ?? 0); $destinationName = $transaction['destination_name'] ?? null; $array = ['id' => $destinationId, 'name' => $destinationName,]; $validDestination = $accountValidator->validateDestination($array); @@ -268,8 +268,8 @@ trait TransactionValidation } /** - * @param TransactionGroup $group - * @param array $transactions + * @param TransactionGroup $group + * @param array $transactions * * @return string */ @@ -279,8 +279,8 @@ trait TransactionValidation } /** - * @param array $transaction - * @param TransactionGroup $transactionGroup + * @param array $transaction + * @param TransactionGroup $transactionGroup * * @return Account|null */ @@ -293,7 +293,7 @@ trait TransactionValidation } /** @var TransactionJournal $journal */ foreach ($transactionGroup->transactionJournals as $journal) { - if ((int) $journal->id === (int) $transaction['transaction_journal_id']) { + if ((int)$journal->id === (int)$transaction['transaction_journal_id']) { return $journal->transactions()->where('amount', '<', 0)->first()->account; } } @@ -304,7 +304,7 @@ trait TransactionValidation /** * Adds an error to the validator when there are no transactions in the array of data. * - * @param Validator $validator + * @param Validator $validator */ public function validateOneRecurrenceTransaction(Validator $validator): void { @@ -313,14 +313,14 @@ trait TransactionValidation // need at least one transaction if (0 === count($transactions)) { - $validator->errors()->add('transactions', (string) trans('validation.at_least_one_transaction')); + $validator->errors()->add('transactions', (string)trans('validation.at_least_one_transaction')); } } /** * Adds an error to the validator when there are no transactions in the array of data. * - * @param Validator $validator + * @param Validator $validator */ public function validateOneTransaction(Validator $validator): void { @@ -328,7 +328,7 @@ trait TransactionValidation $transactions = $this->getTransactionsArray($validator); // need at least one transaction if (0 === count($transactions)) { - $validator->errors()->add('transactions.0.description', (string) trans('validation.at_least_one_transaction')); + $validator->errors()->add('transactions.0.description', (string)trans('validation.at_least_one_transaction')); Log::debug('Added error: at_least_one_transaction.'); return; @@ -337,14 +337,14 @@ trait TransactionValidation } /** - * @param Validator $validator + * @param Validator $validator */ public function validateTransactionArray(Validator $validator): void { $transactions = $this->getTransactionsArray($validator); foreach ($transactions as $key => $value) { if (!is_int($key)) { - $validator->errors()->add('transactions.0.description', (string) trans('validation.at_least_one_transaction')); + $validator->errors()->add('transactions.0.description', (string)trans('validation.at_least_one_transaction')); Log::debug('Added error: at_least_one_transaction.'); return; @@ -355,7 +355,7 @@ trait TransactionValidation /** * All types of splits must be equal. * - * @param Validator $validator + * @param Validator $validator */ public function validateTransactionTypes(Validator $validator): void { @@ -368,20 +368,20 @@ trait TransactionValidation } $unique = array_unique($types); if (count($unique) > 1) { - $validator->errors()->add('transactions.0.type', (string) trans('validation.transaction_types_equal')); + $validator->errors()->add('transactions.0.type', (string)trans('validation.transaction_types_equal')); return; } $first = $unique[0] ?? 'invalid'; if ('invalid' === $first) { - $validator->errors()->add('transactions.0.type', (string) trans('validation.invalid_transaction_type')); + $validator->errors()->add('transactions.0.type', (string)trans('validation.invalid_transaction_type')); } } /** * All types of splits must be equal. * - * @param Validator $validator + * @param Validator $validator */ public function validateTransactionTypesForUpdate(Validator $validator): void { @@ -389,14 +389,14 @@ trait TransactionValidation $transactions = $this->getTransactionsArray($validator); $types = []; foreach ($transactions as $transaction) { - $originalType = $this->getOriginalType((int) ($transaction['transaction_journal_id'] ?? 0)); + $originalType = $this->getOriginalType((int)($transaction['transaction_journal_id'] ?? 0)); // if type is not set, fall back to the type of the journal, if one is given. $types[] = $transaction['type'] ?? $originalType; } $unique = array_unique($types); if (count($unique) > 1) { app('log')->warning('Add error for mismatch transaction types.'); - $validator->errors()->add('transactions.0.type', (string) trans('validation.transaction_types_equal')); + $validator->errors()->add('transactions.0.type', (string)trans('validation.transaction_types_equal')); return; } @@ -404,7 +404,7 @@ trait TransactionValidation } /** - * @param int $journalId + * @param int $journalId * * @return string */ @@ -423,7 +423,7 @@ trait TransactionValidation } /** - * @param Validator $validator + * @param Validator $validator */ private function validateEqualAccounts(Validator $validator): void { @@ -447,26 +447,26 @@ trait TransactionValidation default: case 'withdrawal': if (count($sources) > 1) { - $validator->errors()->add('transactions.0.source_id', (string) trans('validation.all_accounts_equal')); + $validator->errors()->add('transactions.0.source_id', (string)trans('validation.all_accounts_equal')); } break; case 'deposit': if (count($dests) > 1) { - $validator->errors()->add('transactions.0.destination_id', (string) trans('validation.all_accounts_equal')); + $validator->errors()->add('transactions.0.destination_id', (string)trans('validation.all_accounts_equal')); } break; case'transfer': if (count($sources) > 1 || count($dests) > 1) { - $validator->errors()->add('transactions.0.source_id', (string) trans('validation.all_accounts_equal')); - $validator->errors()->add('transactions.0.destination_id', (string) trans('validation.all_accounts_equal')); + $validator->errors()->add('transactions.0.source_id', (string)trans('validation.all_accounts_equal')); + $validator->errors()->add('transactions.0.destination_id', (string)trans('validation.all_accounts_equal')); } break; } } /** - * @param Validator $validator - * @param TransactionGroup $transactionGroup + * @param Validator $validator + * @param TransactionGroup $transactionGroup */ private function validateEqualAccountsForUpdate(Validator $validator, TransactionGroup $transactionGroup): void { @@ -489,14 +489,14 @@ trait TransactionValidation $result = $this->compareAccountData($type, $comparison); if (false === $result) { if ('withdrawal' === $type) { - $validator->errors()->add('transactions.0.source_id', (string) trans('validation.all_accounts_equal')); + $validator->errors()->add('transactions.0.source_id', (string)trans('validation.all_accounts_equal')); } if ('deposit' === $type) { - $validator->errors()->add('transactions.0.destination_id', (string) trans('validation.all_accounts_equal')); + $validator->errors()->add('transactions.0.destination_id', (string)trans('validation.all_accounts_equal')); } if ('transfer' === $type) { - $validator->errors()->add('transactions.0.source_id', (string) trans('validation.all_accounts_equal')); - $validator->errors()->add('transactions.0.destination_id', (string) trans('validation.all_accounts_equal')); + $validator->errors()->add('transactions.0.source_id', (string)trans('validation.all_accounts_equal')); + $validator->errors()->add('transactions.0.destination_id', (string)trans('validation.all_accounts_equal')); } app('log')->warning('Add error about equal accounts.'); @@ -506,7 +506,7 @@ trait TransactionValidation } /** - * @param array $transactions + * @param array $transactions * * @return array */ @@ -519,7 +519,7 @@ trait TransactionValidation /** @var array $transaction */ foreach ($transactions as $transaction) { // source or destination may be omitted. If this is the case, use the original source / destination name + ID. - $originalData = $this->getOriginalData((int) ($transaction['transaction_journal_id'] ?? 0)); + $originalData = $this->getOriginalData((int)($transaction['transaction_journal_id'] ?? 0)); // get field. $comparison[$field][] = $transaction[$field] ?? $originalData[$field]; @@ -530,7 +530,7 @@ trait TransactionValidation } /** - * @param int $journalId + * @param int $journalId * * @return array */ @@ -562,8 +562,8 @@ trait TransactionValidation } /** - * @param string $type - * @param array $comparison + * @param string $type + * @param array $comparison * * @return bool */ @@ -577,7 +577,7 @@ trait TransactionValidation } /** - * @param array $comparison + * @param array $comparison * * @return bool */ @@ -596,7 +596,7 @@ trait TransactionValidation } /** - * @param array $array + * @param array $array * * @return bool */ @@ -606,7 +606,7 @@ trait TransactionValidation } /** - * @param array $comparison + * @param array $comparison * * @return bool */ @@ -625,7 +625,7 @@ trait TransactionValidation } /** - * @param array $comparison + * @param array $comparison * * @return bool */