mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
PHP7 compatible function definitions.
This commit is contained in:
@@ -7,7 +7,6 @@ use Carbon\Carbon;
|
||||
use DB;
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Sql\Query;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -19,6 +18,10 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
class CategoryRepository implements CategoryRepositoryInterface
|
||||
{
|
||||
const SPENT = 1;
|
||||
const EARNED = 2;
|
||||
|
||||
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
@@ -43,7 +46,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function earnedForAccountsPerMonth(Collection $accounts, Carbon $start, Carbon $end)
|
||||
public function earnedForAccountsPerMonth(Collection $accounts, Carbon $start, Carbon $end): Collection
|
||||
{
|
||||
|
||||
$collection = $this->user->categories()
|
||||
@@ -87,7 +90,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function listCategories()
|
||||
public function listCategories(): Collection
|
||||
{
|
||||
/** @var Collection $set */
|
||||
$set = $this->user->categories()->orderBy('name', 'ASC')->get();
|
||||
@@ -114,7 +117,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function listMultiYear(Collection $categories, Collection $accounts, Carbon $start, Carbon $end)
|
||||
public function listMultiYear(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): Collection
|
||||
{
|
||||
|
||||
$set = $this->user->categories()
|
||||
@@ -152,7 +155,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function listNoCategory(Carbon $start, Carbon $end)
|
||||
public function listNoCategory(Carbon $start, Carbon $end): Collection
|
||||
{
|
||||
return $this->user
|
||||
->transactionjournals()
|
||||
@@ -177,7 +180,7 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function spentForAccountsPerMonth(Collection $accounts, Carbon $start, Carbon $end)
|
||||
public function spentForAccountsPerMonth(Collection $accounts, Carbon $start, Carbon $end): Collection
|
||||
{
|
||||
$accountIds = $accounts->pluck('id')->toArray();
|
||||
$query = $this->user->categories()
|
||||
@@ -228,9 +231,9 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function sumEarnedNoCategory(Collection $accounts, Carbon $start, Carbon $end)
|
||||
public function sumEarnedNoCategory(Collection $accounts, Carbon $start, Carbon $end): string
|
||||
{
|
||||
return $this->sumNoCategory($accounts, $start, $end, Query::EARNED);
|
||||
return $this->sumNoCategory($accounts, $start, $end, self::EARNED);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -243,9 +246,9 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function sumSpentNoCategory(Collection $accounts, Carbon $start, Carbon $end)
|
||||
public function sumSpentNoCategory(Collection $accounts, Carbon $start, Carbon $end): string
|
||||
{
|
||||
return $this->sumNoCategory($accounts, $start, $end, Query::SPENT);
|
||||
return $this->sumNoCategory($accounts, $start, $end, self::SPENT);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,10 +262,10 @@ class CategoryRepository implements CategoryRepositoryInterface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function sumNoCategory(Collection $accounts, Carbon $start, Carbon $end, $group = Query::EARNED)
|
||||
protected function sumNoCategory(Collection $accounts, Carbon $start, Carbon $end, $group = self::EARNED)
|
||||
{
|
||||
$accountIds = $accounts->pluck('id')->toArray();
|
||||
if ($group == Query::EARNED) {
|
||||
if ($group == self::EARNED) {
|
||||
$types = [TransactionType::DEPOSIT];
|
||||
} else {
|
||||
$types = [TransactionType::WITHDRAWAL];
|
||||
|
@@ -26,14 +26,14 @@ interface CategoryRepositoryInterface
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function earnedForAccountsPerMonth(Collection $accounts, Carbon $start, Carbon $end);
|
||||
public function earnedForAccountsPerMonth(Collection $accounts, Carbon $start, Carbon $end): Collection;
|
||||
|
||||
/**
|
||||
* Returns a list of all the categories belonging to a user.
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function listCategories();
|
||||
public function listCategories(): Collection;
|
||||
|
||||
/**
|
||||
* This method returns a very special collection for each category:
|
||||
@@ -49,7 +49,7 @@ interface CategoryRepositoryInterface
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function listMultiYear(Collection $categories, Collection $accounts, Carbon $start, Carbon $end);
|
||||
public function listMultiYear(Collection $categories, Collection $accounts, Carbon $start, Carbon $end): Collection;
|
||||
|
||||
/**
|
||||
* Returns a list of transaction journals in the range (all types, all accounts) that have no category
|
||||
@@ -60,7 +60,7 @@ interface CategoryRepositoryInterface
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function listNoCategory(Carbon $start, Carbon $end);
|
||||
public function listNoCategory(Carbon $start, Carbon $end): Collection;
|
||||
|
||||
/**
|
||||
* Returns a collection of Categories appended with the amount of money that has been spent
|
||||
@@ -73,7 +73,7 @@ interface CategoryRepositoryInterface
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function spentForAccountsPerMonth(Collection $accounts, Carbon $start, Carbon $end);
|
||||
public function spentForAccountsPerMonth(Collection $accounts, Carbon $start, Carbon $end): Collection;
|
||||
|
||||
/**
|
||||
* Returns the total amount of money related to transactions without any category connected to
|
||||
@@ -85,7 +85,7 @@ interface CategoryRepositoryInterface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function sumEarnedNoCategory(Collection $accounts, Carbon $start, Carbon $end);
|
||||
public function sumEarnedNoCategory(Collection $accounts, Carbon $start, Carbon $end): string;
|
||||
|
||||
/**
|
||||
* Returns the total amount of money related to transactions without any category connected to
|
||||
@@ -97,6 +97,6 @@ interface CategoryRepositoryInterface
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function sumSpentNoCategory(Collection $accounts, Carbon $start, Carbon $end);
|
||||
public function sumSpentNoCategory(Collection $accounts, Carbon $start, Carbon $end): string;
|
||||
|
||||
}
|
||||
|
@@ -37,7 +37,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countJournals(Category $category)
|
||||
public function countJournals(Category $category): int
|
||||
{
|
||||
return $category->transactionjournals()->count();
|
||||
|
||||
@@ -51,7 +51,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countJournalsInRange(Category $category, Carbon $start, Carbon $end)
|
||||
public function countJournalsInRange(Category $category, Carbon $start, Carbon $end): int
|
||||
{
|
||||
return $category->transactionjournals()->before($end)->after($start)->count();
|
||||
}
|
||||
@@ -59,9 +59,9 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function destroy(Category $category)
|
||||
public function destroy(Category $category): bool
|
||||
{
|
||||
$category->delete();
|
||||
|
||||
@@ -82,7 +82,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function earnedPerDay(Category $category, Carbon $start, Carbon $end)
|
||||
public function earnedPerDay(Category $category, Carbon $start, Carbon $end): array
|
||||
{
|
||||
/** @var Collection $query */
|
||||
$query = $category->transactionjournals()
|
||||
@@ -123,7 +123,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getFirstActivityDate(Category $category)
|
||||
public function getFirstActivityDate(Category $category): Carbon
|
||||
{
|
||||
/** @var TransactionJournal $first */
|
||||
$first = $category->transactionjournals()->orderBy('date', 'ASC')->first();
|
||||
@@ -141,7 +141,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getJournals(Category $category, $page)
|
||||
public function getJournals(Category $category, $page): Collection
|
||||
{
|
||||
$offset = $page > 0 ? $page * 50 : 0;
|
||||
|
||||
@@ -162,7 +162,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getJournalsForAccountsInRange(Category $category, Collection $accounts, Carbon $start, Carbon $end)
|
||||
public function getJournalsForAccountsInRange(Category $category, Collection $accounts, Carbon $start, Carbon $end): Collection
|
||||
{
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
|
||||
@@ -181,9 +181,9 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return mixed
|
||||
* @return Collection
|
||||
*/
|
||||
public function getJournalsInRange(Category $category, $page, Carbon $start, Carbon $end)
|
||||
public function getJournalsInRange(Category $category, $page, Carbon $start, Carbon $end): Collection
|
||||
{
|
||||
$offset = $page > 0 ? $page * 50 : 0;
|
||||
|
||||
@@ -201,7 +201,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
*
|
||||
* @return Carbon|null
|
||||
*/
|
||||
public function getLatestActivity(Category $category)
|
||||
public function getLatestActivity(Category $category): Carbon
|
||||
{
|
||||
$latest = $category->transactionjournals()
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
@@ -212,7 +212,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
return $latest->date;
|
||||
}
|
||||
|
||||
return null;
|
||||
return new Carbon('1900-01-01');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -229,7 +229,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function spentPerDay(Category $category, Carbon $start, Carbon $end)
|
||||
public function spentPerDay(Category $category, Carbon $start, Carbon $end): array
|
||||
{
|
||||
/** @var Collection $query */
|
||||
$query = $category->transactionjournals()
|
||||
@@ -253,7 +253,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
public function store(array $data)
|
||||
public function store(array $data): Category
|
||||
{
|
||||
$newCategory = Category::firstOrCreateEncrypted(
|
||||
[
|
||||
@@ -272,7 +272,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
public function update(Category $category, array $data)
|
||||
public function update(Category $category, array $data): Category
|
||||
{
|
||||
// update the account:
|
||||
$category->name = $data['name'];
|
||||
|
@@ -20,7 +20,7 @@ interface SingleCategoryRepositoryInterface
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countJournals(Category $category);
|
||||
public function countJournals(Category $category): int;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
@@ -30,14 +30,14 @@ interface SingleCategoryRepositoryInterface
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function countJournalsInRange(Category $category, Carbon $start, Carbon $end);
|
||||
public function countJournalsInRange(Category $category, Carbon $start, Carbon $end): int;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
*/
|
||||
public function destroy(Category $category);
|
||||
public function destroy(Category $category): bool;
|
||||
|
||||
/**
|
||||
* Returns an array with the following key:value pairs:
|
||||
@@ -53,7 +53,7 @@ interface SingleCategoryRepositoryInterface
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function earnedPerDay(Category $category, Carbon $start, Carbon $end);
|
||||
public function earnedPerDay(Category $category, Carbon $start, Carbon $end): array;
|
||||
|
||||
/**
|
||||
* Find a category
|
||||
@@ -69,7 +69,7 @@ interface SingleCategoryRepositoryInterface
|
||||
*
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getFirstActivityDate(Category $category);
|
||||
public function getFirstActivityDate(Category $category): Carbon;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
@@ -77,7 +77,7 @@ interface SingleCategoryRepositoryInterface
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getJournals(Category $category, $page);
|
||||
public function getJournals(Category $category, $page): Collection;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
@@ -88,7 +88,7 @@ interface SingleCategoryRepositoryInterface
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getJournalsForAccountsInRange(Category $category, Collection $accounts, Carbon $start, Carbon $end);
|
||||
public function getJournalsForAccountsInRange(Category $category, Collection $accounts, Carbon $start, Carbon $end): Collection;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
@@ -99,14 +99,14 @@ interface SingleCategoryRepositoryInterface
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getJournalsInRange(Category $category, $page, Carbon $start, Carbon $end);
|
||||
public function getJournalsInRange(Category $category, $page, Carbon $start, Carbon $end): Collection;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return Carbon|null
|
||||
* @return Carbon
|
||||
*/
|
||||
public function getLatestActivity(Category $category);
|
||||
public function getLatestActivity(Category $category): Carbon;
|
||||
|
||||
/**
|
||||
* Returns an array with the following key:value pairs:
|
||||
@@ -122,7 +122,7 @@ interface SingleCategoryRepositoryInterface
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function spentPerDay(Category $category, Carbon $start, Carbon $end);
|
||||
public function spentPerDay(Category $category, Carbon $start, Carbon $end): array;
|
||||
|
||||
|
||||
/**
|
||||
@@ -130,7 +130,7 @@ interface SingleCategoryRepositoryInterface
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
public function store(array $data);
|
||||
public function store(array $data): Category;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
@@ -138,5 +138,5 @@ interface SingleCategoryRepositoryInterface
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
public function update(Category $category, array $data);
|
||||
public function update(Category $category, array $data): Category;
|
||||
}
|
||||
|
Reference in New Issue
Block a user