From bea321939e7dd03e36acd24369c01bc1e9342577 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 29 Mar 2015 21:27:51 +0200 Subject: [PATCH] Code rearrange and optimise. --- app/Events/JournalCreated.php | 27 +++--- app/Events/JournalSaved.php | 25 +++--- .../Events/ConnectJournalToPiggyBank.php | 5 +- app/Handlers/Events/RescanJournal.php | 2 +- .../Events/UpdateJournalConnection.php | 4 +- .../Reminders/ReminderHelperInterface.php | 7 +- app/Http/Controllers/AccountController.php | 3 +- app/Http/Controllers/Auth/AuthController.php | 2 +- app/Http/Controllers/BudgetController.php | 14 ++-- app/Http/Controllers/CategoryController.php | 30 ++++--- .../Controllers/GoogleChartController.php | 18 ++-- app/Http/Controllers/JsonController.php | 4 +- app/Http/Middleware/PiggyBanks.php | 4 +- app/Http/Middleware/ReplaceTestVars.php | 2 +- app/Http/Requests/AccountFormRequest.php | 2 +- app/Http/Requests/ProfileFormRequest.php | 2 +- app/Http/breadcrumbs.php | 6 +- app/Http/routes.php | 4 +- app/Models/Account.php | 3 +- app/Models/AccountMeta.php | 4 +- app/Models/Bill.php | 2 +- app/Models/Component.php | 2 +- app/Models/PiggyBank.php | 5 +- app/Providers/EventServiceProvider.php | 3 +- .../Account/AccountRepository.php | 7 +- .../Account/AccountRepositoryInterface.php | 9 +- .../Bill/BillRepositoryInterface.php | 5 +- app/Repositories/Budget/BudgetRepository.php | 9 +- .../PiggyBank/PiggyBankRepository.php | 2 +- app/Repositories/PiggyBank/PiggybankPart.php | 5 +- app/Support/Navigation.php | 84 +++++++++---------- app/Support/Search/Search.php | 4 +- app/Support/Search/SearchInterface.php | 3 +- app/Validation/FireflyValidator.php | 2 +- 34 files changed, 155 insertions(+), 155 deletions(-) diff --git a/app/Events/JournalCreated.php b/app/Events/JournalCreated.php index debbefd1b8..0fc11fb491 100644 --- a/app/Events/JournalCreated.php +++ b/app/Events/JournalCreated.php @@ -1,7 +1,5 @@ journal = $journal; + /** + * Create a new event instance. + * + * @return void + */ + public function __construct(TransactionJournal $journal, $piggyBankId) + { + // + $this->journal = $journal; $this->piggyBankId = $piggyBankId; - } + } } diff --git a/app/Events/JournalSaved.php b/app/Events/JournalSaved.php index e618861169..25471ca809 100644 --- a/app/Events/JournalSaved.php +++ b/app/Events/JournalSaved.php @@ -1,25 +1,24 @@ journal = $journal; - } + } } diff --git a/app/Handlers/Events/ConnectJournalToPiggyBank.php b/app/Handlers/Events/ConnectJournalToPiggyBank.php index 73329f983b..7280ccc3c6 100644 --- a/app/Handlers/Events/ConnectJournalToPiggyBank.php +++ b/app/Handlers/Events/ConnectJournalToPiggyBank.php @@ -38,7 +38,7 @@ class ConnectJournalToPiggyBank /** @var TransactionJournal $journal */ $journal = $event->journal; $piggyBankId = $event->piggyBankId; - if(intval($piggyBankId) < 1) { + if (intval($piggyBankId) < 1) { return; } @@ -66,7 +66,8 @@ class ConnectJournalToPiggyBank // update piggy bank rep for date of transaction journal. $repetition = $piggyBank->piggyBankRepetitions()->relevantOnDate($journal->date)->first(); if (is_null($repetition)) { - Log::debug('Found no repetition for piggy bank for date '.$journal->date->format('Y M d')); + Log::debug('Found no repetition for piggy bank for date ' . $journal->date->format('Y M d')); + return; } diff --git a/app/Handlers/Events/RescanJournal.php b/app/Handlers/Events/RescanJournal.php index 9b74e3bb44..226ae01a3c 100644 --- a/app/Handlers/Events/RescanJournal.php +++ b/app/Handlers/Events/RescanJournal.php @@ -1,8 +1,8 @@ id)->first(); - if(is_null($event)) { + $event = PiggyBankEvent::where('transaction_journal_id', $journal->id)->first(); + if (is_null($event)) { return; } $piggyBank = $event->piggyBank()->first(); diff --git a/app/Helpers/Reminders/ReminderHelperInterface.php b/app/Helpers/Reminders/ReminderHelperInterface.php index 833afe1a24..c3db2dd1d1 100644 --- a/app/Helpers/Reminders/ReminderHelperInterface.php +++ b/app/Helpers/Reminders/ReminderHelperInterface.php @@ -2,16 +2,17 @@ namespace FireflyIII\Helpers\Reminders; -use FireflyIII\Models\Reminder; -use FireflyIII\Models\PiggyBank; use Carbon\Carbon; +use FireflyIII\Models\PiggyBank; +use FireflyIII\Models\Reminder; /** * Interface ReminderHelperInterface * * @package FireflyIII\Helpers\Reminders */ -interface ReminderHelperInterface { +interface ReminderHelperInterface +{ /** * Takes a reminder, finds the piggy bank and tells you what to do now. * Aka how much money to put in. diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 9cf2d0918e..fef73a1085 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -169,7 +169,8 @@ class AccountController extends Controller $what = Config::get('firefly.shortNamesByFullName.' . $account->accountType->type); $journals = $repository->getJournals($account, $page); $subTitle = 'Details for ' . strtolower(e($account->accountType->type)) . ' "' . e($account->name) . '"'; - $journals->setPath('accounts/show/'.$account->id); + $journals->setPath('accounts/show/' . $account->id); + return view('accounts.show', compact('account', 'what', 'subTitleIcon', 'journals', 'subTitle')); } diff --git a/app/Http/Controllers/Auth/AuthController.php b/app/Http/Controllers/Auth/AuthController.php index a4fd311bfd..89668589df 100644 --- a/app/Http/Controllers/Auth/AuthController.php +++ b/app/Http/Controllers/Auth/AuthController.php @@ -64,7 +64,7 @@ class AuthController extends Controller ); } - $data =$request->all(); + $data = $request->all(); $data['password'] = bcrypt($data['password']); $this->auth->login($this->registrar->create($data)); diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index 13287972ce..79247f0397 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -98,8 +98,8 @@ class BudgetController extends Controller */ public function index(BudgetRepositoryInterface $repository) { - $budgets = Auth::user()->budgets()->where('active',1)->get(); - $inactive = Auth::user()->budgets()->where('active',0)->get(); + $budgets = Auth::user()->budgets()->where('active', 1)->get(); + $inactive = Auth::user()->budgets()->where('active', 0)->get(); // loop the budgets: $budgets->each( @@ -118,7 +118,7 @@ class BudgetController extends Controller $budgetMax = Preferences::get('budgetMaximum', 1000); $budgetMaximum = $budgetMax->data; - return view('budgets.index', compact('budgetMaximum','inactive', 'budgets', 'spent', 'spentPCT', 'overspent', 'amount')); + return view('budgets.index', compact('budgetMaximum', 'inactive', 'budgets', 'spent', 'spentPCT', 'overspent', 'amount')); } /** @@ -134,9 +134,9 @@ class BudgetController extends Controller ->whereNull('budget_transaction_journal.id') ->before($end) ->after($start) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order','ASC') - ->orderBy('transaction_journals.id','DESC') + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') ->get(['transaction_journals.*']); $subTitle = 'Transactions without a budget in ' . $start->format('F Y'); @@ -210,7 +210,7 @@ class BudgetController extends Controller public function update(Budget $budget, BudgetFormRequest $request, BudgetRepositoryInterface $repository) { $budgetData = [ - 'name' => $request->input('name'), + 'name' => $request->input('name'), 'active' => intval($request->input('active')) == 1 ]; diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php index b128d6e37d..0e45a06d8b 100644 --- a/app/Http/Controllers/CategoryController.php +++ b/app/Http/Controllers/CategoryController.php @@ -89,10 +89,10 @@ class CategoryController extends Controller $categories->each( function (Category $category) { $latest = $category->transactionjournals() - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order','ASC') - ->orderBy('transaction_journals.id','DESC') - ->first(); + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') + ->first(); if ($latest) { $category->lastActivity = $latest->date; } @@ -115,9 +115,9 @@ class CategoryController extends Controller ->whereNull('category_transaction_journal.id') ->before($end) ->after($start) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order','ASC') - ->orderBy('transaction_journals.id','DESC') + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') ->get(['transaction_journals.*']); $subTitle = 'Transactions without a category between ' . $start->format('jS F Y') . ' and ' . $end->format('jS F Y'); @@ -136,14 +136,12 @@ class CategoryController extends Controller $page = intval(Input::get('page')); $offset = $page > 0 ? $page * 50 : 0; $set = $category->transactionJournals()->withRelevantData()->take(50)->offset($offset) - - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order','ASC') - ->orderBy('transaction_journals.id','DESC') - - ->get( - ['transaction_journals.*'] - ); + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC') + ->get( + ['transaction_journals.*'] + ); $count = $category->transactionJournals()->count(); $journals = new LengthAwarePaginator($set, $count, 50, $page); @@ -166,7 +164,7 @@ class CategoryController extends Controller $category = $repository->store($categoryData); Session::flash('success', 'New category "' . $category->name . '" stored!'); - + if (intval(Input::get('create_another')) === 1) { return Redirect::route('categories.create')->withInput(); } diff --git a/app/Http/Controllers/GoogleChartController.php b/app/Http/Controllers/GoogleChartController.php index c7095c0c84..fd624319da 100644 --- a/app/Http/Controllers/GoogleChartController.php +++ b/app/Http/Controllers/GoogleChartController.php @@ -51,7 +51,7 @@ class GoogleChartController extends Controller $start = Session::get('start', Carbon::now()->startOfMonth()); $end = Session::get('end', Carbon::now()->endOfMonth()); $current = clone $start; - $today = new Carbon; + $today = new Carbon; while ($end >= $current) { $certain = $current < $today; @@ -237,20 +237,20 @@ class GoogleChartController extends Controller $start = Session::get('start', Carbon::now()->startOfMonth()); $end = Session::get('end', Carbon::now()->endOfMonth()); $set = TransactionJournal:: - where('transaction_journals.user_id',Auth::user()->id) - ->leftJoin( - 'transactions', - function (JoinClause $join) { - $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('amount', '>', 0); - } - ) + where('transaction_journals.user_id', Auth::user()->id) + ->leftJoin( + 'transactions', + function (JoinClause $join) { + $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('amount', '>', 0); + } + ) ->leftJoin( 'category_transaction_journal', 'category_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id' ) ->leftJoin('categories', 'categories.id', '=', 'category_transaction_journal.category_id') ->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id') ->before($end) - ->where('categories.user_id',Auth::user()->id) + ->where('categories.user_id', Auth::user()->id) ->after($start) ->where('transaction_types.type', 'Withdrawal') ->groupBy('categories.id') diff --git a/app/Http/Controllers/JsonController.php b/app/Http/Controllers/JsonController.php index 48981f8143..c4d411ba0b 100644 --- a/app/Http/Controllers/JsonController.php +++ b/app/Http/Controllers/JsonController.php @@ -89,8 +89,8 @@ class JsonController extends Controller // paid a bill in this range? $count = $bill->transactionjournals()->before($range['end'])->after($range['start'])->count(); if ($count != 0) { - $journal = $bill->transactionjournals()->with('transactions')->before($range['end'])->after($range['start'])->first(); - $currentAmount = 0; + $journal = $bill->transactionjournals()->with('transactions')->before($range['end'])->after($range['start'])->first(); + $currentAmount = 0; foreach ($journal->transactions as $t) { if (floatval($t->amount) > 0) { $currentAmount = floatval($t->amount); diff --git a/app/Http/Middleware/PiggyBanks.php b/app/Http/Middleware/PiggyBanks.php index 92ac858ba4..fc2c40aa39 100644 --- a/app/Http/Middleware/PiggyBanks.php +++ b/app/Http/Middleware/PiggyBanks.php @@ -98,10 +98,10 @@ class PiggyBanks // first loop fixes this date. or should fix it. $max = new Carbon; - echo '[#'.$piggyBank->id.', from: '.$start->format('Y-m-d.').' to '.$end->format('Y-m-d.').']'; + echo '[#' . $piggyBank->id . ', from: ' . $start->format('Y-m-d.') . ' to ' . $end->format('Y-m-d.') . ']'; // create stuff. Or at least, try: $repetition = $piggyBank->piggyBankRepetitions()->onDates($start, $end)->first(); - if(!$repetition) { + if (!$repetition) { $repetition = new PiggyBankRepetition; $repetition->piggyBank()->associate($piggyBank); $repetition->startdate = $start; diff --git a/app/Http/Middleware/ReplaceTestVars.php b/app/Http/Middleware/ReplaceTestVars.php index ad35519a3e..bc75e07f7c 100644 --- a/app/Http/Middleware/ReplaceTestVars.php +++ b/app/Http/Middleware/ReplaceTestVars.php @@ -46,7 +46,7 @@ class ReplaceTestVars $input = $request->all(); $input['_token'] = $request->session()->token(); // we need to update _token value to make sure we get the POST / PUT tests passed. - Log::debug('Input token replaced ('.$input['_token'].').'); + Log::debug('Input token replaced (' . $input['_token'] . ').'); $request->replace($input); } diff --git a/app/Http/Requests/AccountFormRequest.php b/app/Http/Requests/AccountFormRequest.php index 3ab4a26faf..a9b704f4b3 100644 --- a/app/Http/Requests/AccountFormRequest.php +++ b/app/Http/Requests/AccountFormRequest.php @@ -33,7 +33,7 @@ class AccountFormRequest extends Request $nameRule = 'required|between:1,100|uniqueAccountForUser'; if (Account::find(Input::get('id'))) { - $nameRule = 'required|between:1,100|belongsToUser:accounts|uniqueForUser:'.Input::get('id'); + $nameRule = 'required|between:1,100|belongsToUser:accounts|uniqueForUser:' . Input::get('id'); } return [ diff --git a/app/Http/Requests/ProfileFormRequest.php b/app/Http/Requests/ProfileFormRequest.php index 0fc12e3377..8bac377a5b 100644 --- a/app/Http/Requests/ProfileFormRequest.php +++ b/app/Http/Requests/ProfileFormRequest.php @@ -26,7 +26,7 @@ class ProfileFormRequest extends Request public function rules() { return [ - 'current_password' => 'required', + 'current_password' => 'required', 'new_password' => 'required|confirmed', 'new_password_confirmation' => 'required', ]; diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php index 4ec8165e8c..cdb6a5226e 100644 --- a/app/Http/breadcrumbs.php +++ b/app/Http/breadcrumbs.php @@ -3,13 +3,13 @@ use Carbon\Carbon; use DaveJamesMiller\Breadcrumbs\Generator; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Account; -use FireflyIII\Models\Budget; -use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\Bill; +use FireflyIII\Models\Budget; use FireflyIII\Models\Category; -use FireflyIII\Models\Reminder; use FireflyIII\Models\LimitRepetition; use FireflyIII\Models\PiggyBank; +use FireflyIII\Models\Reminder; +use FireflyIII\Models\TransactionJournal; /* * Back home. diff --git a/app/Http/routes.php b/app/Http/routes.php index 89e5e5bd1b..685009ac92 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -132,7 +132,7 @@ Route::get('/register', ['uses' => 'Auth\AuthController@getRegister', 'as' => 'r Route::controllers( [ - 'auth' => 'Auth\AuthController', + 'auth' => 'Auth\AuthController', 'password' => 'Auth\PasswordController', ] ); @@ -142,7 +142,7 @@ Route::controllers( * Home Controller */ Route::group( - ['middleware' => ['auth', 'range', 'reminders','piggybanks']], function () { + ['middleware' => ['auth', 'range', 'reminders', 'piggybanks']], function () { Route::get('/', ['uses' => 'HomeController@index', 'as' => 'index']); Route::get('/home', ['uses' => 'HomeController@index', 'as' => 'home']); Route::post('/daterange', ['uses' => 'HomeController@dateRange', 'as' => 'daterange']); diff --git a/app/Models/Account.php b/app/Models/Account.php index c6c8816423..0b77b81bbb 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -1,10 +1,11 @@ 'required|exists:accounts,id', 'name' => 'required|between:1,100', 'data' => 'required' ]; - protected $table = 'account_meta'; + protected $table = 'account_meta'; /** * @return \Illuminate\Database\Eloquent\Relations\BelongsTo diff --git a/app/Models/Bill.php b/app/Models/Bill.php index 7cdcc2e67c..62beebef2d 100644 --- a/app/Models/Bill.php +++ b/app/Models/Bill.php @@ -10,7 +10,7 @@ use Illuminate\Database\Eloquent\Model; class Bill extends Model { - protected $fillable = ['name', 'match', 'amount_min','user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active',]; + protected $fillable = ['name', 'match', 'amount_min', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active',]; /** * @return array diff --git a/app/Models/Component.php b/app/Models/Component.php index 7a9bba141b..a17450943d 100644 --- a/app/Models/Component.php +++ b/app/Models/Component.php @@ -12,7 +12,7 @@ class Component extends Model { use SoftDeletes; - protected $fillable = ['user_id', 'name','class']; + protected $fillable = ['user_id', 'name', 'class']; /** * @return array diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php index ad1b4fd672..b46c34cd3d 100644 --- a/app/Models/PiggyBank.php +++ b/app/Models/PiggyBank.php @@ -1,11 +1,10 @@ id.')'); + Log::error('Tried to work with a piggy bank with a repeats=1 value! (id is ' . $this->id . ')'); } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index c92888c235..f32718ca75 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -28,7 +28,7 @@ class EventServiceProvider extends ServiceProvider */ protected $listen = [ - 'FireflyIII\Events\JournalSaved' => [ + 'FireflyIII\Events\JournalSaved' => [ 'FireflyIII\Handlers\Events\RescanJournal', 'FireflyIII\Handlers\Events\UpdateJournalConnection', @@ -60,7 +60,6 @@ class EventServiceProvider extends ServiceProvider ); - Account::deleted( function (Account $account) { diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 6ea2ec97a8..92215550dd 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -106,9 +106,9 @@ class AccountRepository implements AccountRepositoryInterface ->withRelevantData() ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') ->where('transactions.account_id', $account->id) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order','ASC') - ->orderBy('transaction_journals.id','DESC'); + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC'); $query->before(Session::get('end', Carbon::now()->endOfMonth())); $query->after(Session::get('start', Carbon::now()->startOfMonth())); @@ -119,7 +119,6 @@ class AccountRepository implements AccountRepositoryInterface return $paginator; - } /** diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.php index e948ba01c8..20d96fbeb0 100644 --- a/app/Repositories/Account/AccountRepositoryInterface.php +++ b/app/Repositories/Account/AccountRepositoryInterface.php @@ -2,11 +2,12 @@ namespace FireflyIII\Repositories\Account; -use FireflyIII\Models\Account; -use FireflyIII\Models\TransactionJournal; -use FireflyIII\Models\Preference; -use Illuminate\Support\Collection; use Carbon\Carbon; +use FireflyIII\Models\Account; +use FireflyIII\Models\Preference; +use FireflyIII\Models\TransactionJournal; +use Illuminate\Support\Collection; + /** * Interface AccountRepositoryInterface * diff --git a/app/Repositories/Bill/BillRepositoryInterface.php b/app/Repositories/Bill/BillRepositoryInterface.php index 44402cea23..34142fcc37 100644 --- a/app/Repositories/Bill/BillRepositoryInterface.php +++ b/app/Repositories/Bill/BillRepositoryInterface.php @@ -11,7 +11,8 @@ use FireflyIII\Models\TransactionJournal; * * @package FireflyIII\Repositories\Bill */ -interface BillRepositoryInterface { +interface BillRepositoryInterface +{ /** * @param Bill $bill @@ -25,7 +26,7 @@ interface BillRepositoryInterface { * and returns date ranges that fall within the given range; those ranges are the bills expected. When a bill is due on the 14th of the month and * you give 1st and the 31st of that month as argument, you'll get one response, matching the range of your bill. * - * @param Bill $bill + * @param Bill $bill * @param Carbon $start * @param Carbon $end * diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php index 6d5694e348..10a26f898e 100644 --- a/app/Repositories/Budget/BudgetRepository.php +++ b/app/Repositories/Budget/BudgetRepository.php @@ -43,9 +43,9 @@ class BudgetRepository implements BudgetRepositoryInterface $setQuery = $budget->transactionJournals()->withRelevantData()->take($take)->offset($offset) - ->orderBy('transaction_journals.date', 'DESC') - ->orderBy('transaction_journals.order','ASC') - ->orderBy('transaction_journals.id','DESC'); + ->orderBy('transaction_journals.date', 'DESC') + ->orderBy('transaction_journals.order', 'ASC') + ->orderBy('transaction_journals.id', 'DESC'); $countQuery = $budget->transactionJournals(); @@ -57,6 +57,7 @@ class BudgetRepository implements BudgetRepositoryInterface $set = $setQuery->get(['transaction_journals.*']); $count = $countQuery->count(); + return new LengthAwarePaginator($set, $count, $take, $offset); } @@ -103,7 +104,7 @@ class BudgetRepository implements BudgetRepositoryInterface public function update(Budget $budget, array $data) { // update the account: - $budget->name = $data['name']; + $budget->name = $data['name']; $budget->active = $data['active']; $budget->save(); diff --git a/app/Repositories/PiggyBank/PiggyBankRepository.php b/app/Repositories/PiggyBank/PiggyBankRepository.php index 3fedcf5871..9eaa117622 100644 --- a/app/Repositories/PiggyBank/PiggyBankRepository.php +++ b/app/Repositories/PiggyBank/PiggyBankRepository.php @@ -111,7 +111,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface public function setOrder($id, $order) { $piggyBank = PiggyBank::leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id')->where('accounts.user_id', Auth::user()->id) - ->where('piggy_banks.id',$id)->first(['piggy_banks.*']); + ->where('piggy_banks.id', $id)->first(['piggy_banks.*']); if ($piggyBank) { $piggyBank->order = $order; $piggyBank->save(); diff --git a/app/Repositories/PiggyBank/PiggybankPart.php b/app/Repositories/PiggyBank/PiggybankPart.php index 9bbbad807c..bbde8435f3 100644 --- a/app/Repositories/PiggyBank/PiggybankPart.php +++ b/app/Repositories/PiggyBank/PiggybankPart.php @@ -2,10 +2,9 @@ namespace FireflyIII\Repositories\PiggyBank; -use FireflyIII\Models\Reminder; -use FireflyIII\Models\PiggyBankRepetition; - use Carbon\Carbon; +use FireflyIII\Models\PiggyBankRepetition; +use FireflyIII\Models\Reminder; /** * Class PiggyBankPart diff --git a/app/Support/Navigation.php b/app/Support/Navigation.php index 2ef5c9a4bd..65f3de722b 100644 --- a/app/Support/Navigation.php +++ b/app/Support/Navigation.php @@ -344,6 +344,48 @@ class Navigation throw new FireflyException('Cannot do startOfPeriod for $repeat_freq ' . $repeatFreq); } + /** + * @param Carbon $theDate + * @param $repeatFreq + * @param int $subtract + * + * @return Carbon + * @throws FireflyException + */ + public function subtractPeriod(Carbon $theDate, $repeatFreq, $subtract = 1) + { + $date = clone $theDate; + + $functionMap = [ + 'daily' => 'subDays', + 'week' => 'subWeeks', + 'weekly' => 'subWeeks', + 'month' => 'subMonths', + 'monthly' => 'subMonths', + 'year' => 'subYears', + 'yearly' => 'subYears', + ]; + $modifierMap = [ + 'quarter' => 3, + 'quarterly' => 3, + 'half-year' => 6, + ]; + if (isset($functionMap[$repeatFreq])) { + $function = $functionMap[$repeatFreq]; + $date->$function($subtract); + + return $date; + } + if (isset($modifierMap[$repeatFreq])) { + $subtract = $subtract * $modifierMap[$repeatFreq]; + $date->subMonths($subtract); + + return $date; + } + + throw new FireflyException('Cannot do subtractPeriod for $repeat_freq ' . $repeatFreq); + } + /** * @param $range * @param Carbon $start @@ -414,47 +456,5 @@ class Navigation throw new FireflyException('updateStartDate cannot handle $range ' . $range); } - /** - * @param Carbon $theDate - * @param $repeatFreq - * @param int $subtract - * - * @return Carbon - * @throws FireflyException - */ - public function subtractPeriod(Carbon $theDate, $repeatFreq, $subtract = 1) - { - $date = clone $theDate; - - $functionMap = [ - 'daily' => 'subDays', - 'week' => 'subWeeks', - 'weekly' => 'subWeeks', - 'month' => 'subMonths', - 'monthly' => 'subMonths', - 'year' => 'subYears', - 'yearly' => 'subYears', - ]; - $modifierMap = [ - 'quarter' => 3, - 'quarterly' => 3, - 'half-year' => 6, - ]; - if (isset($functionMap[$repeatFreq])) { - $function = $functionMap[$repeatFreq]; - $date->$function($subtract); - - return $date; - } - if (isset($modifierMap[$repeatFreq])) { - $subtract = $subtract * $modifierMap[$repeatFreq]; - $date->subMonths($subtract); - - return $date; - } - - throw new FireflyException('Cannot do subtractPeriod for $repeat_freq ' . $repeatFreq); - } - } diff --git a/app/Support/Search/Search.php b/app/Support/Search/Search.php index 5270cdf610..f1e0c658ae 100644 --- a/app/Support/Search/Search.php +++ b/app/Support/Search/Search.php @@ -112,8 +112,8 @@ class Search implements SearchInterface )->get(); // encrypted - $all = Auth::user()->transactionjournals()->withRelevantData()->where('encrypted', 1)->get(); - $set = $all->filter( + $all = Auth::user()->transactionjournals()->withRelevantData()->where('encrypted', 1)->get(); + $set = $all->filter( function (TransactionJournal $journal) use ($words) { foreach ($words as $word) { $haystack = strtolower($journal->description); diff --git a/app/Support/Search/SearchInterface.php b/app/Support/Search/SearchInterface.php index 4b58393065..431275e8fe 100644 --- a/app/Support/Search/SearchInterface.php +++ b/app/Support/Search/SearchInterface.php @@ -9,7 +9,8 @@ use Illuminate\Support\Collection; * * @package FireflyIII\Support\Search */ -interface SearchInterface { +interface SearchInterface +{ /** * @param array $words * diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php index d4b4771e90..8ee5399b65 100644 --- a/app/Validation/FireflyValidator.php +++ b/app/Validation/FireflyValidator.php @@ -152,7 +152,7 @@ class FireflyValidator extends Validator */ public function validateUniquePiggyBankForUser($attribute, $value, $parameters) { - $query = DB::table($parameters[0])->where('piggy_banks.'.$parameters[1], $value); + $query = DB::table($parameters[0])->where('piggy_banks.' . $parameters[1], $value); $query->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id'); $query->where('accounts.user_id', Auth::user()->id); if (isset($paramers[2])) {