Add interface for journal collector.

This commit is contained in:
James Cole 2016-11-08 20:36:09 +01:00
parent 49cc8a97a3
commit a08dfe1e3c
2 changed files with 157 additions and 27 deletions

View File

@ -27,7 +27,7 @@ use Log;
* *
* @package FireflyIII\Helpers\Collector * @package FireflyIII\Helpers\Collector
*/ */
class JournalCollector class JournalCollector implements JournalCollectorInterface
{ {
/** @var int */ /** @var int */
@ -152,9 +152,9 @@ class JournalCollector
/** /**
* @param Collection $accounts * @param Collection $accounts
* *
* @return JournalCollector * @return JournalCollectorInterface
*/ */
public function setAccounts(Collection $accounts): JournalCollector public function setAccounts(Collection $accounts): JournalCollectorInterface
{ {
if ($accounts->count() > 0) { if ($accounts->count() > 0) {
$accountIds = $accounts->pluck('id')->toArray(); $accountIds = $accounts->pluck('id')->toArray();
@ -169,9 +169,9 @@ class JournalCollector
} }
/** /**
* @return JournalCollector * @return JournalCollectorInterface
*/ */
public function setAllAssetAccounts(): JournalCollector public function setAllAssetAccounts(): JournalCollectorInterface
{ {
/** @var AccountRepositoryInterface $repository */ /** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class, [$this->user]); $repository = app(AccountRepositoryInterface::class, [$this->user]);
@ -191,9 +191,9 @@ class JournalCollector
/** /**
* @param Collection $bills * @param Collection $bills
* *
* @return JournalCollector * @return JournalCollectorInterface
*/ */
public function setBills(Collection $bills): JournalCollector public function setBills(Collection $bills): JournalCollectorInterface
{ {
if ($bills->count() > 0) { if ($bills->count() > 0) {
$billIds = $bills->pluck('id')->toArray(); $billIds = $bills->pluck('id')->toArray();
@ -207,9 +207,9 @@ class JournalCollector
/** /**
* @param Budget $budget * @param Budget $budget
* *
* @return JournalCollector * @return JournalCollectorInterface
*/ */
public function setBudget(Budget $budget): JournalCollector public function setBudget(Budget $budget): JournalCollectorInterface
{ {
$this->joinBudgetTables(); $this->joinBudgetTables();
@ -226,9 +226,9 @@ class JournalCollector
/** /**
* @param Category $category * @param Category $category
* *
* @return JournalCollector * @return JournalCollectorInterface
*/ */
public function setCategory(Category $category): JournalCollector public function setCategory(Category $category): JournalCollectorInterface
{ {
$this->joinCategoryTables(); $this->joinCategoryTables();
@ -245,9 +245,9 @@ class JournalCollector
/** /**
* @param int $limit * @param int $limit
* *
* @return JournalCollector * @return JournalCollectorInterface
*/ */
public function setLimit(int $limit): JournalCollector public function setLimit(int $limit): JournalCollectorInterface
{ {
$this->limit = $limit; $this->limit = $limit;
$this->query->limit($limit); $this->query->limit($limit);
@ -259,9 +259,9 @@ class JournalCollector
/** /**
* @param int $offset * @param int $offset
* *
* @return JournalCollector * @return JournalCollectorInterface
*/ */
public function setOffset(int $offset): JournalCollector public function setOffset(int $offset): JournalCollectorInterface
{ {
$this->offset = $offset; $this->offset = $offset;
@ -271,9 +271,9 @@ class JournalCollector
/** /**
* @param int $page * @param int $page
* *
* @return JournalCollector * @return JournalCollectorInterface
*/ */
public function setPage(int $page): JournalCollector public function setPage(int $page): JournalCollectorInterface
{ {
$this->page = $page; $this->page = $page;
@ -299,9 +299,9 @@ class JournalCollector
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end
* *
* @return JournalCollector * @return JournalCollectorInterface
*/ */
public function setRange(Carbon $start, Carbon $end): JournalCollector public function setRange(Carbon $start, Carbon $end): JournalCollectorInterface
{ {
if ($start <= $end) { if ($start <= $end) {
$this->query->where('transaction_journals.date', '>=', $start->format('Y-m-d')); $this->query->where('transaction_journals.date', '>=', $start->format('Y-m-d'));
@ -314,9 +314,9 @@ class JournalCollector
/** /**
* @param Tag $tag * @param Tag $tag
* *
* @return JournalCollector * @return JournalCollectorInterface
*/ */
public function setTag(Tag $tag): JournalCollector public function setTag(Tag $tag): JournalCollectorInterface
{ {
$this->joinTagTables(); $this->joinTagTables();
$this->query->where('tag_transaction_journal.tag_id', $tag->id); $this->query->where('tag_transaction_journal.tag_id', $tag->id);
@ -327,9 +327,9 @@ class JournalCollector
/** /**
* @param array $types * @param array $types
* *
* @return JournalCollector * @return JournalCollectorInterface
*/ */
public function setTypes(array $types): JournalCollector public function setTypes(array $types): JournalCollectorInterface
{ {
if (count($types) > 0) { if (count($types) > 0) {
$this->query->whereIn('transaction_types.type', $types); $this->query->whereIn('transaction_types.type', $types);
@ -339,9 +339,9 @@ class JournalCollector
} }
/** /**
* @return JournalCollector * @return JournalCollectorInterface
*/ */
public function withoutBudget(): JournalCollector public function withoutBudget(): JournalCollectorInterface
{ {
$this->joinBudgetTables(); $this->joinBudgetTables();
@ -356,9 +356,9 @@ class JournalCollector
} }
/** /**
* @return JournalCollector * @return JournalCollectorInterface
*/ */
public function withoutCategory(): JournalCollector public function withoutCategory(): JournalCollectorInterface
{ {
$this->joinCategoryTables(); $this->joinCategoryTables();

View File

@ -0,0 +1,130 @@
<?php
/**
* JournalCollectorInterface.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Helpers\Collector;
use Carbon\Carbon;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\Tag;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
/**
* Interface JournalCollectorInterface
*
* @package FireflyIII\Helpers\Collector
*/
interface JournalCollectorInterface
{
/**
* @return int
*/
public function count(): int;
/**
* @return Collection
*/
public function getJournals(): Collection;
/**
* @return LengthAwarePaginator
*/
public function getPaginatedJournals():LengthAwarePaginator;
/**
* @param Collection $accounts
*
* @return JournalCollectorInterface
*/
public function setAccounts(Collection $accounts): JournalCollectorInterface;
/**
* @return JournalCollectorInterface
*/
public function setAllAssetAccounts(): JournalCollectorInterface;
/**
* @param Collection $bills
*
* @return JournalCollectorInterface
*/
public function setBills(Collection $bills): JournalCollectorInterface;
/**
* @param Budget $budget
*
* @return JournalCollectorInterface
*/
public function setBudget(Budget $budget): JournalCollectorInterface;
/**
* @param Category $category
*
* @return JournalCollectorInterface
*/
public function setCategory(Category $category): JournalCollectorInterface;
/**
* @param int $limit
*
* @return JournalCollectorInterface
*/
public function setLimit(int $limit): JournalCollectorInterface;
/**
* @param int $offset
*
* @return JournalCollectorInterface
*/
public function setOffset(int $offset): JournalCollectorInterface;
/**
* @param int $page
*
* @return JournalCollectorInterface
*/
public function setPage(int $page): JournalCollectorInterface;
/**
* @param Carbon $start
* @param Carbon $end
*
* @return JournalCollectorInterface
*/
public function setRange(Carbon $start, Carbon $end): JournalCollectorInterface;
/**
* @param Tag $tag
*
* @return JournalCollectorInterface
*/
public function setTag(Tag $tag): JournalCollectorInterface;
/**
* @param array $types
*
* @return JournalCollectorInterface
*/
public function setTypes(array $types): JournalCollectorInterface;
/**
* @return JournalCollectorInterface
*/
public function withoutBudget(): JournalCollectorInterface;
/**
* @return JournalCollectorInterface
*/
public function withoutCategory(): JournalCollectorInterface;
}