Code cleanup

This commit is contained in:
James Cole
2018-04-02 14:50:17 +02:00
parent 379b104778
commit fa7ab45a40
100 changed files with 440 additions and 517 deletions

View File

@@ -57,11 +57,11 @@ class HaveAccounts implements ConfigurationInterface
/** @var Account $dbAccount */
foreach ($collection as $dbAccount) {
$id = $dbAccount->id;
$currencyId = intval($accountRepository->getMetaValue($dbAccount, 'currency_id'));
$currencyId = (int)$accountRepository->getMetaValue($dbAccount, 'currency_id');
$currency = $currencyRepository->findNull($currencyId);
$dbAccounts[$id] = [
'account' => $dbAccount,
'currency' => is_null($currency) ? $defaultCurrency : $currency,
'currency' => null === $currency ? $defaultCurrency : $currency,
];
}
@@ -78,11 +78,9 @@ class HaveAccounts implements ConfigurationInterface
}
$data = [
return [
'config' => $config,
];
return $data;
}
/**
@@ -119,9 +117,9 @@ class HaveAccounts implements ConfigurationInterface
$accounts = $data['bunq_account_id'] ?? [];
$mapping = [];
foreach ($accounts as $bunqId) {
$bunqId = intval($bunqId);
$doImport = intval($data['do_import'][$bunqId] ?? 0) === 1;
$account = intval($data['import'][$bunqId] ?? 0);
$bunqId = (int)$bunqId;
$doImport = (int)($data['do_import'][$bunqId] ?? 0.0) === 1;
$account = (int)($data['import'][$bunqId] ?? 0.0);
if ($doImport) {
$mapping[$bunqId] = $account;
}

View File

@@ -102,7 +102,7 @@ class Initial implements ConfigurationInterface
Log::debug('Now in storeConfiguration for file Upload.');
$config = $this->getConfig();
$type = $data['import_file_type'] ?? 'csv'; // assume it's a CSV file.
$config['file-type'] = in_array($type, config('import.options.file.import_formats')) ? $type : 'csv';
$config['file-type'] = \in_array($type, config('import.options.file.import_formats'), true) ? $type : 'csv';
// update config:
$this->repository->setConfiguration($this->job, $config);
@@ -118,7 +118,7 @@ class Initial implements ConfigurationInterface
}
if (false === $uploaded) {
$this->warning = 'No valid upload.';
$this->warning = (string)trans('firefly.upload_error');
return true;
}

View File

@@ -159,12 +159,12 @@ class Map implements ConfigurationInterface
$config = $this->getConfig();
if (isset($data['mapping'])) {
foreach ($data['mapping'] as $index => $data) {
foreach ($data['mapping'] as $index => $array) {
$config['column-mapping-config'][$index] = [];
foreach ($data as $value => $mapId) {
$mapId = intval($mapId);
foreach ($array as $value => $mapId) {
$mapId = (int)$mapId;
if (0 !== $mapId) {
$config['column-mapping-config'][$index][$value] = intval($mapId);
$config['column-mapping-config'][$index][$value] = $mapId;
}
}
}
@@ -186,10 +186,8 @@ class Map implements ConfigurationInterface
{
$mapperClass = config('csv.import_roles.' . $column . '.mapper');
$mapperName = sprintf('\\FireflyIII\\Import\Mapper\\%s', $mapperClass);
/** @var MapperInterface $mapper */
$mapper = app($mapperName);
return $mapper;
return app($mapperName);
}
/**

View File

@@ -73,7 +73,7 @@ class Roles implements ConfigurationInterface
}
// example rows:
$stmt = (new Statement)->limit(intval(config('csv.example_rows', 5)))->offset($offset);
$stmt = (new Statement)->limit((int)config('csv.example_rows', 5))->offset($offset);
// set data:
$roles = $this->getRoles();
asort($roles);
@@ -274,14 +274,14 @@ class Roles implements ConfigurationInterface
}
// warn if has foreign amount but no currency code:
if ($hasForeignAmount && !$hasForeignCode) {
$this->warning = strval(trans('import.foreign_amount_warning'));
$this->warning = (string)trans('import.foreign_amount_warning');
Log::debug('isRolesComplete() returns FALSE because foreign amount present without foreign code.');
return false;
}
if (0 === $assigned || !$hasAmount) {
$this->warning = strval(trans('import.roles_warning'));
$this->warning = (string)trans('import.roles_warning');
Log::debug('isRolesComplete() returns FALSE because no amount present.');
return false;

View File

@@ -114,16 +114,16 @@ class UploadConfig implements ConfigurationInterface
{
Log::debug('Now in Initial::storeConfiguration()');
$config = $this->getConfig();
$importId = intval($data['csv_import_account'] ?? 0);
$importId = (int)($data['csv_import_account'] ?? 0.0);
$account = $this->accountRepository->find($importId);
$delimiter = strval($data['csv_delimiter']);
$delimiter = (string)$data['csv_delimiter'];
// set "headers":
$config['has-headers'] = intval($data['has_headers'] ?? 0) === 1;
$config['date-format'] = strval($data['date_format']);
$config['has-headers'] = (int)($data['has_headers'] ?? 0.0) === 1;
$config['date-format'] = (string)$data['date_format'];
$config['delimiter'] = 'tab' === $delimiter ? "\t" : $delimiter;
$config['apply-rules'] = intval($data['apply_rules'] ?? 0) === 1;
$config['match-bills'] = intval($data['match_bills'] ?? 0) === 1;
$config['apply-rules'] = (int)($data['apply_rules'] ?? 0.0) === 1;
$config['match-bills'] = (int)($data['match_bills'] ?? 0.0) === 1;
Log::debug('Entered import account.', ['id' => $importId]);

View File

@@ -58,11 +58,11 @@ class HaveAccounts implements ConfigurationInterface
/** @var Account $dbAccount */
foreach ($collection as $dbAccount) {
$id = $dbAccount->id;
$currencyId = intval($dbAccount->getMeta('currency_id'));
$currencyId = (int)$dbAccount->getMeta('currency_id');
$currency = $currencyRepository->find($currencyId);
$dbAccounts[$id] = [
'account' => $dbAccount,
'currency' => is_null($currency->id) ? $defaultCurrency : $currency,
'currency' => null === $currency->id ? $defaultCurrency : $currency,
];
}
@@ -79,12 +79,9 @@ class HaveAccounts implements ConfigurationInterface
}
$data = [
return [
'config' => $config,
];
return $data;
}
/**
@@ -121,9 +118,9 @@ class HaveAccounts implements ConfigurationInterface
$accounts = $data['spectre_account_id'] ?? [];
$mapping = [];
foreach ($accounts as $spectreId) {
$spectreId = intval($spectreId);
$doImport = intval($data['do_import'][$spectreId] ?? 0) === 1;
$account = intval($data['import'][$spectreId] ?? 0);
$spectreId = (int)$spectreId;
$doImport = (int)($data['do_import'][$spectreId] ?? 0.0) === 1;
$account = (int)($data['import'][$spectreId] ?? 0.0);
if ($doImport) {
$mapping[$spectreId] = $account;
}

View File

@@ -63,7 +63,6 @@ class BunqInformation implements InformationInterface
* @return array
*
* @throws FireflyException
* @throws \Exception
*/
public function getAccounts(): array
{
@@ -117,7 +116,7 @@ class BunqInformation implements InformationInterface
/**
* @param SessionToken $sessionToken
*
* @throws \Exception
*/
private function closeSession(SessionToken $sessionToken): void
{
@@ -141,7 +140,7 @@ class BunqInformation implements InformationInterface
*
* @return Collection
*
* @throws \Exception
*/
private function getMonetaryAccounts(SessionToken $sessionToken, int $userId): Collection
{
@@ -166,7 +165,6 @@ class BunqInformation implements InformationInterface
* @return int
*
* @throws FireflyException
* @throws \Exception
*/
private function getUserInformation(SessionToken $sessionToken): int
{
@@ -194,7 +192,7 @@ class BunqInformation implements InformationInterface
/**
* @return SessionToken
*
* @throws \Exception
*/
private function startSession(): SessionToken
{