From 1d2d3523d6773557eaebc4e501b49a8ae9dccf70 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 9 Oct 2016 08:18:47 +0200 Subject: [PATCH] Move CRUD method count() to account repository --- app/Crud/Account/AccountCrud.php | 12 ------------ app/Crud/Account/AccountCrudInterface.php | 7 ------- app/Http/Controllers/HomeController.php | 2 +- app/Http/Controllers/NewUserController.php | 7 ++++--- app/Repositories/Account/AccountRepository.php | 14 ++++++++++++++ .../Account/AccountRepositoryInterface.php | 8 ++++++++ 6 files changed, 27 insertions(+), 23 deletions(-) diff --git a/app/Crud/Account/AccountCrud.php b/app/Crud/Account/AccountCrud.php index 814735dae1..76bcb659e3 100644 --- a/app/Crud/Account/AccountCrud.php +++ b/app/Crud/Account/AccountCrud.php @@ -52,18 +52,6 @@ class AccountCrud implements AccountCrudInterface $this->user = $user; } - /** - * @param array $types - * - * @return int - */ - public function count(array $types):int - { - $count = $this->user->accounts()->accountTypeIn($types)->count(); - - return $count; - } - /** * @param Account $account * @param Account $moveTo diff --git a/app/Crud/Account/AccountCrudInterface.php b/app/Crud/Account/AccountCrudInterface.php index f7e995f020..772bf6afcb 100644 --- a/app/Crud/Account/AccountCrudInterface.php +++ b/app/Crud/Account/AccountCrudInterface.php @@ -24,13 +24,6 @@ use Illuminate\Support\Collection; */ interface AccountCrudInterface { - /** - * @param array $types - * - * @return int - */ - public function count(array $types):int; - /** * @param Account $account * @param Account $moveTo diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 51ef56eac4..bb13eb2fea 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -123,7 +123,7 @@ class HomeController extends Controller { $types = config('firefly.accountTypesByIdentifier.asset'); - $count = $crud->count($types); + $count = $repository->count($types); if ($count == 0) { return redirect(route('new-user.index')); diff --git a/app/Http/Controllers/NewUserController.php b/app/Http/Controllers/NewUserController.php index 974831a0e8..f770a191fa 100644 --- a/app/Http/Controllers/NewUserController.php +++ b/app/Http/Controllers/NewUserController.php @@ -15,6 +15,7 @@ namespace FireflyIII\Http\Controllers; use Carbon\Carbon; use FireflyIII\Crud\Account\AccountCrudInterface; use FireflyIII\Http\Requests\NewUserFormRequest; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; use Preferences; use Session; use View; @@ -36,11 +37,11 @@ class NewUserController extends Controller /** - * @param AccountCrudInterface $crud + * @param AccountRepositoryInterface $repository * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View */ - public function index(AccountCrudInterface $crud) + public function index(AccountRepositoryInterface $repository) { View::share('title', trans('firefly.welcome')); @@ -48,7 +49,7 @@ class NewUserController extends Controller $types = config('firefly.accountTypesByIdentifier.asset'); - $count = $crud->count($types); + $count = $repository->count($types); if ($count > 0) { return redirect(route('index')); diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 73656e48cd..8e4348cba0 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -50,6 +50,20 @@ class AccountRepository implements AccountRepositoryInterface $this->user = $user; } + /** + * Moved here from account CRUD + * + * @param array $types + * + * @return int + */ + public function count(array $types):int + { + $count = $this->user->accounts()->accountTypeIn($types)->count(); + + return $count; + } + /** * This method will call AccountRepositoryInterface::journalsInPeriod and get all withdrawaks made from the given $accounts, * as well as the transfers that move away from those $accounts. This is a slightly sharper selection diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.php index 263a5d1137..855081fba1 100644 --- a/app/Repositories/Account/AccountRepositoryInterface.php +++ b/app/Repositories/Account/AccountRepositoryInterface.php @@ -26,6 +26,14 @@ use Illuminate\Support\Collection; */ interface AccountRepositoryInterface { + /** + * Moved here from account CRUD. + * + * @param array $types + * + * @return int + */ + public function count(array $types): int; /** * This method will call AccountRepositoryInterface::journalsInPeriod and get all withdrawaks made from the given $accounts,