PHPStorm can order methods by alphabet, who knew.

This commit is contained in:
James Cole
2024-02-22 20:11:09 +01:00
parent f9d4a43e05
commit 68c9c4ec3c
221 changed files with 5840 additions and 5843 deletions

View File

@@ -80,10 +80,10 @@ 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' => [
@@ -95,38 +95,6 @@ class TransactionGroupTransformer extends AbstractTransformer
];
}
/**
* @throws FireflyException
*/
public function transformObject(TransactionGroup $group): array
{
try {
$result = [
'id' => $group->id,
'created_at' => $group->created_at->toAtomString(),
'updated_at' => $group->updated_at->toAtomString(),
'user' => $group->user_id,
'group_title' => $group->title,
'transactions' => $this->transformJournals($group->transactionJournals),
'links' => [
[
'rel' => 'self',
'uri' => '/transactions/'.$group->id,
],
],
];
} catch (FireflyException $e) {
app('log')->error($e->getMessage());
app('log')->error($e->getTraceAsString());
throw new FireflyException(sprintf('Transaction group #%d is broken. Please check out your log files.', $group->id), 0, $e);
}
// do something else.
return $result;
}
private function transformTransactions(NullArrayObject $data): array
{
$result = [];
@@ -146,20 +114,20 @@ 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'] && 0 !== bccomp('0', $row['foreign_amount'])) {
$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;
@@ -167,17 +135,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'],
@@ -189,12 +157,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'],
@@ -209,8 +177,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'],
@@ -243,7 +211,7 @@ 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']),
];
}
@@ -260,7 +228,7 @@ class TransactionGroupTransformer extends AbstractTransformer
return $default;
}
return (string) $array[$key];
return (string)$array[$key];
}
if (null !== $default) {
@@ -283,7 +251,7 @@ class TransactionGroupTransformer extends AbstractTransformer
private function integerFromArray(array $array, string $key): ?int
{
if (array_key_exists($key, $array)) {
return (int) $array[$key];
return (int)$array[$key];
}
return null;
@@ -303,6 +271,38 @@ class TransactionGroupTransformer extends AbstractTransformer
return $this->groupRepos->countAttachments($journalId) > 0;
}
/**
* @throws FireflyException
*/
public function transformObject(TransactionGroup $group): array
{
try {
$result = [
'id' => $group->id,
'created_at' => $group->created_at->toAtomString(),
'updated_at' => $group->updated_at->toAtomString(),
'user' => $group->user_id,
'group_title' => $group->title,
'transactions' => $this->transformJournals($group->transactionJournals),
'links' => [
[
'rel' => 'self',
'uri' => '/transactions/'.$group->id,
],
],
];
} catch (FireflyException $e) {
app('log')->error($e->getMessage());
app('log')->error($e->getTraceAsString());
throw new FireflyException(sprintf('Transaction group #%d is broken. Please check out your log files.', $group->id), 0, $e);
}
// do something else.
return $result;
}
/**
* @throws FireflyException
*/
@@ -434,7 +434,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) {
@@ -451,7 +451,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) {
@@ -555,7 +555,7 @@ 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;