mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 10:33:30 +00:00
Small code clean up [skip ci]
This commit is contained in:
@@ -12,6 +12,7 @@ namespace FireflyIII\Rules;
|
|||||||
|
|
||||||
use FireflyIII\Models\Rule;
|
use FireflyIII\Models\Rule;
|
||||||
use FireflyIII\Models\TransactionType;
|
use FireflyIII\Models\TransactionType;
|
||||||
|
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class TransactionMatcher is used to find a list of
|
* Class TransactionMatcher is used to find a list of
|
||||||
@@ -21,20 +22,17 @@ use FireflyIII\Models\TransactionType;
|
|||||||
*/
|
*/
|
||||||
class TransactionMatcher
|
class TransactionMatcher
|
||||||
{
|
{
|
||||||
/** @var array List of triggers to match*/
|
|
||||||
protected $triggers = [];
|
|
||||||
|
|
||||||
/** @var int Maximum number of transaction to search in (for performance reasons) * */
|
/** @var int Maximum number of transaction to search in (for performance reasons) * */
|
||||||
protected $maxTransactionsToSearchIn = 1000;
|
protected $maxTransactionsToSearchIn = 1000;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
protected $transactionTypes = [TransactionType::DEPOSIT, TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
|
protected $transactionTypes = [TransactionType::DEPOSIT, TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
|
||||||
|
/** @var array List of triggers to match */
|
||||||
|
protected $triggers = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor
|
* Default constructor
|
||||||
*
|
*
|
||||||
* @param Rule $rule
|
* @param $triggers
|
||||||
* @param TransactionJournal $journal
|
|
||||||
*/
|
*/
|
||||||
public function __construct($triggers)
|
public function __construct($triggers)
|
||||||
{
|
{
|
||||||
@@ -43,9 +41,13 @@ class TransactionMatcher
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Find matching transactions for the current set of triggers
|
* Find matching transactions for the current set of triggers
|
||||||
* @param number $maxResults The maximum number of transactions returned
|
*
|
||||||
|
* @param int $maxResults The maximum number of transactions returned
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function findMatchingTransactions($maxResults = 50) {
|
public function findMatchingTransactions($maxResults = 50)
|
||||||
|
{
|
||||||
/** @var JournalRepositoryInterface $repository */
|
/** @var JournalRepositoryInterface $repository */
|
||||||
$repository = app('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
|
$repository = app('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
|
||||||
|
|
||||||
@@ -78,10 +80,13 @@ class TransactionMatcher
|
|||||||
$transactions = $repository->getJournalsOfTypes($this->transactionTypes, $offset, $page, $pagesize)->getCollection()->all();
|
$transactions = $repository->getJournalsOfTypes($this->transactionTypes, $offset, $page, $pagesize)->getCollection()->all();
|
||||||
|
|
||||||
// Filter transactions that match the rule
|
// Filter transactions that match the rule
|
||||||
$matchingTransactions += array_filter( $transactions, function($transaction) {
|
$matchingTransactions += array_filter(
|
||||||
|
$transactions, function ($transaction) {
|
||||||
$processor = new Processor(new Rule, $transaction);
|
$processor = new Processor(new Rule, $transaction);
|
||||||
|
|
||||||
return $processor->isTriggeredBy($this->triggers);
|
return $processor->isTriggeredBy($this->triggers);
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// Update counters
|
// Update counters
|
||||||
$page++;
|
$page++;
|
||||||
@@ -103,45 +108,60 @@ class TransactionMatcher
|
|||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getTriggers() {
|
public function getTransactionLimit()
|
||||||
return $this->triggers;
|
{
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array $triggers
|
|
||||||
*/
|
|
||||||
public function setTriggers($triggers) {
|
|
||||||
$this->triggers = $triggers;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function getTransactionLimit() {
|
|
||||||
return $this->maxTransactionsToSearchIn;
|
return $this->maxTransactionsToSearchIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int $limit
|
|
||||||
*/
|
|
||||||
public function setTransactionLimit(int $limit) {
|
|
||||||
$this->maxTransactionsToSearchIn = $limit;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getTransactionTypes() {
|
public function getTransactionTypes()
|
||||||
|
{
|
||||||
return $this->transactionTypes;
|
return $this->transactionTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $transactionTypes
|
* @param array $transactionTypes
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setTransactionTypes(array $transactionTypes) {
|
public function setTransactionTypes(array $transactionTypes)
|
||||||
|
{
|
||||||
$this->transactionTypes = $transactionTypes;
|
$this->transactionTypes = $transactionTypes;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getTriggers()
|
||||||
|
{
|
||||||
|
return $this->triggers;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $triggers
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setTriggers($triggers)
|
||||||
|
{
|
||||||
|
$this->triggers = $triggers;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $limit
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setTransactionLimit(int $limit)
|
||||||
|
{
|
||||||
|
$this->maxTransactionsToSearchIn = $limit;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user