From f99e46bf7533c278cf5258553b81909511016226 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 30 Dec 2015 09:17:14 +0100 Subject: [PATCH] Removed for-loop in favour of "pluck()" aka: RTFM. --- app/Repositories/Category/SingleCategoryRepository.php | 10 ++-------- app/Repositories/Shared/ComponentRepository.php | 6 +----- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/app/Repositories/Category/SingleCategoryRepository.php b/app/Repositories/Category/SingleCategoryRepository.php index 5c115c9ce1..ada1aa5bf6 100644 --- a/app/Repositories/Category/SingleCategoryRepository.php +++ b/app/Repositories/Category/SingleCategoryRepository.php @@ -110,10 +110,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate */ public function earnedInPeriodForAccounts(Category $category, Collection $accounts, Carbon $start, Carbon $end) { - $accountIds = []; - foreach ($accounts as $account) { - $accountIds[] = $account->id; - } + $accountIds = $accounts->pluck('id')->toArray(); $sum = $category ->transactionjournals() @@ -237,10 +234,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate */ public function spentInPeriodForAccounts(Category $category, Collection $accounts, Carbon $start, Carbon $end) { - $accountIds = []; - foreach ($accounts as $account) { - $accountIds[] = $account->id; - } + $accountIds = $accounts->pluck('id')->toArray(); $sum = $category diff --git a/app/Repositories/Shared/ComponentRepository.php b/app/Repositories/Shared/ComponentRepository.php index f9584ef72d..6731c904cb 100644 --- a/app/Repositories/Shared/ComponentRepository.php +++ b/app/Repositories/Shared/ComponentRepository.php @@ -39,11 +39,7 @@ class ComponentRepository return $cache->get(); // @codeCoverageIgnore } - $ids = []; - /** @var Account $account */ - foreach ($accounts as $account) { - $ids[] = $account->id; - } + $ids = $accounts->pluck('id')->toArray(); $entry = $object->transactionjournals()