Code cleanup that (hopefully) matches style CI

This commit is contained in:
James Cole
2020-03-17 14:57:04 +01:00
parent b0c9fc0792
commit bd2f064eeb
30 changed files with 318 additions and 298 deletions

View File

@@ -64,6 +64,8 @@ class TransactionJournalFactory
private $billRepository;
/** @var CurrencyRepositoryInterface */
private $currencyRepository;
/** @var bool */
private $errorOnHash;
/** @var array */
private $fields;
/** @var PiggyBankEventFactory */
@@ -76,8 +78,6 @@ class TransactionJournalFactory
private $typeRepository;
/** @var User The user */
private $user;
/** @var bool */
private $errorOnHash;
/**
* Constructor.
@@ -125,9 +125,9 @@ class TransactionJournalFactory
*
* @param array $data
*
* @return Collection
* @throws DuplicateTransactionException
* @throws FireflyException
* @return Collection
*/
public function create(array $data): Collection
{
@@ -171,6 +171,17 @@ class TransactionJournalFactory
return $collection;
}
/**
* @param bool $errorOnHash
*/
public function setErrorOnHash(bool $errorOnHash): void
{
$this->errorOnHash = $errorOnHash;
if (true === $errorOnHash) {
Log::info('Will trigger duplication alert for this journal.');
}
}
/**
* Set the user.
*
@@ -199,7 +210,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']));
@@ -212,9 +223,9 @@ class TransactionJournalFactory
/**
* @param NullArrayObject $row
*
* @return TransactionJournal|null
* @throws FireflyException
* @throws DuplicateTransactionException
* @return TransactionJournal|null
*/
private function createJournal(NullArrayObject $row): ?TransactionJournal
{
@@ -226,11 +237,11 @@ class TransactionJournalFactory
$type = $this->typeRepository->findTransactionType(null, $row['type']);
$carbon = $row['date'] ?? new Carbon;
$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 = app('steam')->cleanString((string)$row['description']);
$description = app('steam')->cleanString((string) $row['description']);
/** Manipulate basic fields */
$carbon->setTimezone(config('app.timezone'));
@@ -249,7 +260,7 @@ class TransactionJournalFactory
}
/** create or get source and destination accounts */
$sourceInfo = [
'id' => (int)$row['source_id'],
'id' => (int) $row['source_id'],
'name' => $row['source_name'],
'iban' => $row['source_iban'],
'number' => $row['source_number'],
@@ -257,7 +268,7 @@ class TransactionJournalFactory
];
$destInfo = [
'id' => (int)$row['destination_id'],
'id' => (int) $row['destination_id'],
'name' => $row['destination_name'],
'iban' => $row['destination_iban'],
'number' => $row['destination_number'],
@@ -325,7 +336,7 @@ class TransactionJournalFactory
'transaction_type_id' => $type->id,
'bill_id' => $billId,
'transaction_currency_id' => $currency->id,
'description' => substr($description,0,1000),
'description' => substr($description, 0, 1000),
'date' => $carbon->format('Y-m-d H:i:s'),
'order' => $order,
'tag_count' => 0,
@@ -344,7 +355,7 @@ class TransactionJournalFactory
$transactionFactory->setForeignCurrency($sourceForeignCurrency);
$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());
@@ -363,7 +374,7 @@ class TransactionJournalFactory
$transactionFactory->setForeignCurrency($destForeignCurrency);
$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());
@@ -506,7 +517,7 @@ class TransactionJournalFactory
$json = json_encode($dataRow);
if (false === $json) {
// @codeCoverageIgnoreStart
$json = json_encode((string)microtime());
$json = json_encode((string) microtime());
Log::error(sprintf('Could not hash the original row! %s', json_last_error_msg()), $dataRow);
// @codeCoverageIgnoreEnd
}
@@ -542,7 +553,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);
@@ -565,7 +576,7 @@ class TransactionJournalFactory
$this->accountValidator->setTransactionType($transactionType);
// validate source account.
$sourceId = isset($data['source_id']) ? (int)$data['source_id'] : null;
$sourceId = isset($data['source_id']) ? (int) $data['source_id'] : null;
$sourceName = $data['source_name'] ?? null;
$validSource = $this->accountValidator->validateSource($sourceId, $sourceName);
@@ -575,7 +586,7 @@ class TransactionJournalFactory
}
Log::debug('Source seems valid.');
// validate destination account
$destinationId = isset($data['destination_id']) ? (int)$data['destination_id'] : null;
$destinationId = isset($data['destination_id']) ? (int) $data['destination_id'] : null;
$destinationName = $data['destination_name'] ?? null;
$validDestination = $this->accountValidator->validateDestination($destinationId, $destinationName);
// do something with result:
@@ -584,16 +595,5 @@ class TransactionJournalFactory
}
}
/**
* @param bool $errorOnHash
*/
public function setErrorOnHash(bool $errorOnHash): void
{
$this->errorOnHash = $errorOnHash;
if (true === $errorOnHash) {
Log::info('Will trigger duplication alert for this journal.');
}
}
}