From 3cfa3f3b27f959f9d2224ffdc5fb7e810954e18c Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 13 Dec 2014 21:59:02 +0100 Subject: [PATCH] Code cleanup. --- app/breadcrumbs.php | 2 +- app/controllers/BudgetController.php | 20 +++++----- app/controllers/GoogleChartController.php | 19 +++++----- app/controllers/HelpController.php | 4 +- app/controllers/ReportController.php | 4 +- app/controllers/TransactionController.php | 5 ++- ...te_component_transaction_journal_table.php | 20 +++++----- ..._component_recurring_transaction_table.php | 22 +++++------ .../2014_12_13_190730_changes_for_v321.php | 35 +++++++++++++++++ app/database/seeds/TestContentSeeder.php | 8 ++-- .../FireflyIII/Collection/PiggybankPart.php | 11 ++++++ app/lib/FireflyIII/Database/Account.php | 35 ++++++++++++++--- app/lib/FireflyIII/Database/AccountType.php | 9 ++++- app/lib/FireflyIII/Database/Budget.php | 19 +++++++++- app/lib/FireflyIII/Database/Category.php | 17 ++++++++- .../Database/Ifaces/RecurringInterface.php | 9 +++-- .../Database/Ifaces/ReportInterface.php | 5 +++ app/lib/FireflyIII/Database/Piggybank.php | 13 ++++++- app/lib/FireflyIII/Database/Recurring.php | 3 ++ .../FireflyIII/Database/RepeatedExpense.php | 17 ++++++++- app/lib/FireflyIII/Database/Report.php | 5 +++ app/lib/FireflyIII/Database/Transaction.php | 9 ++++- .../Database/TransactionJournal.php | 23 +++++++++-- .../FireflyIII/Database/TransactionType.php | 10 ++++- app/lib/FireflyIII/Event/Account.php | 14 +++++++ app/lib/FireflyIII/Event/Budget.php | 23 ++++++----- app/lib/FireflyIII/Event/Event.php | 10 +++++ app/lib/FireflyIII/Event/Piggybank.php | 27 ++++++++++++- app/lib/FireflyIII/Event/Transaction.php | 14 +++++++ .../FireflyIII/Event/TransactionJournal.php | 14 ++++++- app/lib/FireflyIII/Form/Form.php | 21 +++++----- app/lib/FireflyIII/Report/Report.php | 2 + app/lib/FireflyIII/Search/Search.php | 5 +++ app/lib/FireflyIII/Shared/Facade/DateKit.php | 8 ++++ app/lib/FireflyIII/Shared/Facade/FFForm.php | 8 ++++ app/lib/FireflyIII/Shared/Facade/Filter.php | 8 ++++ .../FireflyIII/Shared/Facade/Navigation.php | 8 ++++ .../FireflyIII/Shared/Facade/Reminders.php | 8 ++++ app/lib/FireflyIII/Shared/Facade/Steam.php | 8 ++++ .../FireflyIII/Shared/Mail/Registration.php | 16 ++++---- .../Shared/SingleTableInheritanceEntity.php | 14 +++---- app/lib/FireflyIII/Shared/Toolkit/Date.php | 10 ++++- .../Shared/Validation/FireflyValidator.php | 7 ++++ app/models/Account.php | 23 +++++++---- app/models/AccountMeta.php | 5 +++ app/models/AccountType.php | 3 ++ app/models/Budget.php | 12 ++++-- app/models/{Limit.php => BudgetLimit.php} | 9 +++-- app/models/Category.php | 6 +++ app/models/Component.php | 5 +++ app/models/LimitRepetition.php | 31 ++++++++------- app/models/Piggybank.php | 9 +++++ app/models/PiggybankEvent.php | 3 ++ app/models/PiggybankRepetition.php | 11 ++++++ app/models/Preference.php | 3 ++ app/models/RecurringTransaction.php | 6 ++- app/models/Reminder.php | 17 +++++++++ app/models/Transaction.php | 27 +++++++++++++ app/models/TransactionCurrency.php | 3 ++ app/models/TransactionGroup.php | 3 ++ app/models/TransactionJournal.php | 23 +++++++++++ app/models/TransactionRelation.php | 3 ++ app/models/TransactionType.php | 3 ++ app/models/User.php | 29 +++++++------- app/routes.php | 4 +- app/start/global.php | 38 +++++++++---------- tests/functional/CategoryControllerCest.php | 3 -- 67 files changed, 651 insertions(+), 177 deletions(-) create mode 100644 app/database/migrations/2014_12_13_190730_changes_for_v321.php rename app/models/{Limit.php => BudgetLimit.php} (90%) diff --git a/app/breadcrumbs.php b/app/breadcrumbs.php index 9772319edf..3269c6e773 100644 --- a/app/breadcrumbs.php +++ b/app/breadcrumbs.php @@ -90,7 +90,7 @@ Breadcrumbs::register( $breadcrumbs->push($budget->name, route('budgets.show', $budget->id)); if (!is_null($repetition)) { $breadcrumbs->push( - DateKit::periodShow($repetition->startdate, $repetition->limit->repeat_freq), route('budgets.show', $budget->id, $repetition->id) + DateKit::periodShow($repetition->startdate, $repetition->budgetlimit->repeat_freq), route('budgets.show', $budget->id, $repetition->id) ); } } diff --git a/app/controllers/BudgetController.php b/app/controllers/BudgetController.php index 1a90a92afd..b004435e7a 100644 --- a/app/controllers/BudgetController.php +++ b/app/controllers/BudgetController.php @@ -7,7 +7,7 @@ use FireflyIII\Shared\Preferences\PreferencesInterface as Pref; /** * Class BudgetController * - * TODO move AJAX methods to their own BudgetAjaxControlle + * TODO move AJAX methods to their own BudgetAjaxController * TODO Find out what constitutes proper camelCase * TODO How is object coupling counted? * @@ -44,7 +44,7 @@ class BudgetController extends BaseController public function amount(Budget $budget) { $amount = intval(Input::get('amount')); - $date = Session::get('start',Carbon::now()->startOfMonth()); + $date = Session::get('start', Carbon::now()->startOfMonth()); $limitRepetition = $this->_repository->updateLimitAmount($budget, $date, $amount); return Response::json(['name' => $budget->name, 'repetition' => $limitRepetition->id]); @@ -112,16 +112,18 @@ class BudgetController extends BaseController $budgets->each( function (Budget $budget) { /** @noinspection PhpUndefinedFieldInspection */ - $budget->spent = $this->_repository->spentInMonth($budget, \Session::get('start',Carbon::now()->startOfMonth())); + $budget->spent = $this->_repository->spentInMonth($budget, \Session::get('start', Carbon::now()->startOfMonth())); /** @noinspection PhpUndefinedFieldInspection */ - $budget->currentRep = $budget->limitrepetitions()->where('limit_repetitions.startdate', \Session::get('start',Carbon::now()->startOfMonth())->format('Y-m-d'))->first( + $budget->currentRep = $budget->limitrepetitions()->where( + 'limit_repetitions.startdate', \Session::get('start', Carbon::now()->startOfMonth())->format('Y-m-d') + )->first( ['limit_repetitions.*'] ); } ); $spent = $budgets->sum('spent'); - $amount = $this->_preferences->get('budgetIncomeTotal' . \Session::get('start',Carbon::now()->startOfMonth())->format('FY'), 1000)->data; + $amount = $this->_preferences->get('budgetIncomeTotal' . \Session::get('start', Carbon::now()->startOfMonth())->format('FY'), 1000)->data; $overspent = $spent > $amount; $spentPCT = $overspent ? ceil($amount / $spent * 100) : ceil($spent / $amount * 100); @@ -133,7 +135,7 @@ class BudgetController extends BaseController */ public function postUpdateIncome() { - $this->_preferences->set('budgetIncomeTotal' . Session::get('start',Carbon::now()->startOfMonth())->format('FY'), intval(Input::get('amount'))); + $this->_preferences->set('budgetIncomeTotal' . Session::get('start', Carbon::now()->startOfMonth())->format('FY'), intval(Input::get('amount'))); return Redirect::route('budgets.index'); } @@ -146,13 +148,13 @@ class BudgetController extends BaseController */ public function show(Budget $budget, LimitRepetition $repetition = null) { - if (!is_null($repetition) && $repetition->limit->budget->id != $budget->id) { + if (!is_null($repetition) && $repetition->budgetlimit->budget->id != $budget->id) { App::abort(500); } $hideBudget = true; // used in transaction list. $journals = $this->_repository->getJournals($budget, $repetition); - $limits = $repetition ? [$repetition->limit] : $budget->limits()->orderBy('startdate', 'DESC')->get(); + $limits = $repetition ? [$repetition->limit] : $budget->budgetlimits()->orderBy('startdate', 'DESC')->get(); $subTitle = $repetition ? e($budget->name) . ' in ' . $repetition->startdate->format('F Y') : e($budget->name); return View::make('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle', 'hideBudget')); @@ -244,7 +246,7 @@ class BudgetController extends BaseController */ public function updateIncome() { - $budgetAmount = $this->_preferences->get('budgetIncomeTotal' . Session::get('start',Carbon::now()->startOfMonth())->format('FY'), 1000); + $budgetAmount = $this->_preferences->get('budgetIncomeTotal' . Session::get('start', Carbon::now()->startOfMonth())->format('FY'), 1000); return View::make('budgets.income')->with('amount', $budgetAmount); } diff --git a/app/controllers/GoogleChartController.php b/app/controllers/GoogleChartController.php index c31c66c354..c61be7cc12 100644 --- a/app/controllers/GoogleChartController.php +++ b/app/controllers/GoogleChartController.php @@ -1,9 +1,10 @@ addColumn('Budget', 'string'); - $chart->addColumn('Budgeted', 'number'); - $chart->addColumn('Spent', 'number'); + $this->_chart->addColumn('Budget', 'string'); + $this->_chart->addColumn('Budgeted', 'number'); + $this->_chart->addColumn('Spent', 'number'); /** @var \FireflyIII\Database\Budget $bdt */ $bdt = App::make('FireflyIII\Database\Budget'); @@ -165,7 +164,7 @@ class GoogleChartController extends BaseController */ $expenses = floatval($budget->transactionjournals()->before($searchEnd)->after($searchStart)->lessThan(0)->sum('amount')) * -1; if ($expenses > 0) { - $chart->addRow($budget->name, $limit, $expenses); + $this->_chart->addRow($budget->name, $limit, $expenses); } } @@ -175,12 +174,12 @@ class GoogleChartController extends BaseController */ $noBudgetSet = $bdt->transactionsWithoutBudgetInDateRange(Session::get('start', Carbon::now()->startOfMonth()), Session::get('end')); $sum = $noBudgetSet->sum('amount') * -1; - $chart->addRow('No budget', 0, $sum); + $this->_chart->addRow('No budget', 0, $sum); - $chart->generate(); + $this->_chart->generate(); - return Response::json($chart->getData()); + return Response::json($this->_chart->getData()); } /** diff --git a/app/controllers/HelpController.php b/app/controllers/HelpController.php index 1424351c40..4d3bb54dcb 100644 --- a/app/controllers/HelpController.php +++ b/app/controllers/HelpController.php @@ -29,9 +29,9 @@ class HelpController extends BaseController } // get the help-content from Github: - $URL = 'https://raw.githubusercontent.com/JC5/firefly-iii-help/master/' . e($route) . '.md'; + $uri = 'https://raw.githubusercontent.com/JC5/firefly-iii-help/master/' . e($route) . '.md'; try { - $content = file_get_contents($URL); + $content = file_get_contents($uri); } catch (ErrorException $e) { $content = '

There is no help for this route.

'; } diff --git a/app/controllers/ReportController.php b/app/controllers/ReportController.php index 81ff131fdd..04eef366f8 100644 --- a/app/controllers/ReportController.php +++ b/app/controllers/ReportController.php @@ -6,6 +6,8 @@ use FireflyIII\Database\TransactionJournal as TransactionJournalRepository; use FireflyIII\Report\ReportInterface as ReportHelper; /** + * @SuppressWarnings("CamelCase") + * * Class ReportController */ class ReportController extends BaseController @@ -163,7 +165,7 @@ class ReportController extends BaseController public function unbalanced($year, $month) { try { - $date = new Carbon($year . '-' . $month . '-01'); + new Carbon($year . '-' . $month . '-01'); } catch (Exception $e) { App::abort(500); } diff --git a/app/controllers/TransactionController.php b/app/controllers/TransactionController.php index 5885f53f2d..cce380bad4 100644 --- a/app/controllers/TransactionController.php +++ b/app/controllers/TransactionController.php @@ -45,11 +45,11 @@ class TransactionController extends BaseController } } $unique = array_unique($ids); - if (count($ids) > 0) { + if (count($unique) > 0) { /** @var \FireflyIII\Database\TransactionJournal $repository */ $repository = App::make('FireflyIII\Database\TransactionJournal'); - $set = $repository->getByIds($ids); + $set = $repository->getByIds($unique); $set->each( function (TransactionJournal $journal) { $journal->amount = mf($journal->getAmount()); @@ -544,6 +544,7 @@ class TransactionController extends BaseController /** * @param TransactionJournal $journal * + * @return $this * @throws FireflyException */ public function update(TransactionJournal $journal) diff --git a/app/database/migrations/2014_07_05_171326_create_component_transaction_journal_table.php b/app/database/migrations/2014_07_05_171326_create_component_transaction_journal_table.php index 4474c18ec7..ba819428d3 100644 --- a/app/database/migrations/2014_07_05_171326_create_component_transaction_journal_table.php +++ b/app/database/migrations/2014_07_05_171326_create_component_transaction_journal_table.php @@ -30,19 +30,19 @@ class CreateComponentTransactionJournalTable extends Migration { Schema::create( 'component_transaction_journal', function (Blueprint $table) { - $table->increments('id'); - $table->integer('component_id')->unsigned(); - $table->integer('transaction_journal_id')->unsigned(); + $table->increments('id'); + $table->integer('component_id')->unsigned(); + $table->integer('transaction_journal_id')->unsigned(); - // link components with component_id - $table->foreign('component_id')->references('id')->on('components')->onDelete('cascade'); + // link components with component_id + $table->foreign('component_id')->references('id')->on('components')->onDelete('cascade'); - // link transaction journals with transaction_journal_id - $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade'); + // link transaction journals with transaction_journal_id + $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade'); - // combo must be unique: - $table->unique(['component_id', 'transaction_journal_id'],'cid_tjid_unique'); - } + // combo must be unique: + $table->unique(['component_id', 'transaction_journal_id'], 'cid_tjid_unique'); + } ); } diff --git a/app/database/migrations/2014_08_06_044416_create_component_recurring_transaction_table.php b/app/database/migrations/2014_08_06_044416_create_component_recurring_transaction_table.php index e6f25ed2ec..1b0b56e384 100644 --- a/app/database/migrations/2014_08_06_044416_create_component_recurring_transaction_table.php +++ b/app/database/migrations/2014_08_06_044416_create_component_recurring_transaction_table.php @@ -30,21 +30,21 @@ class CreateComponentRecurringTransactionTable extends Migration { Schema::create( 'component_recurring_transaction', function (Blueprint $table) { - $table->increments('id'); - $table->integer('component_id')->unsigned(); - $table->integer('recurring_transaction_id')->unsigned(); - $table->boolean('optional'); + $table->increments('id'); + $table->integer('component_id')->unsigned(); + $table->integer('recurring_transaction_id')->unsigned(); + $table->boolean('optional'); - // link components with component_id - $table->foreign('component_id')->references('id')->on('components')->onDelete('cascade'); + // link components with component_id + $table->foreign('component_id')->references('id')->on('components')->onDelete('cascade'); - // link transaction journals with transaction_journal_id - $table->foreign('recurring_transaction_id')->references('id')->on('recurring_transactions')->onDelete('cascade'); + // link transaction journals with transaction_journal_id + $table->foreign('recurring_transaction_id')->references('id')->on('recurring_transactions')->onDelete('cascade'); - // component and recurring transaction must be unique. - $table->unique(['component_id','recurring_transaction_id'],'cid_rtid_unique'); + // component and recurring transaction must be unique. + $table->unique(['component_id', 'recurring_transaction_id'], 'cid_rtid_unique'); - } + } ); } diff --git a/app/database/migrations/2014_12_13_190730_changes_for_v321.php b/app/database/migrations/2014_12_13_190730_changes_for_v321.php new file mode 100644 index 0000000000..1b8f084771 --- /dev/null +++ b/app/database/migrations/2014_12_13_190730_changes_for_v321.php @@ -0,0 +1,35 @@ +first(); $ibType = AccountType::whereType('Initial balance account')->first(); - $euro = TransactionCurrency::whereCode('EUR')->first(); - $obType = TransactionType::whereType('Opening balance')->first(); $withdrawal = TransactionType::whereType('Withdrawal')->first(); $transfer = TransactionType::whereType('Transfer')->first(); @@ -132,11 +130,15 @@ class TestContentSeeder extends Seeder * @param $description * @param $date * + * @param Budget $budget + * @param Category $category + * * @return TransactionJournal */ public function createTransaction( Account $from, Account $to, $amount, TransactionType $type, $description, $date, Budget $budget = null, Category $category = null - ) { + ) + { $user = User::whereEmail('thegrumpydictator@gmail.com')->first(); $euro = TransactionCurrency::whereCode('EUR')->first(); diff --git a/app/lib/FireflyIII/Collection/PiggybankPart.php b/app/lib/FireflyIII/Collection/PiggybankPart.php index faf28173b2..bf26edee5b 100644 --- a/app/lib/FireflyIII/Collection/PiggybankPart.php +++ b/app/lib/FireflyIII/Collection/PiggybankPart.php @@ -5,6 +5,11 @@ namespace FireflyIII\Collection; use Carbon\Carbon; +/** + * Class PiggybankPart + * + * @package FireflyIII\Collection + */ class PiggybankPart { /** @var float */ @@ -92,11 +97,17 @@ class PiggybankPart $this->targetdate = $targetdate; } + /** + * @return bool + */ public function hasReminder() { return !is_null($this->reminder); } + /** + * @return float|int + */ public function percentage() { if ($this->getCurrentamount() < $this->getCumulativeAmount()) { diff --git a/app/lib/FireflyIII/Database/Account.php b/app/lib/FireflyIII/Database/Account.php index 5ccd858ec3..d1d91bce21 100644 --- a/app/lib/FireflyIII/Database/Account.php +++ b/app/lib/FireflyIII/Database/Account.php @@ -221,7 +221,7 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface { // delete journals: - $journals = \TransactionJournal::whereIn( + \TransactionJournal::whereIn( 'id', function ($query) use ($model) { $query->select('transaction_journal_id') ->from('transactions')->whereIn( @@ -454,10 +454,9 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface } /** - * Finds an account type using one of the "$what"'s: expense, asset, revenue, opening, etc. - * * @param $what * + * @throws NotImplementedException * @return \AccountType|null */ public function findByWhat($what) @@ -470,6 +469,7 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface * Returns all objects. * * @return Collection + * @throws NotImplementedException */ public function get() { @@ -487,6 +487,12 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface return $this->getUser()->accounts()->whereIn('id', $ids)->get(); } + /** + * @param $name + * + * @return static + * @throws \FireflyIII\Exception\FireflyException + */ public function firstExpenseAccountOrCreate($name) { /** @var \FireflyIII\Database\AccountType $accountTypeRepos */ @@ -510,6 +516,12 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface } + /** + * @param $name + * + * @return static + * @throws \FireflyIII\Exception\FireflyException + */ public function firstRevenueAccountOrCreate($name) { /** @var \FireflyIII\Database\AccountType $accountTypeRepos */ @@ -523,6 +535,12 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface } + /** + * @param \Account $account + * @param int $limit + * + * @return \Illuminate\Pagination\Paginator + */ public function getAllTransactionJournals(\Account $account, $limit = 50) { $offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0; @@ -568,6 +586,13 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface return $date; } + /** + * @param \Account $account + * @param int $limit + * @param string $range + * + * @return \Illuminate\Pagination\Paginator + */ public function getTransactionJournals(\Account $account, $limit = 50, $range = 'session') { $offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0; @@ -580,8 +605,8 @@ class Account implements CUD, CommonDatabaseCalls, AccountInterface ->orderBy('date', 'DESC'); if ($range == 'session') { - $query->before(\Session::get('end', \Carbon\Carbon::now()->startOfMonth())); - $query->after(\Session::get('start', \Carbon\Carbon::now()->startOfMonth())); + $query->before(\Session::get('end', Carbon::now()->startOfMonth())); + $query->after(\Session::get('start', Carbon::now()->startOfMonth())); } $count = $query->count(); $set = $query->take($limit)->offset($offset)->get(['transaction_journals.*']); diff --git a/app/lib/FireflyIII/Database/AccountType.php b/app/lib/FireflyIII/Database/AccountType.php index 6a7131d2b1..5015214a2a 100644 --- a/app/lib/FireflyIII/Database/AccountType.php +++ b/app/lib/FireflyIII/Database/AccountType.php @@ -21,6 +21,7 @@ class AccountType implements CUD, CommonDatabaseCalls * @param \Eloquent $model * * @return bool + * @throws NotImplementedException */ public function destroy(\Eloquent $model) { @@ -32,6 +33,7 @@ class AccountType implements CUD, CommonDatabaseCalls * @param array $data * * @return \Eloquent + * @throws NotImplementedException */ public function store(array $data) { @@ -41,9 +43,10 @@ class AccountType implements CUD, CommonDatabaseCalls /** * @param \Eloquent $model - * @param array $data + * @param array $data * * @return bool + * @throws NotImplementedException */ public function update(\Eloquent $model, array $data) { @@ -58,6 +61,7 @@ class AccountType implements CUD, CommonDatabaseCalls * @param array $model * * @return array + * @throws NotImplementedException */ public function validate(array $model) { @@ -71,6 +75,7 @@ class AccountType implements CUD, CommonDatabaseCalls * @param int $id * * @return \Eloquent + * @throws NotImplementedException */ public function find($id) { @@ -115,6 +120,7 @@ class AccountType implements CUD, CommonDatabaseCalls * Returns all objects. * * @return Collection + * @throws NotImplementedException */ public function get() { @@ -126,6 +132,7 @@ class AccountType implements CUD, CommonDatabaseCalls * @param array $ids * * @return Collection + * @throws NotImplementedException */ public function getByIds(array $ids) { diff --git a/app/lib/FireflyIII/Database/Budget.php b/app/lib/FireflyIII/Database/Budget.php index 5ed3b18e6d..16adbb4e6d 100644 --- a/app/lib/FireflyIII/Database/Budget.php +++ b/app/lib/FireflyIII/Database/Budget.php @@ -136,6 +136,7 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface * @param $what * * @return \AccountType|null + * @throws NotImplementedException */ public function findByWhat($what) { @@ -159,6 +160,7 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface * @param array $ids * * @return Collection + * @throws NotImplementedException */ public function getByIds(array $ids) { @@ -200,6 +202,12 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface return \Paginator::make($items, $count, $take); } + /** + * @param \Budget $budget + * @param int $limit + * + * @return \Illuminate\Pagination\Paginator + */ public function getTransactionJournals(\Budget $budget, $limit = 50) { $offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0; @@ -214,6 +222,13 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface } + /** + * @param \Budget $budget + * @param \LimitRepetition $repetition + * @param int $limit + * + * @return \Illuminate\Pagination\Paginator + */ public function getTransactionJournalsInRepetition(\Budget $budget, \LimitRepetition $repetition, $limit = 50) { $start = $repetition->startdate; @@ -241,8 +256,8 @@ class Budget implements CUD, CommonDatabaseCalls, BudgetInterface public function repetitionOnStartingOnDate(\Budget $budget, Carbon $date) { return \LimitRepetition:: - leftJoin('limits', 'limit_repetitions.limit_id', '=', 'limits.id')->leftJoin( - 'components', 'limits.component_id', '=', 'components.id' + leftJoin('budget_limits', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id')->leftJoin( + 'components', 'budget_limits.component_id', '=', 'components.id' )->where('limit_repetitions.startdate', $date->format('Y-m-d'))->where( 'components.id', $budget->id )->first(['limit_repetitions.*']); diff --git a/app/lib/FireflyIII/Database/Category.php b/app/lib/FireflyIII/Database/Category.php index 649dfc47ea..88b1c59b35 100644 --- a/app/lib/FireflyIII/Database/Category.php +++ b/app/lib/FireflyIII/Database/Category.php @@ -124,6 +124,7 @@ class Category implements CUD, CommonDatabaseCalls * @param int $id * * @return \Eloquent + * @throws NotImplementedException */ public function find($id) { @@ -137,6 +138,7 @@ class Category implements CUD, CommonDatabaseCalls * @param $what * * @return \AccountType|null + * @throws NotImplementedException */ public function findByWhat($what) { @@ -158,6 +160,7 @@ class Category implements CUD, CommonDatabaseCalls * @param array $ids * * @return Collection + * @throws NotImplementedException */ public function getByIds(array $ids) { @@ -165,11 +168,22 @@ class Category implements CUD, CommonDatabaseCalls throw new NotImplementedException; } + /** + * @param $name + * + * @return static + */ public function firstOrCreate($name) { return \Category::firstOrCreate(['user_id' => $this->getUser()->id, 'name' => $name]); } + /** + * @param \Category $category + * @param int $limit + * + * @return \Illuminate\Pagination\Paginator + */ public function getTransactionJournals(\Category $category, $limit = 50) { $offset = intval(\Input::get('page')) > 0 ? intval(\Input::get('page')) * $limit : 0; @@ -185,10 +199,11 @@ class Category implements CUD, CommonDatabaseCalls } /** - * @param \Category $budget + * @param \Category $category * @param Carbon $date * * @return null + * @internal param \Category $budget */ public function repetitionOnStartingOnDate(\Category $category, Carbon $date) { diff --git a/app/lib/FireflyIII/Database/Ifaces/RecurringInterface.php b/app/lib/FireflyIII/Database/Ifaces/RecurringInterface.php index 5ff9a7aabb..426b507a76 100644 --- a/app/lib/FireflyIII/Database/Ifaces/RecurringInterface.php +++ b/app/lib/FireflyIII/Database/Ifaces/RecurringInterface.php @@ -13,10 +13,13 @@ interface RecurringInterface { /** * @param \RecurringTransaction $recurring - * @param Carbon $current - * @param Carbon $currentEnd + * @param Carbon $start + * @param Carbon $end + * + * @return null|\TransactionJournal + * @internal param Carbon $current + * @internal param Carbon $currentEnd * - * @return \TransactionJournal|null */ public function getJournalForRecurringInRange(\RecurringTransaction $recurring, Carbon $start, Carbon $end); diff --git a/app/lib/FireflyIII/Database/Ifaces/ReportInterface.php b/app/lib/FireflyIII/Database/Ifaces/ReportInterface.php index 192d388c90..90aef7181a 100644 --- a/app/lib/FireflyIII/Database/Ifaces/ReportInterface.php +++ b/app/lib/FireflyIII/Database/Ifaces/ReportInterface.php @@ -5,6 +5,11 @@ namespace FireflyIII\Database\Ifaces; use Carbon\Carbon; +/** + * Interface ReportInterface + * + * @package FireflyIII\Database\Ifaces + */ interface ReportInterface { diff --git a/app/lib/FireflyIII/Database/Piggybank.php b/app/lib/FireflyIII/Database/Piggybank.php index f416900a4c..0f8c4e58f6 100644 --- a/app/lib/FireflyIII/Database/Piggybank.php +++ b/app/lib/FireflyIII/Database/Piggybank.php @@ -203,6 +203,7 @@ class Piggybank implements CUD, CommonDatabaseCalls, PiggybankInterface * @param $what * * @return \AccountType|null + * @throws NotImplementedException */ public function findByWhat($what) { @@ -224,6 +225,7 @@ class Piggybank implements CUD, CommonDatabaseCalls, PiggybankInterface * @param array $ids * * @return Collection + * @throws NotImplementedException */ public function getByIds(array $ids) { @@ -231,7 +233,16 @@ class Piggybank implements CUD, CommonDatabaseCalls, PiggybankInterface throw new NotImplementedException; } - public function findRepetitionByDate(\Piggybank $piggybank, Carbon $date) + /** + * @param \Piggybank $piggybank + * @param Carbon $date + * + * @return mixed + * @throws FireflyException + * @throws NotImplementedException + */ + public function findRepetitionByDate(\Piggybank $piggybank, /** @noinspection PhpUnusedParameterInspection */ + Carbon $date) { $reps = $piggybank->piggybankrepetitions()->get(); if ($reps->count() == 1) { diff --git a/app/lib/FireflyIII/Database/Recurring.php b/app/lib/FireflyIII/Database/Recurring.php index d87a7f2b33..d503230d97 100644 --- a/app/lib/FireflyIII/Database/Recurring.php +++ b/app/lib/FireflyIII/Database/Recurring.php @@ -183,6 +183,7 @@ class Recurring implements CUD, CommonDatabaseCalls, RecurringInterface * @param int $id * * @return \Eloquent + * @throws NotImplementedException */ public function find($id) { @@ -196,6 +197,7 @@ class Recurring implements CUD, CommonDatabaseCalls, RecurringInterface * @param $what * * @return \AccountType|null + * @throws NotImplementedException */ public function findByWhat($what) { @@ -217,6 +219,7 @@ class Recurring implements CUD, CommonDatabaseCalls, RecurringInterface * @param array $ids * * @return Collection + * @throws NotImplementedException */ public function getByIds(array $ids) { diff --git a/app/lib/FireflyIII/Database/RepeatedExpense.php b/app/lib/FireflyIII/Database/RepeatedExpense.php index e0294558ce..18d098bd8f 100644 --- a/app/lib/FireflyIII/Database/RepeatedExpense.php +++ b/app/lib/FireflyIII/Database/RepeatedExpense.php @@ -13,6 +13,11 @@ use Illuminate\Support\Collection; use Illuminate\Support\MessageBag; +/** + * Class RepeatedExpense + * + * @package FireflyIII\Database + */ class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggybankInterface { use SwitchUser; @@ -30,6 +35,8 @@ class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggybankInterface * other variables this method tries to divide the piggy bank into equal parts. Each is * accommodated by a reminder (if everything goes to plan). * + * @param \PiggybankRepetition $repetition + * * @return \PiggybankRepetition */ public function calculateParts(\PiggybankRepetition $repetition) @@ -98,7 +105,7 @@ class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggybankInterface foreach ($bars as $index => $bar) { $bar->setAmountPerBar($amountPerBar); $bar->setCumulativeAmount($cumulative); - if($parts -1 == $index) { + if ($parts - 1 == $index) { $bar->setCumulativeAmount($piggyBank->targetamount); } @@ -275,6 +282,7 @@ class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggybankInterface * @param \Eloquent $model * * @return bool + * @throws NotImplementedException */ public function destroy(\Eloquent $model) { @@ -316,9 +324,10 @@ class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggybankInterface /** * @param \Eloquent $model - * @param array $data + * @param array $data * * @return bool + * @throws NotImplementedException */ public function update(\Eloquent $model, array $data) { @@ -426,6 +435,7 @@ class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggybankInterface * @param int $id * * @return \Eloquent + * @throws NotImplementedException */ public function find($id) { @@ -439,6 +449,7 @@ class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggybankInterface * @param $what * * @return \AccountType|null + * @throws NotImplementedException */ public function findByWhat($what) { @@ -460,6 +471,7 @@ class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggybankInterface * @param array $ids * * @return Collection + * @throws NotImplementedException */ public function getByIds(array $ids) { @@ -471,6 +483,7 @@ class RepeatedExpense implements CUD, CommonDatabaseCalls, PiggybankInterface * @param \Account $account * * @return float + * @throws NotImplementedException */ public function leftOnAccount(\Account $account) { diff --git a/app/lib/FireflyIII/Database/Report.php b/app/lib/FireflyIII/Database/Report.php index 4cd5d5238c..7de6f79481 100644 --- a/app/lib/FireflyIII/Database/Report.php +++ b/app/lib/FireflyIII/Database/Report.php @@ -12,6 +12,11 @@ namespace FireflyIII\Database; use Carbon\Carbon; use FireflyIII\Database\Ifaces\ReportInterface; +/** + * Class Report + * + * @package FireflyIII\Database + */ class Report implements ReportInterface { use SwitchUser; diff --git a/app/lib/FireflyIII/Database/Transaction.php b/app/lib/FireflyIII/Database/Transaction.php index 514ea66217..566c41c9de 100644 --- a/app/lib/FireflyIII/Database/Transaction.php +++ b/app/lib/FireflyIII/Database/Transaction.php @@ -24,6 +24,7 @@ class Transaction implements CUD, CommonDatabaseCalls * @param \Eloquent $model * * @return bool + * @throws NotImplementedException */ public function destroy(\Eloquent $model) { @@ -35,6 +36,7 @@ class Transaction implements CUD, CommonDatabaseCalls * @param array $data * * @return \Eloquent + * @throws FireflyException */ public function store(array $data) { @@ -59,9 +61,10 @@ class Transaction implements CUD, CommonDatabaseCalls /** * @param \Eloquent $model - * @param array $data + * @param array $data * * @return bool + * @throws NotImplementedException */ public function update(\Eloquent $model, array $data) { @@ -141,6 +144,7 @@ class Transaction implements CUD, CommonDatabaseCalls * @param int $id * * @return \Eloquent + * @throws NotImplementedException */ public function find($id) { @@ -154,6 +158,7 @@ class Transaction implements CUD, CommonDatabaseCalls * @param $what * * @return \AccountType|null + * @throws NotImplementedException */ public function findByWhat($what) { @@ -165,6 +170,7 @@ class Transaction implements CUD, CommonDatabaseCalls * Returns all objects. * * @return Collection + * @throws NotImplementedException */ public function get() { @@ -176,6 +182,7 @@ class Transaction implements CUD, CommonDatabaseCalls * @param array $ids * * @return Collection + * @throws NotImplementedException */ public function getByIds(array $ids) { diff --git a/app/lib/FireflyIII/Database/TransactionJournal.php b/app/lib/FireflyIII/Database/TransactionJournal.php index 4a51e9e607..a05f8d5e62 100644 --- a/app/lib/FireflyIII/Database/TransactionJournal.php +++ b/app/lib/FireflyIII/Database/TransactionJournal.php @@ -58,6 +58,7 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData * @param array $data * * @return \Eloquent + * @throws FireflyException */ public function store(array $data) { @@ -174,6 +175,7 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData * @param array $data * * @return bool + * @throws FireflyException */ public function update(\Eloquent $model, array $data) { @@ -186,9 +188,6 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData /** @var \FireflyIII\Database\TransactionCurrency $currencyRepository */ $currencyRepository = \App::make('FireflyIII\Database\TransactionCurrency'); - /** @var \FireflyIII\Database\Transaction $transactionRepository */ - $transactionRepository = \App::make('FireflyIII\Database\Transaction'); - $journalType = $typeRepository->findByWhat($data['what']); $currency = $currencyRepository->findByCode($data['currency']); @@ -284,6 +283,7 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData * @param array $model * * @return array + * @throws FireflyException */ public function validate(array $model) { @@ -350,7 +350,6 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData /* * Many checks to catch invalid or not-existing accounts. */ - $accountError = false; switch (true) { // this combination is often seen in withdrawals. case (isset($model['account_id']) && isset($model['expense_account'])): @@ -458,6 +457,7 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData * @param $what * * @return \AccountType|null + * @throws NotImplementedException */ public function findByWhat($what) { @@ -560,6 +560,11 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData return $sum; } + /** + * @param int $limit + * + * @return \Illuminate\Pagination\Paginator + */ public function getDepositsPaginated($limit = 50) { $offset = intval(\Input::get('page')) > 0 ? (intval(\Input::get('page')) - 1) * $limit : 0; @@ -599,6 +604,11 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData return $query; } + /** + * @param int $limit + * + * @return \Illuminate\Pagination\Paginator + */ public function getTransfersPaginated($limit = 50) { $offset = intval(\Input::get('page')) > 0 ? (intval(\Input::get('page')) - 1) * $limit : 0; @@ -615,6 +625,11 @@ class TransactionJournal implements TransactionJournalInterface, CUD, CommonData return \Paginator::make($items, $count, $limit); } + /** + * @param int $limit + * + * @return \Illuminate\Pagination\Paginator + */ public function getWithdrawalsPaginated($limit = 50) { $offset = intval(\Input::get('page')) > 0 ? (intval(\Input::get('page')) - 1) * $limit : 0; diff --git a/app/lib/FireflyIII/Database/TransactionType.php b/app/lib/FireflyIII/Database/TransactionType.php index 566c60ba45..8c19431c34 100644 --- a/app/lib/FireflyIII/Database/TransactionType.php +++ b/app/lib/FireflyIII/Database/TransactionType.php @@ -23,6 +23,7 @@ class TransactionType implements CUD, CommonDatabaseCalls * @param \Eloquent $model * * @return bool + * @throws NotImplementedException */ public function destroy(\Eloquent $model) { @@ -34,6 +35,7 @@ class TransactionType implements CUD, CommonDatabaseCalls * @param array $data * * @return \Eloquent + * @throws NotImplementedException */ public function store(array $data) { @@ -43,9 +45,10 @@ class TransactionType implements CUD, CommonDatabaseCalls /** * @param \Eloquent $model - * @param array $data + * @param array $data * * @return bool + * @throws NotImplementedException */ public function update(\Eloquent $model, array $data) { @@ -60,6 +63,7 @@ class TransactionType implements CUD, CommonDatabaseCalls * @param array $model * * @return array + * @throws NotImplementedException */ public function validate(array $model) { @@ -73,6 +77,7 @@ class TransactionType implements CUD, CommonDatabaseCalls * @param int $id * * @return \Eloquent + * @throws NotImplementedException */ public function find($id) { @@ -86,6 +91,7 @@ class TransactionType implements CUD, CommonDatabaseCalls * @param $what * * @return \AccountType|null + * @throws FireflyException */ public function findByWhat($what) { @@ -114,6 +120,7 @@ class TransactionType implements CUD, CommonDatabaseCalls * Returns all objects. * * @return Collection + * @throws NotImplementedException */ public function get() { @@ -125,6 +132,7 @@ class TransactionType implements CUD, CommonDatabaseCalls * @param array $ids * * @return Collection + * @throws NotImplementedException */ public function getByIds(array $ids) { diff --git a/app/lib/FireflyIII/Event/Account.php b/app/lib/FireflyIII/Event/Account.php index 7b265b9816..bdc87d8e9a 100644 --- a/app/lib/FireflyIII/Event/Account.php +++ b/app/lib/FireflyIII/Event/Account.php @@ -5,14 +5,25 @@ namespace FireflyIII\Event; use Illuminate\Events\Dispatcher; +/** + * Class Account + * + * @package FireflyIII\Event + */ class Account { + /** + * @param \Account $account + */ public function destroy(\Account $account) { \Cache::forget('account.' . $account->id . '.latestBalance'); \Cache::forget('account.' . $account->id . '.lastActivityDate'); } + /** + * @param \Account $account + */ public function store(\Account $account) { @@ -31,6 +42,9 @@ class Account $events->listen('account.destroy', 'FireflyIII\Event\Account@destroy'); } + /** + * @param \Account $account + */ public function update(\Account $account) { \Cache::forget('account.' . $account->id . '.latestBalance'); diff --git a/app/lib/FireflyIII/Event/Budget.php b/app/lib/FireflyIII/Event/Budget.php index adbd8abb95..f40e02b958 100644 --- a/app/lib/FireflyIII/Event/Budget.php +++ b/app/lib/FireflyIII/Event/Budget.php @@ -5,35 +5,40 @@ namespace FireflyIII\Event; use Illuminate\Database\QueryException; use Illuminate\Events\Dispatcher; +/** + * Class Budget + * + * @package FireflyIII\Event + */ class Budget { /** - * @param \Limit $limit + * @param \BudgetLimit $budgetLimit */ - public function storeOrUpdateLimit(\Limit $limit) + public function storeOrUpdateLimit(\BudgetLimit $budgetLimit) { - $end = \DateKit::addPeriod(clone $limit->startdate, $limit->repeat_freq, 0); + $end = \DateKit::addPeriod(clone $budgetLimit->startdate, $budgetLimit->repeat_freq, 0); $end->subDay(); - $set = $limit->limitrepetitions()->where('startdate', $limit->startdate->format('Y-m-d'))->where('enddate', $end->format('Y-m-d'))->get(); + $set = $budgetLimit->limitrepetitions()->where('startdate', $budgetLimit->startdate->format('Y-m-d'))->where('enddate', $end->format('Y-m-d'))->get(); /* * Create new LimitRepetition: */ if ($set->count() == 0) { $repetition = new \LimitRepetition(); - $repetition->startdate = $limit->startdate; + $repetition->startdate = $budgetLimit->startdate; $repetition->enddate = $end; - $repetition->amount = $limit->amount; - $repetition->limit()->associate($limit); + $repetition->amount = $budgetLimit->amount; + $repetition->budgetLimit()->associate($budgetLimit); try { $repetition->save(); } catch (QueryException $e) { - \Log::error('Trying to save new Limitrepetition failed!'); + \Log::error('Trying to save new LimitRepetition failed!'); \Log::error($e->getMessage()); } } else { @@ -42,7 +47,7 @@ class Budget * Update existing one. */ $repetition = $set->first(); - $repetition->amount = $limit->amount; + $repetition->amount = $budgetLimit->amount; $repetition->save(); } diff --git a/app/lib/FireflyIII/Event/Event.php b/app/lib/FireflyIII/Event/Event.php index 1f670ccb20..0f4bfda97a 100644 --- a/app/lib/FireflyIII/Event/Event.php +++ b/app/lib/FireflyIII/Event/Event.php @@ -4,9 +4,19 @@ namespace FireflyIII\Event; use Illuminate\Events\Dispatcher; +/** + * Class Event + * + * @package FireflyIII\Event + */ class Event { + /** + * @param \Account $account + * + * @throws \Exception + */ public function deleteAccount(\Account $account) { // get piggy banks diff --git a/app/lib/FireflyIII/Event/Piggybank.php b/app/lib/FireflyIII/Event/Piggybank.php index 05657efafb..206c165988 100644 --- a/app/lib/FireflyIII/Event/Piggybank.php +++ b/app/lib/FireflyIII/Event/Piggybank.php @@ -6,6 +6,11 @@ namespace FireflyIII\Event; use Carbon\Carbon; use Illuminate\Events\Dispatcher; +/** + * Class Piggybank + * + * @package FireflyIII\Event + */ class Piggybank { @@ -21,13 +26,19 @@ class Piggybank $event->amount = floatval($amount); $event->date = new Carbon; if (!$event->isValid()) { - var_dump($event->getErrors()); - exit(); + \Log::error($event->getErrors()); + \App::abort(500); } $event->save(); } } + /** + * @param \TransactionJournal $journal + * + * @throws \FireflyIII\Exception\FireflyException + * @throws \FireflyIII\Exception\NotImplementedException + */ public function destroyTransfer(\TransactionJournal $journal) { if ($journal->piggybankevents()->count() > 0) { @@ -88,6 +99,9 @@ class Piggybank } } + /** + * @param \Piggybank $piggybank + */ public function storePiggybank(\Piggybank $piggybank) { if (intval($piggybank->repeats) == 0) { @@ -250,6 +264,9 @@ class Piggybank } } + /** + * @param \Piggybank $piggyBank + */ public function updatePiggybank(\Piggybank $piggyBank) { // get the repetition: @@ -259,6 +276,12 @@ class Piggybank $repetition->save(); } + /** + * @param \TransactionJournal $journal + * + * @throws \FireflyIII\Exception\FireflyException + * @throws \FireflyIII\Exception\NotImplementedException + */ public function updateTransfer(\TransactionJournal $journal) { diff --git a/app/lib/FireflyIII/Event/Transaction.php b/app/lib/FireflyIII/Event/Transaction.php index 285e942875..e5d53e04f5 100644 --- a/app/lib/FireflyIII/Event/Transaction.php +++ b/app/lib/FireflyIII/Event/Transaction.php @@ -5,14 +5,25 @@ namespace FireflyIII\Event; use Illuminate\Events\Dispatcher; +/** + * Class Transaction + * + * @package FireflyIII\Event + */ class Transaction { + /** + * @param \Transaction $transaction + */ public function destroy(\Transaction $transaction) { \Cache::forget('account.' . $transaction->account_id . '.latestBalance'); \Cache::forget('account.' . $transaction->account_id . '.lastActivityDate'); } + /** + * @param \Transaction $transaction + */ public function store(\Transaction $transaction) { \Cache::forget('account.' . $transaction->account_id . '.latestBalance'); @@ -30,6 +41,9 @@ class Transaction $events->listen('transaction.destroy', 'FireflyIII\Event\Transaction@destroy'); } + /** + * @param \Transaction $transaction + */ public function update(\Transaction $transaction) { \Cache::forget('account.' . $transaction->account_id . '.latestBalance'); diff --git a/app/lib/FireflyIII/Event/TransactionJournal.php b/app/lib/FireflyIII/Event/TransactionJournal.php index aabc4c0537..88353e34ee 100644 --- a/app/lib/FireflyIII/Event/TransactionJournal.php +++ b/app/lib/FireflyIII/Event/TransactionJournal.php @@ -4,10 +4,19 @@ namespace FireflyIII\Event; use Illuminate\Events\Dispatcher; +/** + * Class TransactionJournal + * + * @package FireflyIII\Event + */ class TransactionJournal { - public function store(\TransactionJournal $journal, $id = 0) + /** + * @param \TransactionJournal $journal + * @param int $id + */ + public function store(\TransactionJournal $journal) { /** @var \FireflyIII\Database\Recurring $repository */ $repository = \App::make('FireflyIII\Database\Recurring'); @@ -30,6 +39,9 @@ class TransactionJournal $events->listen('transactionJournal.update', 'FireflyIII\Event\TransactionJournal@update'); } + /** + * @param \TransactionJournal $journal + */ public function update(\TransactionJournal $journal) { /** @var \FireflyIII\Database\Recurring $repository */ diff --git a/app/lib/FireflyIII/Form/Form.php b/app/lib/FireflyIII/Form/Form.php index 9b11b13678..4f8bda184d 100644 --- a/app/lib/FireflyIII/Form/Form.php +++ b/app/lib/FireflyIII/Form/Form.php @@ -287,18 +287,17 @@ class Form /* * Store. */ - $store = ''; switch ($type) { case 'create': - $store = '
'; + $store = '
'; $store .= '
'; break; case 'update': - $store = '
'; + $store = '
'; $store .= '
'; break; default: @@ -309,9 +308,9 @@ class Form /* * validate is always the same: */ - $validate = '