mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-24 06:43:23 +00:00
Type hinting.
This commit is contained in:
@@ -295,7 +295,8 @@ class RuleController extends Controller
|
|||||||
$limit = Config::get('firefly.test-triggers.limit');
|
$limit = Config::get('firefly.test-triggers.limit');
|
||||||
$range = Config::get('firefly.test-triggers.range');
|
$range = Config::get('firefly.test-triggers.range');
|
||||||
|
|
||||||
$matcher = new TransactionMatcher;
|
/** @var TransactionMatcher $matcher */
|
||||||
|
$matcher = app('FireflyIII\Rules\TransactionMatcher');
|
||||||
$matcher->setLimit($limit);
|
$matcher->setLimit($limit);
|
||||||
$matcher->setRange($range);
|
$matcher->setRange($range);
|
||||||
$matcher->setTriggers($triggers);
|
$matcher->setTriggers($triggers);
|
||||||
|
@@ -27,22 +27,38 @@ class TransactionMatcher
|
|||||||
private $limit = 10;
|
private $limit = 10;
|
||||||
/** @var int Maximum number of transaction to search in (for performance reasons) * */
|
/** @var int Maximum number of transaction to search in (for performance reasons) * */
|
||||||
private $range = 200;
|
private $range = 200;
|
||||||
|
/** @var JournalRepositoryInterface */
|
||||||
|
private $repository;
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $transactionTypes = [TransactionType::DEPOSIT, TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
|
private $transactionTypes = [TransactionType::DEPOSIT, TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
|
||||||
/** @var array List of triggers to match */
|
/** @var array List of triggers to match */
|
||||||
private $triggers = [];
|
private $triggers = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find matching transactions for the current set of triggers
|
* TransactionMatcher constructor. Typehint the repository.
|
||||||
|
*
|
||||||
|
* @param JournalRepositoryInterface $repository
|
||||||
|
*/
|
||||||
|
public function __construct(JournalRepositoryInterface $repository)
|
||||||
|
{
|
||||||
|
$this->repository = $repository;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will search the user's transaction journal (with an upper limit of $range) for
|
||||||
|
* transaction journals matching the given $triggers. This is accomplished by trying to fire these
|
||||||
|
* triggers onto each transaction journal until enough matches are found ($limit).
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function findMatchingTransactions(): Collection
|
public function findMatchingTransactions(): Collection
|
||||||
{
|
{
|
||||||
/** @var JournalRepositoryInterface $repository */
|
if (count($this->triggers) === 0) {
|
||||||
$repository = app('FireflyIII\Repositories\Journal\JournalRepositoryInterface');
|
return new Collection;
|
||||||
$pagesize = min($this->range / 2, $this->limit * 2);
|
}
|
||||||
|
$pagesize = min($this->range / 2, $this->limit * 2);
|
||||||
|
|
||||||
// Variables used within the loop
|
// Variables used within the loop
|
||||||
$processed = 0;
|
$processed = 0;
|
||||||
@@ -57,7 +73,7 @@ class TransactionMatcher
|
|||||||
do {
|
do {
|
||||||
// Fetch a batch of transactions from the database
|
// Fetch a batch of transactions from the database
|
||||||
$offset = $page > 0 ? ($page - 1) * $pagesize : 0;
|
$offset = $page > 0 ? ($page - 1) * $pagesize : 0;
|
||||||
$set = $repository->getCollectionOfTypes($this->transactionTypes, $offset, $pagesize);
|
$set = $this->repository->getCollectionOfTypes($this->transactionTypes, $offset, $pagesize);
|
||||||
|
|
||||||
// Filter transactions that match the given triggers.
|
// Filter transactions that match the given triggers.
|
||||||
$filtered = $set->filter(
|
$filtered = $set->filter(
|
||||||
|
Reference in New Issue
Block a user