Reformat various code.

This commit is contained in:
James Cole
2022-03-29 15:00:29 +02:00
parent d1a09ff33b
commit d04efb8325
81 changed files with 662 additions and 662 deletions

View File

@@ -52,12 +52,12 @@ class AppendNotes implements ActionInterface
{
$dbNote = Note
::
where('noteable_id', (int)$journal['transaction_journal_id'])
where('noteable_id', (int) $journal['transaction_journal_id'])
->where('noteable_type', TransactionJournal::class)
->first(['notes.*']);
if (null === $dbNote) {
$dbNote = new Note;
$dbNote->noteable_id = (int)$journal['transaction_journal_id'];
$dbNote->noteable_id = (int) $journal['transaction_journal_id'];
$dbNote->noteable_type = TransactionJournal::class;
$dbNote->text = '';
}

View File

@@ -58,7 +58,7 @@ class LinkToBill implements ActionInterface
/** @var BillRepositoryInterface $repository */
$repository = app(BillRepositoryInterface::class);
$repository->setUser($user);
$billName = (string)$this->action->action_value;
$billName = (string) $this->action->action_value;
$bill = $repository->findByName($billName);
if (null !== $bill && $journal['transaction_type_type'] === TransactionType::WITHDRAWAL) {

View File

@@ -52,12 +52,12 @@ class PrependNotes implements ActionInterface
{
$dbNote = Note
::
where('noteable_id', (int)$journal['transaction_journal_id'])
where('noteable_id', (int) $journal['transaction_journal_id'])
->where('noteable_type', TransactionJournal::class)
->first(['notes.*']);
if (null === $dbNote) {
$dbNote = new Note;
$dbNote->noteable_id = (int)$journal['transaction_journal_id'];
$dbNote->noteable_id = (int) $journal['transaction_journal_id'];
$dbNote->noteable_type = TransactionJournal::class;
$dbNote->text = '';
}

View File

@@ -58,7 +58,7 @@ class SetDestinationAccount implements ActionInterface
$user = User::find($journal['user_id']);
$type = $journal['transaction_type_type'];
/** @var TransactionJournal|null $object */
$object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']);
$object = $user->transactionJournals()->find((int) $journal['transaction_journal_id']);
$this->repository = app(AccountRepositoryInterface::class);
if (null === $object) {
@@ -95,7 +95,7 @@ class SetDestinationAccount implements ActionInterface
return false;
}
if (null !== $newAccount && (int)$newAccount->id === (int)$source->account_id) {
if (null !== $newAccount && (int) $newAccount->id === (int) $source->account_id) {
Log::error(
sprintf(
'New destination account ID #%d and current source account ID #%d are the same. Do nothing.', $newAccount->id,

View File

@@ -61,7 +61,7 @@ class UpdatePiggybank implements ActionInterface
// refresh the transaction type.
$user = User::find($journal['user_id']);
$journalObj = $user->transactionJournals()->find($journal['transaction_journal_id']);
$type = TransactionType::find((int)$journalObj->transaction_type_id);
$type = TransactionType::find((int) $journalObj->transaction_type_id);
$journal['transaction_type_type'] = $type->type;
if (TransactionType::TRANSFER !== $journal['transaction_type_type']) {
@@ -86,13 +86,13 @@ class UpdatePiggybank implements ActionInterface
/** @var Transaction $destination */
$destination = Transaction::where('transaction_journal_id', $journal['transaction_journal_id'])->where('amount', '>', 0)->first();
if ((int)$source->account_id === (int)$piggyBank->account_id) {
if ((int) $source->account_id === (int) $piggyBank->account_id) {
Log::debug('Piggy bank account is linked to source, so remove amount.');
$this->removeAmount($journal, $piggyBank, $destination->amount);
return true;
}
if ((int)$destination->account_id === (int)$piggyBank->account_id) {
if ((int) $destination->account_id === (int) $piggyBank->account_id) {
Log::debug('Piggy bank account is linked to source, so add amount.');
$this->addAmount($journal, $piggyBank, $destination->amount);

View File

@@ -86,84 +86,6 @@ class SearchRuleEngine implements RuleEngineInterface
return $collection->unique();
}
/**
* @inheritDoc
* @throws FireflyException
*/
public function fire(): void
{
$this->resultCount = [];
Log::debug('SearchRuleEngine::fire()!');
// if rules and no rule groups, file each rule separately.
if (0 !== $this->rules->count()) {
Log::debug(sprintf('SearchRuleEngine:: found %d rule(s) to fire.', $this->rules->count()));
foreach ($this->rules as $rule) {
$this->fireRule($rule);
}
Log::debug('SearchRuleEngine:: done processing all rules!');
return;
}
if (0 !== $this->groups->count()) {
Log::debug(sprintf('SearchRuleEngine:: found %d rule group(s) to fire.', $this->groups->count()));
// fire each group:
/** @var RuleGroup $group */
foreach ($this->groups as $group) {
$this->fireGroup($group);
}
}
Log::debug('SearchRuleEngine:: done processing all rules!');
}
/**
* Return the number of changed transactions from the previous "fire" action.
*
* @return int
*/
public function getResults(): int
{
return count($this->resultCount);
}
/**
* @inheritDoc
*/
public function setRuleGroups(Collection $ruleGroups): void
{
Log::debug(__METHOD__);
foreach ($ruleGroups as $group) {
if ($group instanceof RuleGroup) {
Log::debug(sprintf('Adding a rule group to the SearchRuleEngine: #%d ("%s")', $group->id, $group->title));
$this->groups->push($group);
}
}
}
/**
* @inheritDoc
*/
public function setRules(Collection $rules): void
{
Log::debug(__METHOD__);
foreach ($rules as $rule) {
if ($rule instanceof Rule) {
Log::debug(sprintf('Adding a rule to the SearchRuleEngine: #%d ("%s")', $rule->id, $rule->title));
$this->rules->push($rule);
}
}
}
/**
* @inheritDoc
*/
public function setUser(User $user): void
{
$this->user = $user;
$this->operators = [];
}
/**
* Finds the transactions a strict rule will execute on.
*
@@ -266,7 +188,7 @@ class SearchRuleEngine implements RuleEngineInterface
$journalId = 0;
foreach ($array as $triggerName => $values) {
if ('journal_id' === $triggerName && is_array($values) && 1 === count($values)) {
$journalId = (int)trim(($values[0] ?? '"0"'), '"'); // follows format "123".
$journalId = (int) trim(($values[0] ?? '"0"'), '"'); // follows format "123".
Log::debug(sprintf('Found journal ID #%d', $journalId));
}
}
@@ -365,6 +287,36 @@ class SearchRuleEngine implements RuleEngineInterface
return $unique;
}
/**
* @inheritDoc
* @throws FireflyException
*/
public function fire(): void
{
$this->resultCount = [];
Log::debug('SearchRuleEngine::fire()!');
// if rules and no rule groups, file each rule separately.
if (0 !== $this->rules->count()) {
Log::debug(sprintf('SearchRuleEngine:: found %d rule(s) to fire.', $this->rules->count()));
foreach ($this->rules as $rule) {
$this->fireRule($rule);
}
Log::debug('SearchRuleEngine:: done processing all rules!');
return;
}
if (0 !== $this->groups->count()) {
Log::debug(sprintf('SearchRuleEngine:: found %d rule group(s) to fire.', $this->groups->count()));
// fire each group:
/** @var RuleGroup $group */
foreach ($this->groups as $group) {
$this->fireGroup($group);
}
}
Log::debug('SearchRuleEngine:: done processing all rules!');
}
/**
* Returns true if the rule has been triggered.
*
@@ -460,7 +412,7 @@ class SearchRuleEngine implements RuleEngineInterface
$actions = $rule->ruleActions()->get();
/** @var RuleAction $ruleAction */
foreach ($actions as $ruleAction) {
if(false === $ruleAction->active) {
if (false === $ruleAction->active) {
continue;
}
$break = $this->processRuleAction($ruleAction, $transaction);
@@ -553,4 +505,52 @@ class SearchRuleEngine implements RuleEngineInterface
return $all;
}
/**
* Return the number of changed transactions from the previous "fire" action.
*
* @return int
*/
public function getResults(): int
{
return count($this->resultCount);
}
/**
* @inheritDoc
*/
public function setRuleGroups(Collection $ruleGroups): void
{
Log::debug(__METHOD__);
foreach ($ruleGroups as $group) {
if ($group instanceof RuleGroup) {
Log::debug(sprintf('Adding a rule group to the SearchRuleEngine: #%d ("%s")', $group->id, $group->title));
$this->groups->push($group);
}
}
}
/**
* @inheritDoc
*/
public function setRules(Collection $rules): void
{
Log::debug(__METHOD__);
foreach ($rules as $rule) {
if ($rule instanceof Rule) {
Log::debug(sprintf('Adding a rule to the SearchRuleEngine: #%d ("%s")', $rule->id, $rule->title));
$this->rules->push($rule);
}
}
}
/**
* @inheritDoc
*/
public function setUser(User $user): void
{
$this->user = $user;
$this->operators = [];
}
}