Various code optimalisations.

This commit is contained in:
James Cole
2018-07-08 07:59:58 +02:00
parent 10492e3b2f
commit 2f2f907ffe
59 changed files with 309 additions and 279 deletions

View File

@@ -89,10 +89,10 @@ class IndexController extends Controller
$hasPreReq = (bool)config(sprintf('import.has_prereq.%s', $importProvider));
$hasConfig = (bool)config(sprintf('import.has_job_config.%s', $importProvider));
// if job provider has no prerequisites:
if ($hasPreReq === false) {
if (false === $hasPreReq) {
Log::debug('Provider has no prerequisites. Continue.');
// if job provider also has no configuration:
if ($hasConfig === false) {
if (false === $hasConfig) {
// @codeCoverageIgnoreStart
Log::debug('Provider needs no configuration for job. Job is ready to start.');
$this->repository->updateStatus($importJob, 'ready_to_run');
@@ -130,7 +130,7 @@ class IndexController extends Controller
// update job to say "has_prereq".
$this->repository->setStatus($importJob, 'has_prereq');
if ($hasConfig === false) {
if (false === $hasConfig) {
// @codeCoverageIgnoreStart
Log::debug('Provider has no configuration. Job is ready to start.');
$this->repository->updateStatus($importJob, 'ready_to_run');
@@ -208,16 +208,16 @@ class IndexController extends Controller
$enabled = (bool)config(sprintf('import.enabled.%s', $providerName));
$allowedForDemo = (bool)config(sprintf('import.allowed_for_demo.%s', $providerName));
$allowedForUser = (bool)config(sprintf('import.allowed_for_user.%s', $providerName));
if ($enabled === false) {
if (false === $enabled) {
//Log::debug('Provider is not enabled. NEXT!');
continue;
}
if ($isDemoUser === true && $allowedForDemo === false) {
if (true === $isDemoUser && false === $allowedForDemo) {
//Log::debug('User is demo and this provider is not allowed for demo user. NEXT!');
continue;
}
if ($isDemoUser === false && $allowedForUser === false && $isDebug === false) {
if (false === $isDemoUser && false === $allowedForUser && false === $isDebug) {
//Log::debug('User is not demo and this provider is not allowed for such users. NEXT!');
continue; // @codeCoverageIgnore
}
@@ -227,7 +227,7 @@ class IndexController extends Controller
];
$class = (string)config(sprintf('import.prerequisites.%s', $providerName));
$result = false;
if ($class !== '' && class_exists($class)) {
if ('' !== $class && class_exists($class)) {
//Log::debug('Will not check prerequisites.');
/** @var PrerequisitesInterface $object */
$object = app($class);

View File

@@ -90,7 +90,7 @@ class JobStatusController extends Controller
'download_config_text' => '',
];
if ($importJob->provider === 'file') {
if ('file' === $importJob->provider) {
$json['download_config'] = true;
$json['download_config_text']
= trans('import.should_download_config', ['route' => route('import.job.download', [$importJob->key])]) . ' '
@@ -101,10 +101,10 @@ class JobStatusController extends Controller
if (null !== $importJob->tag_id) {
$count = $importJob->tag->transactionJournals->count();
}
if ($count === 0) {
if (0 === $count) {
$json['report_txt'] = trans('import.result_no_transactions');
}
if ($count === 1 && null !== $importJob->tag_id) {
if (1 === $count && null !== $importJob->tag_id) {
$json['report_txt'] = trans(
'import.result_one_transaction', ['route' => route('tags.show', [$importJob->tag_id, 'all']), 'tag' => $importJob->tag->tag]
);

View File

@@ -73,7 +73,7 @@ class PrerequisitesController extends Controller
{
// catch impossible status:
$allowed = ['new'];
if (null !== $importJob && !in_array($importJob->status, $allowed)) {
if (null !== $importJob && !in_array($importJob->status, $allowed, true)) {
Log::error(sprintf('Job has state "%s" but this Prerequisites::index() only accepts %s', $importJob->status, json_encode($allowed)));
session()->flash('error', trans('import.bad_job_status', ['status' => $importJob->status]));