Various PSR12 code cleanup

This commit is contained in:
James Cole
2022-12-29 19:42:40 +01:00
parent 6cfdc58cb1
commit 56b9b66352
38 changed files with 763 additions and 691 deletions

View File

@@ -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,
],
],
];

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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,
],
],
];

View File

@@ -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,
],
],
];

View File

@@ -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,
],
],
];

View File

@@ -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,
],
],
];

View File

@@ -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
{

View File

@@ -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,

View File

@@ -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;

View File

@@ -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,
],
],
];

View File

@@ -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,

View File

@@ -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,
],
],
];

View File

@@ -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();
}
}

View File

@@ -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,
],
],
];

View File

@@ -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,
],
],
];

View File

@@ -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
{

View File

@@ -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;
}
}
}

View File

@@ -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.
}
}

View File

@@ -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.
}
}

View File

@@ -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,
];
}
}

View File

@@ -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

View File

@@ -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,
];

View File

@@ -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,
];

View File

@@ -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