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

@@ -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
{