Reformat various code.

This commit is contained in:
James Cole
2022-03-29 14:58:06 +02:00
parent 1209c4e76a
commit 29bed2547c
140 changed files with 1004 additions and 1010 deletions

View File

@@ -137,7 +137,7 @@ class AccountFactory
*/
protected function getAccountType(array $data): ?AccountType
{
$accountTypeId = array_key_exists('account_type_id', $data) ? (int)$data['account_type_id'] : 0;
$accountTypeId = array_key_exists('account_type_id', $data) ? (int) $data['account_type_id'] : 0;
$accountTypeName = array_key_exists('account_type_name', $data) ? $data['account_type_name'] : null;
$result = null;
// find by name or ID
@@ -200,7 +200,7 @@ class AccountFactory
'iban' => $data['iban'],
];
// fix virtual balance when it's empty
if ('' === (string)$databaseData['virtual_balance']) {
if ('' === (string) $databaseData['virtual_balance']) {
$databaseData['virtual_balance'] = null;
}
// remove virtual balance when not an asset account or a liability
@@ -252,9 +252,9 @@ class AccountFactory
*/
private function cleanMetaDataArray(Account $account, array $data): array
{
$currencyId = array_key_exists('currency_id', $data) ? (int)$data['currency_id'] : 0;
$currencyCode = array_key_exists('currency_code', $data) ? (string)$data['currency_code'] : '';
$accountRole = array_key_exists('account_role', $data) ? (string)$data['account_role'] : null;
$currencyId = array_key_exists('currency_id', $data) ? (int) $data['currency_id'] : 0;
$currencyCode = array_key_exists('currency_code', $data) ? (string) $data['currency_code'] : '';
$accountRole = array_key_exists('account_role', $data) ? (string) $data['account_role'] : null;
$currency = $this->getCurrency($currencyId, $currencyCode);
// only asset account may have a role:
@@ -301,7 +301,7 @@ class AccountFactory
$data[$field] = 1;
}
$factory->crud($account, $field, (string)$data[$field]);
$factory->crud($account, $field, (string) $data[$field]);
}
}
}
@@ -372,7 +372,7 @@ class AccountFactory
$order = $maxOrder + 1;
}
if (array_key_exists('order', $data)) {
$order = (int)($data['order'] > $maxOrder ? $maxOrder + 1 : $data['order']);
$order = (int) ($data['order'] > $maxOrder ? $maxOrder + 1 : $data['order']);
$order = 0 === $order ? $maxOrder + 1 : $order;
}

View File

@@ -52,7 +52,7 @@ class AttachmentFactory
// get journal instead of transaction.
if (Transaction::class === $model) {
/** @var Transaction $transaction */
$transaction = $this->user->transactions()->find((int)$data['attachable_id']);
$transaction = $this->user->transactions()->find((int) $data['attachable_id']);
if (null === $transaction) {
throw new FireflyException('Unexpectedly could not find transaction');
}
@@ -75,7 +75,7 @@ class AttachmentFactory
'uploaded' => 0,
]
);
$notes = (string)($data['notes'] ?? '');
$notes = (string) ($data['notes'] ?? '');
if ('' !== $notes) {
$note = new Note;
$note->noteable()->associate($attachment);

View File

@@ -41,8 +41,8 @@ class BudgetFactory
*/
public function find(?int $budgetId, ?string $budgetName): ?Budget
{
$budgetId = (int)$budgetId;
$budgetName = (string)$budgetName;
$budgetId = (int) $budgetId;
$budgetName = (string) $budgetName;
if (0 === $budgetId && '' === $budgetName) {
return null;

View File

@@ -45,8 +45,8 @@ class CategoryFactory
*/
public function findOrCreate(?int $categoryId, ?string $categoryName): ?Category
{
$categoryId = (int)$categoryId;
$categoryName = (string)$categoryName;
$categoryId = (int) $categoryId;
$categoryName = (string) $categoryName;
Log::debug(sprintf('Going to find category with ID %d and name "%s"', $categoryId, $categoryName));

View File

@@ -41,8 +41,8 @@ class PiggyBankFactory
*/
public function find(?int $piggyBankId, ?string $piggyBankName): ?PiggyBank
{
$piggyBankId = (int)$piggyBankId;
$piggyBankName = (string)$piggyBankName;
$piggyBankId = (int) $piggyBankId;
$piggyBankName = (string) $piggyBankName;
if ('' === $piggyBankName && 0 === $piggyBankId) {
return null;
}

View File

@@ -84,7 +84,7 @@ class RecurrenceFactory
$firstDate = $data['recurrence']['first_date'];
}
if (array_key_exists('nr_of_repetitions', $data['recurrence'])) {
$repetitions = (int)$data['recurrence']['nr_of_repetitions'];
$repetitions = (int) $data['recurrence']['nr_of_repetitions'];
}
if (array_key_exists('repeat_until', $data['recurrence'])) {
$repeatUntil = $data['recurrence']['repeat_until'];
@@ -120,7 +120,7 @@ class RecurrenceFactory
$recurrence->save();
if (array_key_exists('notes', $data['recurrence'])) {
$this->updateNote($recurrence, (string)$data['recurrence']['notes']);
$this->updateNote($recurrence, (string) $data['recurrence']['notes']);
}

View File

@@ -80,9 +80,9 @@ class TagFactory
*/
public function create(array $data): ?Tag
{
$zoomLevel = 0 === (int)$data['zoom_level'] ? null : (int)$data['zoom_level'];
$latitude = 0.0 === (float)$data['latitude'] ? null : (float)$data['latitude'];
$longitude = 0.0 === (float)$data['longitude'] ? null : (float)$data['longitude'];
$zoomLevel = 0 === (int) $data['zoom_level'] ? null : (int) $data['zoom_level'];
$latitude = 0.0 === (float) $data['latitude'] ? null : (float) $data['latitude'];
$longitude = 0.0 === (float) $data['longitude'] ? null : (float) $data['longitude'];
$array = [
'user_id' => $this->user->id,
'tag' => trim($data['tag']),

View File

@@ -46,7 +46,7 @@ class TransactionCurrencyFactory
// if the code already exists (deleted)
// force delete it and then create the transaction:
$count = TransactionCurrency::withTrashed()->whereCode($data['code'])->count();
if(1 === $count) {
if (1 === $count) {
$old = TransactionCurrency::withTrashed()->whereCode($data['code'])->first();
$old->forceDelete();
Log::warning(sprintf('Force deleted old currency with ID #%d and code "%s".', $old->id, $data['code']));
@@ -80,8 +80,8 @@ class TransactionCurrencyFactory
*/
public function find(?int $currencyId, ?string $currencyCode): ?TransactionCurrency
{
$currencyCode = (string)$currencyCode;
$currencyId = (int)$currencyId;
$currencyCode = (string) $currencyCode;
$currencyId = (int) $currencyId;
if ('' === $currencyCode && 0 === $currencyId) {
Log::debug('Cannot find anything on empty currency code and empty currency ID!');

View File

@@ -160,11 +160,11 @@ class TransactionJournalFactory
$type = $this->typeRepository->findTransactionType(null, $row['type']);
$carbon = $row['date'] ?? today(config('app.timezone'));
$order = $row['order'] ?? 0;
$currency = $this->currencyRepository->findCurrency((int)$row['currency_id'], $row['currency_code']);
$currency = $this->currencyRepository->findCurrency((int) $row['currency_id'], $row['currency_code']);
$foreignCurrency = $this->currencyRepository->findCurrencyNull($row['foreign_currency_id'], $row['foreign_currency_code']);
$bill = $this->billRepository->findBill((int)$row['bill_id'], $row['bill_name']);
$bill = $this->billRepository->findBill((int) $row['bill_id'], $row['bill_name']);
$billId = TransactionType::WITHDRAWAL === $type->type && null !== $bill ? $bill->id : null;
$description = (string)$row['description'];
$description = (string) $row['description'];
/** Manipulate basic fields */
$carbon->setTimezone(config('app.timezone'));
@@ -237,7 +237,7 @@ class TransactionJournalFactory
$transactionFactory->setForeignCurrency($foreignCurrency);
$transactionFactory->setReconciled($row['reconciled'] ?? false);
try {
$negative = $transactionFactory->createNegative((string)$row['amount'], (string)$row['foreign_amount']);
$negative = $transactionFactory->createNegative((string) $row['amount'], (string) $row['foreign_amount']);
} catch (FireflyException $e) {
Log::error('Exception creating negative transaction.');
Log::error($e->getMessage());
@@ -256,7 +256,7 @@ class TransactionJournalFactory
$transactionFactory->setForeignCurrency($foreignCurrency);
$transactionFactory->setReconciled($row['reconciled'] ?? false);
try {
$transactionFactory->createPositive((string)$row['amount'], (string)$row['foreign_amount']);
$transactionFactory->createPositive((string) $row['amount'], (string) $row['foreign_amount']);
} catch (FireflyException $e) {
Log::error('Exception creating positive transaction.');
Log::error($e->getMessage());
@@ -307,7 +307,7 @@ class TransactionJournalFactory
$json = json_encode($dataRow, JSON_THROW_ON_ERROR);
if (false === $json) {
$json = json_encode((string)microtime(), JSON_THROW_ON_ERROR);
$json = json_encode((string) microtime(), JSON_THROW_ON_ERROR);
Log::error(sprintf('Could not hash the original row! %s', json_last_error_msg()), $dataRow);
}
@@ -366,10 +366,10 @@ class TransactionJournalFactory
// validate source account.
$array = [
'id' => $data['source_id'] ? (int)$data['source_id'] : null,
'name' => $data['source_name'] ? (string)$data['source_name'] : null,
'iban' => $data['source_iban'] ? (string)$data['source_iban'] : null,
'number' => $data['source_number'] ? (string)$data['source_number'] : null,
'id' => $data['source_id'] ? (int) $data['source_id'] : null,
'name' => $data['source_name'] ? (string) $data['source_name'] : null,
'iban' => $data['source_iban'] ? (string) $data['source_iban'] : null,
'number' => $data['source_number'] ? (string) $data['source_number'] : null,
];
$validSource = $this->accountValidator->validateSource($array);
@@ -381,10 +381,10 @@ class TransactionJournalFactory
// validate destination account
$array = [
'id' => $data['destination_id'] ? (int)$data['destination_id'] : null,
'name' => $data['destination_name'] ? (string)$data['destination_name'] : null,
'iban' => $data['destination_iban'] ? (string)$data['destination_iban'] : null,
'number' => $data['destination_number'] ? (string)$data['destination_number'] : null,
'id' => $data['destination_id'] ? (int) $data['destination_id'] : null,
'name' => $data['destination_name'] ? (string) $data['destination_name'] : null,
'iban' => $data['destination_iban'] ? (string) $data['destination_iban'] : null,
'number' => $data['destination_number'] ? (string) $data['destination_number'] : null,
];
$validDestination = $this->accountValidator->validateDestination($array);
@@ -526,7 +526,7 @@ class TransactionJournalFactory
return;
}
$piggyBank = $this->piggyRepository->findPiggyBank((int)$data['piggy_bank_id'], $data['piggy_bank_name']);
$piggyBank = $this->piggyRepository->findPiggyBank((int) $data['piggy_bank_id'], $data['piggy_bank_name']);
if (null !== $piggyBank) {
$this->piggyEventFactory->create($journal, $piggyBank);
@@ -558,7 +558,7 @@ class TransactionJournalFactory
$set = [
'journal' => $journal,
'name' => $field,
'data' => (string)($data[$field] ?? ''),
'data' => (string) ($data[$field] ?? ''),
];
//Log::debug(sprintf('Going to store meta-field "%s", with value "%s".', $set['name'], $set['data']));

View File

@@ -60,7 +60,7 @@ class TransactionJournalMetaFactory
//Log::debug('Is a carbon object.');
$value = $data['data']->toW3cString();
}
if ('' === (string)$value) {
if ('' === (string) $value) {
// Log::debug('Is an empty string.');
// don't store blank strings.
if (null !== $entry) {