mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Various PSR12 code cleanup
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user