Various code cleanup and fixed alignments.

This commit is contained in:
James Cole
2024-01-01 14:43:56 +01:00
parent 1368aafe5f
commit f963ac63f1
443 changed files with 3668 additions and 3672 deletions

View File

@@ -50,7 +50,7 @@ class ApplyRules extends Command
protected $description = 'This command will apply your rules and rule groups on a selection of your transactions.';
protected $signature
= 'firefly-iii:apply-rules
= 'firefly-iii:apply-rules
{--user=1 : The user ID.}
{--token= : The user\'s access token.}
{--accounts= : A comma-separated list of asset accounts or liabilities to apply your rules to.}
@@ -77,7 +77,7 @@ class ApplyRules extends Command
*/
public function handle(): int
{
$start = microtime(true);
$start = microtime(true);
$this->stupidLaravel();
if (!$this->verifyAccessToken()) {
$this->friendlyError('Invalid access token.');
@@ -89,19 +89,19 @@ class ApplyRules extends Command
$this->ruleRepository->setUser($this->getUser());
$this->ruleGroupRepository->setUser($this->getUser());
$result = $this->verifyInput();
$result = $this->verifyInput();
if (false === $result) {
return 1;
}
$this->allRules = $this->option('all_rules');
$this->allRules = $this->option('all_rules');
// always get all the rules of the user.
$this->grabAllRules();
// loop all groups and rules and indicate if they're included:
$rulesToApply = $this->getRulesToApply();
$count = $rulesToApply->count();
$rulesToApply = $this->getRulesToApply();
$count = $rulesToApply->count();
if (0 === $count) {
$this->friendlyError('No rules or rule groups have been included.');
$this->friendlyWarning('Make a selection using:');
@@ -114,7 +114,7 @@ class ApplyRules extends Command
// create new rule engine:
/** @var RuleEngineInterface $ruleEngine */
$ruleEngine = app(RuleEngineInterface::class);
$ruleEngine = app(RuleEngineInterface::class);
$ruleEngine->setRules($rulesToApply);
$ruleEngine->setUser($this->getUser());
@@ -123,7 +123,7 @@ class ApplyRules extends Command
foreach ($this->accounts as $account) {
$filterAccountList[] = $account->id;
}
$list = implode(',', $filterAccountList);
$list = implode(',', $filterAccountList);
$ruleEngine->addOperator(['type' => 'account_id', 'value' => $list]);
// add the date as a filter:
@@ -137,7 +137,7 @@ class ApplyRules extends Command
$ruleEngine->fire();
$this->friendlyLine('');
$end = round(microtime(true) - $start, 2);
$end = round(microtime(true) - $start, 2);
$this->friendlyPositive(sprintf('Done in %s seconds!', $end));
return 0;
@@ -187,14 +187,14 @@ class ApplyRules extends Command
*/
private function verifyInputAccounts(): bool
{
$accountString = $this->option('accounts');
$accountString = $this->option('accounts');
if (null === $accountString || '' === $accountString) {
$this->friendlyError('Please use the --accounts option to indicate the accounts to apply rules to.');
return false;
}
$finalList = new Collection();
$accountList = explode(',', $accountString);
$finalList = new Collection();
$accountList = explode(',', $accountString);
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
@@ -212,7 +212,7 @@ class ApplyRules extends Command
return false;
}
$this->accounts = $finalList;
$this->accounts = $finalList;
return true;
}
@@ -224,7 +224,7 @@ class ApplyRules extends Command
// can be empty.
return true;
}
$ruleGroupList = explode(',', $ruleGroupString);
$ruleGroupList = explode(',', $ruleGroupString);
foreach ($ruleGroupList as $ruleGroupId) {
$ruleGroup = $this->ruleGroupRepository->find((int)$ruleGroupId);
@@ -246,7 +246,7 @@ class ApplyRules extends Command
// can be empty.
return true;
}
$ruleList = explode(',', $ruleString);
$ruleList = explode(',', $ruleString);
foreach ($ruleList as $ruleId) {
$rule = $this->ruleRepository->find((int)$ruleId);
@@ -264,13 +264,13 @@ class ApplyRules extends Command
private function verifyInputDates(): void
{
// parse start date.
$inputStart = today(config('app.timezone'))->startOfMonth();
$startString = $this->option('start_date');
$inputStart = today(config('app.timezone'))->startOfMonth();
$startString = $this->option('start_date');
if (null === $startString) {
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
$repository->setUser($this->getUser());
$first = $repository->firstNull();
$first = $repository->firstNull();
if (null !== $first) {
$inputStart = $first->date;
}
@@ -280,8 +280,8 @@ class ApplyRules extends Command
}
// parse end date
$inputEnd = today(config('app.timezone'));
$endString = $this->option('end_date');
$inputEnd = today(config('app.timezone'));
$endString = $this->option('end_date');
if (null !== $endString && '' !== $endString) {
$inputEnd = Carbon::createFromFormat('Y-m-d', $endString);
}