Various code cleanup.

This commit is contained in:
James Cole
2021-04-06 08:51:27 +02:00
parent d32446b171
commit 5ceef2e9c3
47 changed files with 161 additions and 557 deletions

View File

@@ -214,14 +214,6 @@ class ApplyRules extends Command
$finalList = new Collection;
$accountList = explode(',', $accountString);
// @codeCoverageIgnoreStart
if (0 === count($accountList)) {
$this->error('Please use the --accounts option to indicate the accounts to apply rules to.');
return false;
}
// @codeCoverageIgnoreEnd
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$accountRepository->setUser($this->getUser());
@@ -255,12 +247,7 @@ class ApplyRules extends Command
return true;
}
$ruleGroupList = explode(',', $ruleGroupString);
// @codeCoverageIgnoreStart
if (0 === count($ruleGroupList)) {
// can be empty.
return true;
}
// @codeCoverageIgnoreEnd
foreach ($ruleGroupList as $ruleGroupId) {
$ruleGroup = $this->ruleGroupRepository->find((int)$ruleGroupId);
if ($ruleGroup->active) {
@@ -286,14 +273,6 @@ class ApplyRules extends Command
}
$ruleList = explode(',', $ruleString);
// @codeCoverageIgnoreStart
if (0 === count($ruleList)) {
// can be empty.
return true;
}
// @codeCoverageIgnoreEnd
foreach ($ruleList as $ruleId) {
$rule = $this->ruleRepository->find((int)$ruleId);
if (null !== $rule && $rule->active) {

View File

@@ -65,9 +65,8 @@ class Cron extends Command
$date = null;
try {
$date = new Carbon($this->option('date'));
} catch (InvalidArgumentException | Exception $e) {
} catch (InvalidArgumentException $e) {
$this->error(sprintf('"%s" is not a valid date', $this->option('date')));
$e->getMessage();
}
$force = (bool)$this->option('force');
@@ -127,13 +126,15 @@ class Cron extends Command
$recurring->setDate($date);
}
$result = $recurring->fire();
if (false === $result) {
$this->line('The recurring transaction cron job did not fire.');
$recurring->fire();
if($recurring->jobErrored) {
$this->error(sprintf('Error in "create recurring transactions" cron: %s', $recurring->message));
}
if (true === $result) {
$this->line('The recurring transaction cron job fired successfully.');
if($recurring->jobFired) {
$this->error(sprintf('"Create recurring transactions" cron fired: %s', $recurring->message));
}
if($recurring->jobSucceeded) {
$this->error(sprintf('"Create recurring transactions" cron ran with success: %s', $recurring->message));
}
}
@@ -142,7 +143,6 @@ class Cron extends Command
* @param Carbon|null $date
*
* @throws FireflyException
* @throws Exception
*/
private function autoBudgetCronJob(bool $force, ?Carbon $date): void
{
@@ -153,13 +153,16 @@ class Cron extends Command
$autoBudget->setDate($date);
}
$result = $autoBudget->fire();
$autoBudget->fire();
if (false === $result) {
$this->line('The auto budget cron job did not fire.');
if($autoBudget->jobErrored) {
$this->error(sprintf('Error in "create auto budgets" cron: %s', $autoBudget->message));
}
if (true === $result) {
$this->line('The auto budget cron job fired successfully.');
if($autoBudget->jobFired) {
$this->error(sprintf('"Create auto budgets" cron fired: %s', $autoBudget->message));
}
if($autoBudget->jobSucceeded) {
$this->error(sprintf('"Create auto budgets" cron ran with success: %s', $autoBudget->message));
}
}
@@ -167,6 +170,8 @@ class Cron extends Command
/**
* @param bool $force
* @param Carbon|null $date
*
* @throws FireflyException
*/
private function telemetryCronJob(bool $force, ?Carbon $date): void
{
@@ -182,13 +187,16 @@ class Cron extends Command
$telemetry->setDate($date);
}
$result = $telemetry->fire();
$telemetry->fire();
if (false === $result) {
$this->line('The telemetry cron job did not fire.');
if($telemetry->jobErrored) {
$this->error(sprintf('Error in "send telemetry" cron: %s', $telemetry->message));
}
if (true === $result) {
$this->line('The telemetry cron job fired successfully.');
if($telemetry->jobFired) {
$this->error(sprintf('"Send telemetry" cron fired: %s', $telemetry->message));
}
if($telemetry->jobSucceeded) {
$this->error(sprintf('"Send telemetry" cron ran with success: %s', $telemetry->message));
}
}

View File

@@ -148,7 +148,7 @@ class AccountCurrencies extends Command
}
Log::debug(sprintf('Users currency pref is %s', $defaultCurrencyCode));
/** @var TransactionCurrency $defaultCurrency */
/** @var TransactionCurrency|null $defaultCurrency */
$defaultCurrency = TransactionCurrency::where('code', $defaultCurrencyCode)->first();
if (null === $defaultCurrency) {

View File

@@ -73,11 +73,8 @@ class AppendBudgetLimitPeriods extends Command
private function isExecuted(): bool
{
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) {
return (bool)$configVar->data;
}
return false; // @codeCoverageIgnore
return (bool)$configVar->data;
}
/**

View File

@@ -87,11 +87,7 @@ class BackToJournals extends Command
private function isMigrated(): bool
{
$configVar = app('fireflyconfig')->get(MigrateToGroups::CONFIG_NAME, false);
if (null !== $configVar) {
return (bool)$configVar->data;
}
return false; // @codeCoverageIgnore
}
/**
@@ -100,11 +96,7 @@ class BackToJournals extends Command
private function isExecuted(): bool
{
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) {
return (bool)$configVar->data;
}
return false; // @codeCoverageIgnore
}
/**