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

@@ -58,7 +58,7 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface
$config = $this->repository->getConfiguration($this->importJob);
$mapping = $config['mapping'] ?? [];
$complete = \count($mapping) > 0;
if ($complete === true) {
if (true === $complete) {
// move job to correct stage to download transactions
$this->repository->setStage($this->importJob, 'go-for-import');
}
@@ -79,12 +79,12 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface
$config = $this->repository->getConfiguration($this->importJob);
$accounts = $config['accounts'] ?? [];
$mapping = $data['account_mapping'] ?? [];
$applyRules = (int)$data['apply_rules'] === 1;
$applyRules = 1 === (int)$data['apply_rules'];
$final = [];
if (\count($accounts) === 0) {
if (0 === \count($accounts)) {
throw new FireflyException('No bunq accounts found. Import cannot continue.'); // @codeCoverageIgnore
}
if (\count($mapping) === 0) {
if (0 === \count($mapping)) {
$messages = new MessageBag;
$messages->add('nomap', (string)trans('import.bunq_no_mapping'));
@@ -116,7 +116,7 @@ class ChooseAccountsHandler implements BunqJobConfigurationInterface
{
$config = $this->repository->getConfiguration($this->importJob);
$accounts = $config['accounts'] ?? [];
if (\count($accounts) === 0) {
if (0 === \count($accounts)) {
throw new FireflyException('No bunq accounts found. Import cannot continue.'); // @codeCoverageIgnore
}
// list the users accounts:

View File

@@ -183,7 +183,7 @@ class ConfigureMappingHandler implements FileConfigurationInterface
{
$canBeMapped = config('csv.import_roles.' . $name . '.mappable');
return $canBeMapped === true && $requested === true;
return true === $canBeMapped && true === $requested;
}
/**
@@ -247,7 +247,7 @@ class ConfigureMappingHandler implements FileConfigurationInterface
$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;
}
@@ -274,7 +274,7 @@ class ConfigureMappingHandler implements FileConfigurationInterface
*/
public function getValuesForMapping(Reader $reader, array $config, array $columnConfig): array
{
$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
@@ -295,7 +295,7 @@ class ConfigureMappingHandler implements FileConfigurationInterface
continue;
}
$value = trim($line[$columnIndex]);
if (\strlen($value) === 0) {
if ('' === $value) {
// value is empty, ignore it.
continue;
}
@@ -309,7 +309,7 @@ class ConfigureMappingHandler implements FileConfigurationInterface
$columnConfig[$columnIndex]['values'] = array_unique($columnConfig[$columnIndex]['values']);
asort($columnConfig[$columnIndex]['values']);
// if the count of this array is zero, there is nothing to map.
if (\count($columnConfig[$columnIndex]['values']) === 0) {
if (0 === \count($columnConfig[$columnIndex]['values'])) {
unset($columnConfig[$columnIndex]);
}
}

View File

@@ -76,10 +76,10 @@ class ConfigureRolesHandler implements FileConfigurationInterface
if (\in_array($role, ['amount', 'amount_credit', 'amount_debit'])) {
$hasAmount = true;
}
if ($role === 'foreign-currency-code') {
if ('foreign-currency-code' === $role) {
$hasForeignCode = true;
}
if ($role === 'amount_foreign') {
if ('amount_foreign' === $role) {
$hasForeignAmount = true;
}
}
@@ -122,7 +122,7 @@ class ConfigureRolesHandler implements FileConfigurationInterface
$count = $config['column-count'];
for ($i = 0; $i < $count; ++$i) {
$role = $data['role'][$i] ?? '_ignore';
$mapping = (isset($data['map'][$i]) && $data['map'][$i] === '1');
$mapping = (isset($data['map'][$i]) && '1' === $data['map'][$i]);
$config['column-roles'][$i] = $role;
$config['column-do-mapping'][$i] = $mapping;
Log::debug(sprintf('Column %d has been given role %s (mapping: %s)', $i, $role, var_export($mapping, true)));
@@ -130,7 +130,7 @@ class ConfigureRolesHandler implements FileConfigurationInterface
$config = $this->ignoreUnmappableColumns($config);
$messages = $this->configurationComplete($config);
if ($messages->count() === 0) {
if (0 === $messages->count()) {
$this->repository->setStage($this->importJob, 'ready_to_run');
if ($this->isMappingNecessary($config)) {
$this->repository->setStage($this->importJob, 'map');
@@ -175,7 +175,7 @@ class ConfigureRolesHandler implements FileConfigurationInterface
public function getExamplesFromFile(Reader $reader, array $config): void
{
$limit = (int)config('csv.example_rows', 5);
$offset = isset($config['has-headers']) && $config['has-headers'] === true ? 1 : 0;
$offset = isset($config['has-headers']) && true === $config['has-headers'] ? 1 : 0;
// make statement.
try {
@@ -214,7 +214,7 @@ class ConfigureRolesHandler implements FileConfigurationInterface
public function getHeaders(Reader $reader, array $config): array
{
$headers = [];
if (isset($config['has-headers']) && $config['has-headers'] === true) {
if (isset($config['has-headers']) && true === $config['has-headers']) {
try {
$stmt = (new Statement)->limit(1)->offset(0);
$records = $stmt->process($reader);
@@ -273,7 +273,7 @@ class ConfigureRolesHandler implements FileConfigurationInterface
$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

@@ -57,10 +57,10 @@ class ConfigureUploadHandler implements FileConfigurationInterface
// collect values:
$importId = isset($data['csv_import_account']) ? (int)$data['csv_import_account'] : 0;
$delimiter = (string)$data['csv_delimiter'];
$config['has-headers'] = (int)($data['has_headers'] ?? 0.0) === 1;
$config['has-headers'] = 1 === (int)($data['has_headers'] ?? 0.0);
$config['date-format'] = (string)$data['date_format'];
$config['delimiter'] = 'tab' === $delimiter ? "\t" : $delimiter;
$config['apply-rules'] = (int)($data['apply_rules'] ?? 0.0) === 1;
$config['apply-rules'] = 1 === (int)($data['apply_rules'] ?? 0.0);
$config['specifics'] = $this->getSpecifics($data);
// validate values:
$account = $this->accountRepos->findNull($importId);

View File

@@ -123,7 +123,7 @@ class NewFileJobHandler implements FileConfigurationInterface
/** @var Attachment $attachment */
foreach ($attachments as $attachment) {
// if file is configuration file, store it into the job.
if ($attachment->filename === 'configuration_file') {
if ('configuration_file' === $attachment->filename) {
$this->storeConfig($attachment);
}
}
@@ -162,7 +162,7 @@ class NewFileJobHandler implements FileConfigurationInterface
}
// if file is configuration file, store it into the job.
if ($attachment->filename === 'configuration_file') {
if ('configuration_file' === $attachment->filename) {
$this->storeConfig($attachment);
}
}
@@ -179,10 +179,10 @@ class NewFileJobHandler implements FileConfigurationInterface
{
$content = $this->attachments->getAttachmentContent($attachment);
$result = mb_detect_encoding($content, 'UTF-8', true);
if ($result === false) {
if (false === $result) {
return false;
}
if ($result !== 'ASCII' && $result !== 'UTF-8') {
if ('ASCII' !== $result && 'UTF-8' !== $result) {
return false; // @codeCoverageIgnore
}
@@ -194,7 +194,6 @@ class NewFileJobHandler implements FileConfigurationInterface
*
* @param Attachment $attachment
*
* @throws FireflyException
*/
private function storeConfig(Attachment $attachment): void
{

View File

@@ -98,7 +98,7 @@ class ChooseAccountsHandler implements SpectreJobConfigurationInterface
$config['account_mapping'] = $final;
$config['apply-rules'] = $applyRules;
$this->repository->setConfiguration($this->importJob, $config);
if ($final === [0 => 0] || \count($final) === 0) {
if ($final === [0 => 0] || 0 === \count($final)) {
$messages->add('count', (string)trans('import.spectre_no_mapping'));
}
@@ -116,7 +116,7 @@ class ChooseAccountsHandler implements SpectreJobConfigurationInterface
Log::debug('Now in ChooseAccountsHandler::getnextData()');
$config = $this->importJob->configuration;
$accounts = $config['accounts'] ?? [];
if (\count($accounts) === 0) {
if (0 === \count($accounts)) {
throw new FireflyException('It seems you have no accounts with this bank. The import cannot continue.'); // @codeCoverageIgnore
}
$converted = [];
@@ -128,15 +128,15 @@ class ChooseAccountsHandler implements SpectreJobConfigurationInterface
$login = null;
$logins = $config['all-logins'] ?? [];
$selected = $config['selected-login'] ?? 0;
if (\count($logins) === 0) {
if (0 === \count($logins)) {
throw new FireflyException('It seems you have no configured logins in this import job. The import cannot continue.'); // @codeCoverageIgnore
}
Log::debug(sprintf('Selected login to use is %d', $selected));
if ($selected === 0) {
if (0 === $selected) {
$login = new Login($logins[0]);
Log::debug(sprintf('Will use login %d (%s %s)', $login->getId(), $login->getProviderName(), $login->getCountryCode()));
}
if ($selected !== 0) {
if (0 !== $selected) {
foreach ($logins as $loginArray) {
$loginId = $loginArray['id'] ?? -1;
if ($loginId === $selected) {

View File

@@ -82,7 +82,7 @@ class ChooseLoginHandler implements SpectreJobConfigurationInterface
Log::debug(sprintf('The selected login by the user is #%d', $selectedLogin));
// if selected login is zero, create a new one.
if ($selectedLogin === 0) {
if (0 === $selectedLogin) {
Log::debug('Login is zero, get Spectre customer + token and store it in config.');
$customer = $this->getCustomer($this->importJob);
// get a token for the user and redirect to next stage