Various PSR12 code cleanup

This commit is contained in:
James Cole
2022-12-29 19:41:57 +01:00
parent 0022009dd5
commit dbf3e76ecc
340 changed files with 4079 additions and 3816 deletions

View File

@@ -315,7 +315,7 @@ class GroupCollector implements GroupCollectorInterface
/**
* Limit results to NOT a specific currency, either foreign or normal one.
*
* @param TransactionCurrency $currency
* @param TransactionCurrency $currency
*
* @return GroupCollectorInterface
*/
@@ -352,7 +352,7 @@ class GroupCollector implements GroupCollectorInterface
/**
* Limit the result to NOT a set of specific transaction groups.
*
* @param array $groupIds
* @param array $groupIds
*
* @return GroupCollectorInterface
*/
@@ -366,7 +366,7 @@ class GroupCollector implements GroupCollectorInterface
/**
* Limit the result to NOT a set of specific journals.
*
* @param array $journalIds
* @param array $journalIds
*
* @return GroupCollectorInterface
*/
@@ -386,7 +386,7 @@ class GroupCollector implements GroupCollectorInterface
/**
* Search for words in descriptions.
*
* @param array $array
* @param array $array
*
* @return GroupCollectorInterface
*/
@@ -500,7 +500,7 @@ class GroupCollector implements GroupCollectorInterface
}
/**
* @param Collection $collection
* @param Collection $collection
*
* @return Collection
*/
@@ -515,21 +515,21 @@ class GroupCollector implements GroupCollectorInterface
// make new array
$parsedGroup = $this->parseAugmentedJournal($augumentedJournal);
$groupArray = [
'id' => (int) $augumentedJournal->transaction_group_id,
'user_id' => (int) $augumentedJournal->user_id,
'id' => (int)$augumentedJournal->transaction_group_id,
'user_id' => (int)$augumentedJournal->user_id,
'title' => $augumentedJournal->transaction_group_title,
'transaction_type' => $parsedGroup['transaction_type_type'],
'count' => 1,
'sums' => [],
'transactions' => [],
];
$journalId = (int) $augumentedJournal->transaction_journal_id;
$journalId = (int)$augumentedJournal->transaction_journal_id;
$groupArray['transactions'][$journalId] = $parsedGroup;
$groups[$groupId] = $groupArray;
continue;
}
// or parse the rest.
$journalId = (int) $augumentedJournal->transaction_journal_id;
$journalId = (int)$augumentedJournal->transaction_journal_id;
if (array_key_exists($journalId, $groups[$groupId]['transactions'])) {
// append data to existing group + journal (for multiple tags or multiple attachments)
$groups[$groupId]['transactions'][$journalId] = $this->mergeTags($groups[$groupId]['transactions'][$journalId], $augumentedJournal);
@@ -549,7 +549,7 @@ class GroupCollector implements GroupCollectorInterface
}
/**
* @param TransactionJournal $augumentedJournal
* @param TransactionJournal $augumentedJournal
*
* @return array
*/
@@ -582,7 +582,7 @@ class GroupCollector implements GroupCollectorInterface
$dates = ['interest_date', 'payment_date', 'invoice_date', 'book_date', 'due_date', 'process_date'];
if (array_key_exists('meta_name', $result) && in_array($result['meta_name'], $dates, true)) {
$name = $result['meta_name'];
if (array_key_exists('meta_data', $result) && '' !== (string) $result['meta_data']) {
if (array_key_exists('meta_data', $result) && '' !== (string)$result['meta_data']) {
$result[$name] = Carbon::createFromFormat('!Y-m-d', substr(json_decode($result['meta_data']), 0, 10));
}
}
@@ -593,9 +593,9 @@ class GroupCollector implements GroupCollectorInterface
// convert back to strings because SQLite is dumb like that.
$result = $this->convertToStrings($result);
$result['reconciled'] = 1 === (int) $result['reconciled'];
$result['reconciled'] = 1 === (int)$result['reconciled'];
if (array_key_exists('tag_id', $result) && null !== $result['tag_id']) { // assume the other fields are present as well.
$tagId = (int) $augumentedJournal['tag_id'];
$tagId = (int)$augumentedJournal['tag_id'];
$tagDate = null;
try {
$tagDate = Carbon::parse($augumentedJournal['tag_date']);
@@ -604,7 +604,7 @@ class GroupCollector implements GroupCollectorInterface
}
$result['tags'][$tagId] = [
'id' => (int) $result['tag_id'],
'id' => (int)$result['tag_id'],
'name' => $result['tag_name'],
'date' => $tagDate,
'description' => $result['tag_description'],
@@ -613,8 +613,8 @@ class GroupCollector implements GroupCollectorInterface
// also merge attachments:
if (array_key_exists('attachment_id', $result)) {
$uploaded = 1 === (int) $result['attachment_uploaded'];
$attachmentId = (int) $augumentedJournal['attachment_id'];
$uploaded = 1 === (int)$result['attachment_uploaded'];
$attachmentId = (int)$augumentedJournal['attachment_id'];
if (0 !== $attachmentId && $uploaded) {
$result['attachments'][$attachmentId] = [
'id' => $attachmentId,
@@ -624,7 +624,8 @@ class GroupCollector implements GroupCollectorInterface
}
}
// unset various fields:
unset($result['tag_id'], $result['meta_data'], $result['meta_name'],
unset(
$result['tag_id'], $result['meta_data'], $result['meta_name'],
$result['tag_name'], $result['tag_date'], $result['tag_description'],
$result['tag_latitude'], $result['tag_longitude'], $result['tag_zoom_level'],
$result['attachment_filename'], $result['attachment_id']
@@ -637,35 +638,35 @@ class GroupCollector implements GroupCollectorInterface
/**
* Convert a selected set of fields to arrays.
*
* @param array $array
* @param array $array
*
* @return array
*/
private function convertToInteger(array $array): array
{
foreach ($this->integerFields as $field) {
$array[$field] = array_key_exists($field, $array) ? (int) $array[$field] : null;
$array[$field] = array_key_exists($field, $array) ? (int)$array[$field] : null;
}
return $array;
}
/**
* @param array $array
* @param array $array
* @return array
*/
private function convertToStrings(array $array): array
{
foreach ($this->stringFields as $field) {
$array[$field] = array_key_exists($field, $array) && null !== $array[$field] ? (string) $array[$field] : null;
$array[$field] = array_key_exists($field, $array) && null !== $array[$field] ? (string)$array[$field] : null;
}
return $array;
}
/**
* @param array $existingJournal
* @param TransactionJournal $newJournal
* @param array $existingJournal
* @param TransactionJournal $newJournal
*
* @return array
*/
@@ -673,7 +674,7 @@ class GroupCollector implements GroupCollectorInterface
{
$newArray = $newJournal->toArray();
if (array_key_exists('tag_id', $newArray)) { // assume the other fields are present as well.
$tagId = (int) $newJournal['tag_id'];
$tagId = (int)$newJournal['tag_id'];
$tagDate = null;
try {
@@ -683,7 +684,7 @@ class GroupCollector implements GroupCollectorInterface
}
$existingJournal['tags'][$tagId] = [
'id' => (int) $newArray['tag_id'],
'id' => (int)$newArray['tag_id'],
'name' => $newArray['tag_name'],
'date' => $tagDate,
'description' => $newArray['tag_description'],
@@ -694,8 +695,8 @@ class GroupCollector implements GroupCollectorInterface
}
/**
* @param array $existingJournal
* @param TransactionJournal $newJournal
* @param array $existingJournal
* @param TransactionJournal $newJournal
*
* @return array
*/
@@ -703,7 +704,7 @@ class GroupCollector implements GroupCollectorInterface
{
$newArray = $newJournal->toArray();
if (array_key_exists('attachment_id', $newArray)) {
$attachmentId = (int) $newJournal['attachment_id'];
$attachmentId = (int)$newJournal['attachment_id'];
$existingJournal['attachments'][$attachmentId] = [
'id' => $attachmentId,
@@ -714,20 +715,20 @@ class GroupCollector implements GroupCollectorInterface
}
/**
* @param array $groups
* @param array $groups
*
* @return array
*/
private function parseSums(array $groups): array
{
/**
* @var int $groudId
* @var int $groudId
* @var array $group
*/
foreach ($groups as $groudId => $group) {
/** @var array $transaction */
foreach ($group['transactions'] as $transaction) {
$currencyId = (int) $transaction['currency_id'];
$currencyId = (int)$transaction['currency_id'];
// set default:
if (!array_key_exists($currencyId, $groups[$groudId]['sums'])) {
@@ -740,7 +741,7 @@ class GroupCollector implements GroupCollectorInterface
$groups[$groudId]['sums'][$currencyId]['amount'] = bcadd($groups[$groudId]['sums'][$currencyId]['amount'], $transaction['amount']);
if (null !== $transaction['foreign_amount'] && null !== $transaction['foreign_currency_id']) {
$currencyId = (int) $transaction['foreign_currency_id'];
$currencyId = (int)$transaction['foreign_currency_id'];
// set default:
if (!array_key_exists($currencyId, $groups[$groudId]['sums'])) {
@@ -762,14 +763,14 @@ class GroupCollector implements GroupCollectorInterface
}
/**
* @param Collection $collection
* @param Collection $collection
* @return Collection
*/
private function postFilterCollection(Collection $collection): Collection
{
$currentCollection = $collection;
/**
* @var int $i
* @var int $i
* @var Closure $function
*/
foreach ($this->postFilters as $function) {
@@ -778,7 +779,7 @@ class GroupCollector implements GroupCollectorInterface
// and save it (or not) in the new collection.
// that new collection is the next current collection
/**
* @var int $index
* @var int $index
* @var array $item
*/
foreach ($currentCollection as $ii => $item) {
@@ -812,7 +813,7 @@ class GroupCollector implements GroupCollectorInterface
/**
* Limit the number of returned entries.
*
* @param int $limit
* @param int $limit
*
* @return GroupCollectorInterface
*/
@@ -845,7 +846,7 @@ class GroupCollector implements GroupCollectorInterface
/**
* Limit results to a specific currency, either foreign or normal one.
*
* @param TransactionCurrency $currency
* @param TransactionCurrency $currency
*
* @return GroupCollectorInterface
*/
@@ -874,7 +875,7 @@ class GroupCollector implements GroupCollectorInterface
/**
* Limit the result to a set of specific transaction groups.
*
* @param array $groupIds
* @param array $groupIds
*
* @return GroupCollectorInterface
*/
@@ -888,7 +889,7 @@ class GroupCollector implements GroupCollectorInterface
/**
* Limit the result to a set of specific journals.
*
* @param array $journalIds
* @param array $journalIds
*
* @return GroupCollectorInterface
*/
@@ -908,7 +909,7 @@ class GroupCollector implements GroupCollectorInterface
/**
* Set the page to get.
*
* @param int $page
* @param int $page
*
* @return GroupCollectorInterface
*/
@@ -924,7 +925,7 @@ class GroupCollector implements GroupCollectorInterface
/**
* Search for words in descriptions.
*
* @param array $array
* @param array $array
*
* @return GroupCollectorInterface
*/
@@ -960,7 +961,7 @@ class GroupCollector implements GroupCollectorInterface
/**
* Limit the search to one specific transaction group.
*
* @param TransactionGroup $transactionGroup
* @param TransactionGroup $transactionGroup
*
* @return GroupCollectorInterface
*/
@@ -974,7 +975,7 @@ class GroupCollector implements GroupCollectorInterface
/**
* Limit the included transaction types.
*
* @param array $types
* @param array $types
*
* @return GroupCollectorInterface
*/
@@ -988,7 +989,7 @@ class GroupCollector implements GroupCollectorInterface
/**
* Set the user object and start the query.
*
* @param User $user
* @param User $user
*
* @return GroupCollectorInterface
*/