Various code cleanup.

This commit is contained in:
James Cole
2018-07-27 05:03:37 +02:00
parent 0312ba8ad7
commit e3e0e12fef
43 changed files with 167 additions and 145 deletions

View File

@@ -80,7 +80,7 @@ class StageImportDataHandler
$bunqAccountId = $bunqAccount['id'] ?? 0;
$localId = $mapping[$bunqAccountId] ?? 0;
Log::debug(sprintf('Looping accounts, now at bunq account #%d and local account #%d', $bunqAccountId, $localId));
if ($localId !== 0 && $bunqAccountId !== 0) {
if (0 !== $localId && 0 !== $bunqAccountId) {
$localAccount = $this->getLocalAccount((int)$localId);
$collection[] = $this->getTransactionsFromBunq($bunqAccountId, $localAccount);
}
@@ -122,7 +122,7 @@ class StageImportDataHandler
Log::debug(sprintf('Amount is %s %s', $amount->getCurrency(), $amount->getValue()));
$expected = AccountType::EXPENSE;
if (bccomp($amount->getValue(), '0') === 1) {
if (1 === bccomp($amount->getValue(), '0')) {
// amount + means that its a deposit.
$expected = AccountType::REVENUE;
$type = TransactionType::DEPOSIT;
@@ -131,7 +131,7 @@ class StageImportDataHandler
$destination = $this->convertToAccount($counterParty, $expected);
// switch source and destination if necessary.
if (bccomp($amount->getValue(), '0') === 1) {
if (1 === bccomp($amount->getValue(), '0')) {
Log::debug('Will make it a deposit.');
[$source, $destination] = [$destination, $source];
}
@@ -187,11 +187,12 @@ class StageImportDataHandler
* @param string $expectedType
*
* @return LocalAccount
* @throws FireflyException
*/
private function convertToAccount(LabelMonetaryAccount $party, string $expectedType): LocalAccount
{
Log::debug('in convertToAccount()');
if ($party->getIban() !== null) {
if (null !== $party->getIban()) {
// find opposing party by IBAN first.
$result = $this->accountRepository->findByIbanNull($party->getIban(), [$expectedType]);
if (null !== $result) {

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Support\Import\Routine\Fake;
use FireflyIII\Exceptions\FireflyException;
use Log;
/**
@@ -33,7 +32,6 @@ use Log;
class StageAhoyHandler
{
/**
* @throws FireflyException
*/
public function run(): void
{

View File

@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Support\Import\Routine\Fake;
use FireflyIII\Exceptions\FireflyException;
use Log;
/**
@@ -33,7 +32,6 @@ use Log;
class StageNewHandler
{
/**
* @throws FireflyException
*/
public function run(): void
{

View File

@@ -205,7 +205,7 @@ class ImportableConverter
$transactionType = $this->getTransactionType($source->accountType->type, $destination->accountType->type);
$currency = $currency ?? $this->getCurrency($source, $destination);
if ($transactionType === 'unknown') {
if ('unknown' === $transactionType) {
$message = sprintf(
'Cannot determine transaction type. Source account is a %s, destination is a %s', $source->accountType->type, $destination->accountType->type
);
@@ -282,14 +282,14 @@ class ImportableConverter
if ($destination->accountType->type === AccountType::ASSET) {
// destination is asset, might have currency preference:
$destinationCurrencyId = (int)$this->accountRepository->getMetaValue($destination, 'currency_id');
$currency = $destinationCurrencyId === 0 ? $this->defaultCurrency : $this->currencyMapper->map($destinationCurrencyId, []);
$currency = 0 === $destinationCurrencyId ? $this->defaultCurrency : $this->currencyMapper->map($destinationCurrencyId, []);
Log::debug(sprintf('Destination is an asset account, and has currency preference %s', $currency->code));
}
if ($source->accountType->type === AccountType::ASSET) {
// source is asset, might have currency preference:
$sourceCurrencyId = (int)$this->accountRepository->getMetaValue($source, 'currency_id');
$currency = $sourceCurrencyId === 0 ? $this->defaultCurrency : $this->currencyMapper->map($sourceCurrencyId, []);
$currency = 0 === $sourceCurrencyId ? $this->defaultCurrency : $this->currencyMapper->map($sourceCurrencyId, []);
Log::debug(sprintf('Source is an asset account, and has currency preference %s', $currency->code));
}
if (null === $currency) {

View File

@@ -123,7 +123,7 @@ class LineReader
/** @var array $config */
$config = $this->importJob->configuration;
Log::debug('now in getLines()');
$offset = isset($config['has-headers']) && $config['has-headers'] === true ? 1 : 0;
$offset = isset($config['has-headers']) && true === $config['has-headers'] ? 1 : 0;
try {
$stmt = (new Statement)->offset($offset);
// @codeCoverageIgnoreStart
@@ -151,7 +151,7 @@ class LineReader
$collection = $this->repository->getAttachments($this->importJob);
/** @var Attachment $attachment */
foreach ($collection as $attachment) {
if ($attachment->filename === 'import_file') {
if ('import_file' === $attachment->filename) {
$content = $this->attachments->getAttachmentContent($attachment);
break;
}

View File

@@ -195,7 +195,7 @@ class MappingConverger
$value = trim($value);
$originalRole = $this->roles[$columnIndex] ?? '_ignore';
Log::debug(sprintf('Now at column #%d (%s), value "%s"', $columnIndex, $originalRole, $value));
if ($originalRole !== '_ignore' && \strlen($value) > 0) {
if ('_ignore' !== $originalRole && \strlen($value) > 0) {
// is a mapped value present?
$mapped = $this->mapping[$columnIndex][$value] ?? 0;

View File

@@ -53,7 +53,7 @@ class OpposingAccountMapper
$expectedType = AccountType::EXPENSE;
$result = null;
Log::debug(sprintf('Going to search for accounts of type %s', $expectedType));
if (bccomp($amount, '0') === 1) {
if (1 === bccomp($amount, '0')) {
// more than zero.
$expectedType = AccountType::REVENUE;
Log::debug(sprintf('Because amount is %s, will instead search for accounts of type %s', $amount, $expectedType));

View File

@@ -57,7 +57,7 @@ class StageAuthenticatedHandler
$config = $this->importJob->configuration;
$logins = $config['all-logins'] ?? [];
Log::debug(sprintf('%d logins in config', \count($logins)));
if (\count($logins) === 0) {
if (0 === \count($logins)) {
// get logins from Spectre.
$logins = $this->getLogins();
$config['all-logins'] = $logins;

View File

@@ -60,7 +60,7 @@ class StageImportDataHandler
$config = $this->importJob->configuration;
$accounts = $config['accounts'] ?? [];
Log::debug(sprintf('Count of accounts in array is %d', \count($accounts)));
if (\count($accounts) === 0) {
if (0 === \count($accounts)) {
throw new FireflyException('There are no accounts in this import job. Cannot continue.'); // @codeCoverageIgnore
}
$toImport = $config['account_mapping'] ?? [];
@@ -124,14 +124,14 @@ class StageImportDataHandler
$amount = $transaction->getAmount();
$source = $originalSource;
$destination = $this->mapper->map(null, $amount, $destinationData);
$notes = (string)trans('import.imported_from_account', ['account' => $spectreAccount->getName()]) . ' ' . "\n";
$notes = trans('import.imported_from_account', ['account' => $spectreAccount->getName()]) . ' ' . "\n";
$foreignAmount = null;
$foreignCurrencyCode = null;
$currencyCode = $transaction->getCurrencyCode();
$type = 'withdrawal';
// switch source and destination if amount is greater than zero.
if (bccomp($amount, '0') === 1) {
if (1 === bccomp($amount, '0')) {
[$source, $destination] = [$destination, $source];
$type = 'deposit';
}