Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Some code cleanup.
James Cole812aae358fbc
diff --git a/app/Helpers/Collection/BalanceLine.php b/app/Helpers/Collection/BalanceLine.phpindex a3d64ff7e3..de82b6814d 100644--- a/app/Helpers/Collection/BalanceLine.php+++ b/app/Helpers/Collection/BalanceLine.php@@ -64,6 +64,7 @@ class BalanceLineif ($this->getRole() == self::ROLE_DIFFROLE) {return trans('firefly.leftUnbalanced');}+ return '';}/**diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.phpindex bb77e99b52..986d324e50 100644--- a/app/Helpers/Report/ReportHelper.php+++ b/app/Helpers/Report/ReportHelper.php@@ -70,7 +70,8 @@ class ReportHelper implements ReportHelperInterfaceif ($account->accountType->type != 'Cash account') {return $account;}- } // @codeCoverageIgnore+ return null;+ });// summarize:diff --git a/app/Helpers/Report/ReportQuery.php b/app/Helpers/Report/ReportQuery.phpindex 8675989368..ad1a6d575a 100644--- a/app/Helpers/Report/ReportQuery.php+++ b/app/Helpers/Report/ReportQuery.php@@ -72,7 +72,8 @@ class ReportQuery implements ReportQueryInterfaceif ($journal->amount != 0) {return $journal;}- } // @codeCoverageIgnore+ return null;+ });return $data;@@ -188,7 +189,8 @@ class ReportQuery implements ReportQueryInterfaceif ($journal->amount != 0) {return $journal;}- } // @codeCoverageIgnore+ return null;+ });return $data;diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.phpindex 70d39f6040..b583e62c71 100644--- a/app/Http/Controllers/BudgetController.php+++ b/app/Http/Controllers/BudgetController.php@@ -20,6 +20,7 @@ use View;* Class BudgetController** @package FireflyIII\Http\Controllers+ * @SuppressWarnings(PHPMD.TooManyMethods)*/class BudgetController extends Controller{diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.phpindex 5460b9212b..5c9e11e3c1 100644--- a/app/Http/Controllers/Chart/AccountController.php+++ b/app/Http/Controllers/Chart/AccountController.php@@ -26,6 +26,10 @@ class AccountController extends Controller* @param GChart $chart* @param AccountRepositoryInterface $repository*+ * @param $year+ * @param $month+ * @param bool $shared+ ** @return \Symfony\Component\HttpFoundation\Response*/public function all(GChart $chart, AccountRepositoryInterface $repository, $year, $month, $shared = false)@@ -38,7 +42,6 @@ class AccountController extends Controller/** @var Collection $accounts */$accounts = $repository->getAccounts(['Default account', 'Asset account']);if ($shared === false) {- // remove the shared accounts from the collection:/** @var Account $account */foreach ($accounts as $index => $account) {if ($account->getMeta('accountRole') == 'sharedAsset') {@@ -71,7 +74,6 @@ class AccountController extends Controller$chart->generate();return Response::json($chart->getData());-}/**diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.phpindex a49f294630..195b3c4458 100644--- a/app/Http/Controllers/Chart/BudgetController.php+++ b/app/Http/Controllers/Chart/BudgetController.php@@ -25,6 +25,8 @@ class BudgetController extends Controller* @param GChart $chart* @param BudgetRepositoryInterface $repository* @param Budget $budget+ *+ * @return \Symfony\Component\HttpFoundation\Response*/public function budget(GChart $chart, BudgetRepositoryInterface $repository, Budget $budget){diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.phpindex 44f87a3463..d6ebe48f18 100644--- a/app/Http/Controllers/PiggyBankController.php+++ b/app/Http/Controllers/PiggyBankController.php@@ -18,6 +18,9 @@ use URL;use View;/**+ *+ * @SuppressWarnings(PHPMD.TooManyMethods)+ ** Class PiggyBankController** @package FireflyIII\Http\Controllersdiff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.phpindex 28d47123aa..8a73839482 100644--- a/app/Http/Controllers/TagController.php+++ b/app/Http/Controllers/TagController.php@@ -111,7 +111,9 @@ class TagController extends Controller}/**- * @param Tag $tag+ * @param Tag $tag+ *+ * @param TagRepositoryInterface $repository** @return View*/diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.phpindex c1c21adbbc..ad24e7a712 100644--- a/app/Models/TransactionJournal.php+++ b/app/Models/TransactionJournal.php@@ -12,6 +12,8 @@ use Watson\Validating\ValidatingTrait;* Class TransactionJournal** @package FireflyIII\Models+ *+ * @SuppressWarnings(PHPMD.TooManyMethods)*/class TransactionJournal extends Model{diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.phpindex a79274200f..0f03b71f3d 100644--- a/app/Repositories/Account/AccountRepository.php+++ b/app/Repositories/Account/AccountRepository.php@@ -25,6 +25,8 @@ use Steam;/**+ * @SuppressWarnings(PHPMD.TooManyMethods)+ ** Class AccountRepository** @package FireflyIII\Repositories\Account@@ -306,7 +308,8 @@ class AccountRepository implements AccountRepositoryInterfaceif ($journal->destination_account->id == $account->id) {return $journal;}- } // @codeCoverageIgnore+ return null;+ });return $filtered;@@ -398,7 +401,6 @@ class AccountRepository implements AccountRepositoryInterface// update meta data:$this->updateMetadata($account, $data);-$openingBalance = $this->openingBalanceTransaction($account);// if has openingbalance?@@ -421,10 +423,8 @@ class AccountRepository implements AccountRepositoryInterface}} else {- // opening balance is zero, should we delete it?- if ($openingBalance) {- // delete existing opening balance.- $openingBalance->delete();+ if ($openingBalance) { // opening balance is zero, should we delete it?+ $openingBalance->delete();// delete existing opening balance.}}diff --git a/app/Support/ExpandedForm.php b/app/Support/ExpandedForm.phpindex 8e5d4fe7a4..bac40078a4 100644--- a/app/Support/ExpandedForm.php+++ b/app/Support/ExpandedForm.php@@ -3,6 +3,7 @@namespace FireflyIII\Support;use Amount as Amt;+use Eloquent;use Illuminate\Support\Collection;use Illuminate\Support\MessageBag;use Input;@@ -13,6 +14,8 @@ use View;* Class ExpandedForm** @package FireflyIII\Support+ *+ * @SuppressWarnings(PHPMD.TooManyMethods)*/class ExpandedForm{@@ -46,7 +49,7 @@ class ExpandedForm** @return mixed*/- public function label($name, $options)+ protected function label($name, $options){if (isset($options['label'])) {return $options['label'];@@ -63,7 +66,7 @@ class ExpandedForm** @return array*/- public function expandOptionArray($name, $label, array $options)+ protected function expandOptionArray($name, $label, array $options){$options['class'] = 'form-control';$options['id'] = 'ffInput_' . $name;@@ -78,7 +81,7 @@ class ExpandedForm** @return string*/- public function getHolderClasses($name)+ protected function getHolderClasses($name){/** Get errors from session:@@ -100,7 +103,7 @@ class ExpandedForm** @return mixed*/- public function fillFieldValue($name, $value)+ protected function fillFieldValue($name, $value){if (Session::has('preFilled')) {$preFilled = Session::get('preFilled');diff --git a/app/Support/Navigation.php b/app/Support/Navigation.phpindex bfb3c607a2..542cd669f3 100644--- a/app/Support/Navigation.php+++ b/app/Support/Navigation.php@@ -140,117 +140,6 @@ class Navigationreturn $currentEnd;}- /**- * @param $range- * @param Carbon $date- *- * @return Carbon- * @throws FireflyException- */- public function jumpToNext($range, Carbon $date)- {- switch ($range) {- case '1D':- $date->endOfDay()->addDay();- break;- case '1W':- $date->endOfWeek()->addDay()->startOfWeek();- break;- case '1M':- $date->endOfMonth()->addDay()->startOfMonth();- break;- case '3M':- $date->lastOfQuarter()->addDay();- break;- case '6M':- if ($date->month >= 7) {- $date->startOfYear()->addYear();- } else {- $date->startOfYear()->addMonths(6);- }- break;- case '1Y':- $date->startOfYear()->addYear();- break;- default:- throw new FireflyException('Cannot do _next() on ' . $range);- break;- }-- return $date;- }-- /**- * @param $range- * @param Carbon $date- *- * @return Carbon- * @throws FireflyException- */- public function jumpToPrevious($range, Carbon $date)- {- $functionMap = [- '1D' => 'Day',- '1W' => 'Week',- '1M' => 'Month',- '1Y' => 'Year'- ];-- if (isset($functionMap[$range])) {- $startFunction = 'startOf' . $functionMap[$range];- $subFunction = 'sub' . $functionMap[$range];- $date->$startFunction()->$subFunction();-- return $date;- }- if ($range == '3M') {- $date->firstOfQuarter()->subMonths(3)->firstOfQuarter();-- return $date;- }- if ($range == '6M') {- $date->startOfYear();- if ($date->month <= 6) {- $date->subMonths(6);- }-- return $date;- }- throw new FireflyException('Cannot do _previous() on ' . $range);- }-- /**- * @param $range- * @param Carbon $date- *- * @return string- * @throws FireflyException- */- public function periodName($range, Carbon $date)- {- $formatMap = [- '1D' => 'jS F Y',- '1W' => '\w\e\ek W, Y',- '1M' => 'F Y',- '1Y' => 'Y',- ];- if (isset($formatMap[$range])) {- return $date->format($formatMap[$range]);- }- if ($range == '3M') {--- return 'Q' . ceil(($date->month / 12) * 4) . ' ' . $date->year;- }- if ($range == '6M') {- $half = ceil(($date->month / 12) * 2);- $halfName = $half == 1 ? 'first' : 'second';-- return $halfName . ' half of ' . $date->year;- }- throw new FireflyException('No _periodName() for range "' . $range . '"');- }-/*** @param Carbon $date* @param $repeatFrequencydiff --git a/app/Support/Preferences.php b/app/Support/Preferences.phpindex a4adfb586f..3d53d9c16a 100644--- a/app/Support/Preferences.php+++ b/app/Support/Preferences.php@@ -4,7 +4,6 @@ namespace FireflyIII\Support;use Auth;use FireflyIII\Models\Preference;-use Log;/*** Class Preferencesdiff --git a/app/Support/Steam.php b/app/Support/Steam.phpindex d49affdc2d..a04e3ee002 100644--- a/app/Support/Steam.php+++ b/app/Support/Steam.php@@ -6,7 +6,6 @@ use Carbon\Carbon;use FireflyIII\Models\Account;use FireflyIII\Models\PiggyBank;use FireflyIII\Models\PiggyBankRepetition;-use Illuminate\Support\Collection;/*** Class Steam@@ -50,155 +49,4 @@ class Steamreturn round($balance, 2);}- /**- * Only return the top X entries, group the rest by amount- * and described as 'Others'. id = 0 as well- *- * @param array $array- * @param int $limit- *- * @return array- */- public function limitArray(array $array, $limit = 10)- {- $others = [- 'name' => 'Others',- 'queryAmount' => 0- ];- $return = [];- $count = 0;- foreach ($array as $id => $entry) {- if ($count < ($limit - 1)) {- $return[$id] = $entry;- } else {- $others['queryAmount'] += $entry['queryAmount'];- }-- $count++;- }- $return[0] = $others;-- return $return;-- }-- /**- * Turns a collection into an array. Needs the field 'id' for the key,- * and saves only 'name' and 'amount' as a sub array.- *- * @param \Illuminate\Support\Collection $collection- *- * @return array- */- public function makeArray(Collection $collection)- {- $array = [];- foreach ($collection as $entry) {- $entry->spent = isset($entry->spent) ? floatval($entry->spent) : 0.0;- $id = intval($entry->id);- if (isset($array[$id])) {- $array[$id]['amount'] += floatval($entry->amount);- $array[$id]['queryAmount'] += floatval($entry->queryAmount);- $array[$id]['spent'] += floatval($entry->spent);- $array[$id]['encrypted'] = intval($entry->encrypted);- } else {- $array[$id] = [- 'amount' => floatval($entry->amount),- 'queryAmount' => floatval($entry->queryAmount),- 'spent' => floatval($entry->spent),- 'encrypted' => intval($entry->encrypted),- 'name' => $entry->name- ];- }- }-- return $array;- }-- /**- * Merges two of the arrays as defined above. Can't handle more (yet)- *- * @param array $one- * @param array $two- *- * @return array- */- public function mergeArrays(array $one, array $two)- {- foreach ($two as $id => $value) {- // $otherId also exists in $one:- if (isset($one[$id])) {- $one[$id]['queryAmount'] += $value['queryAmount'];- $one[$id]['spent'] += $value['spent'];- } else {- $one[$id] = $value;- }- }-- return $one;- }-- /**- * @param PiggyBank $piggyBank- * @param PiggyBankRepetition $repetition- *- * @return int- */- public function percentage(PiggyBank $piggyBank, PiggyBankRepetition $repetition)- {- $pct = $repetition->currentamount / $piggyBank->targetamount * 100;- if ($pct > 100) {- // @codeCoverageIgnoreStart- return 100;- // @codeCoverageIgnoreEnd- } else {- return floor($pct);- }- }-- /**- * Sort an array where all 'amount' keys are positive floats.- *- * @param array $array- *- * @return array- */- public function sortArray(array $array)- {- uasort(- $array, function ($left, $right) {- if ($left['queryAmount'] == $right['queryAmount']) {- return 0;- }-- return ($left['queryAmount'] < $right['queryAmount']) ? 1 : -1;- }- );-- return $array;-- }-- /**- * Sort an array where all 'amount' keys are negative floats.- *- * @param array $array- *- * @return array- */- public function sortNegativeArray(array $array)- {- uasort(- $array, function ($left, $right) {- if ($left['queryAmount'] == $right['queryAmount']) {- return 0;- }-- return ($left['queryAmount'] < $right['queryAmount']) ? -1 : 1;- }- );-- return $array;- }-}diff --git a/database/migrations/2015_05_22_172026_changes_for_v3409.php b/database/migrations/2015_05_22_172026_changes_for_v3409.phpindex 3f53f00441..5c401d8cdd 100644--- a/database/migrations/2015_05_22_172026_changes_for_v3409.php+++ b/database/migrations/2015_05_22_172026_changes_for_v3409.php@@ -18,60 +18,12 @@ class ChangesForV3409 extends Migration*/public function down(){- // remove decryption, but this will destroy amounts.-- Schema::table(- 'accounts', function (Blueprint $table) {- $table->dropColumn('virtual_balance_encrypted');- }- );-- Schema::table(- 'bills', function (Blueprint $table) {- $table->dropColumn('amount_min_encrypted');- $table->dropColumn('amount_max_encrypted');- }- );-- Schema::table(- 'budget_limits', function (Blueprint $table) {-- $table->dropColumn('amount_encrypted');- }- );- Schema::table(- 'limit_repetitions', function (Blueprint $table) {- $table->dropColumn('amount_encrypted');- }- );- Schema::table(- 'piggy_bank_events', function (Blueprint $table) {- $table->dropColumn('amount_encrypted');- }- );- Schema::table(- 'piggy_bank_repetitions', function (Blueprint $table) {- $table->dropColumn('currentamount_encrypted');- }- );-- Schema::table(- 'piggy_banks', function (Blueprint $table) {- $table->dropColumn('targetamount_encrypted');- }- );Schema::table('preferences', function (Blueprint $table) {$table->dropColumn('name_encrypted');$table->dropColumn('data_encrypted');});-- Schema::table(- 'transactions', function (Blueprint $table) {- $table->dropColumn('amount_encrypted');- }- );}/**@@ -81,52 +33,7 @@ class ChangesForV3409 extends Migration*/public function up(){- // encrypt account virtual balance:- Schema::table(- 'accounts', function (Blueprint $table) {- $table->string('virtual_balance_encrypted')->nullable()->after('virtual_balance');- }- );-- // encrypt bill amount_min and amount_max:- Schema::table(- 'bills', function (Blueprint $table) {- $table->string('amount_min_encrypted')->nullable()->after('amount_min');- $table->string('amount_max_encrypted')->nullable()->after('amount_max');- }- );-- // encrypt budget limit amount- Schema::table(- 'budget_limits', function (Blueprint $table) {- $table->string('amount_encrypted')->nullable()->after('amount');- }- );- // encrypt limit repetition amount- Schema::table(- 'limit_repetitions', function (Blueprint $table) {- $table->string('amount_encrypted')->nullable()->after('amount');- }- );- // encrypt piggy bank event amount- Schema::table(- 'piggy_bank_events', function (Blueprint $table) {- $table->string('amount_encrypted')->nullable()->after('amount');- }- );- // encrypt piggy bank repetition currentamount- Schema::table(- 'piggy_bank_repetitions', function (Blueprint $table) {- $table->string('currentamount_encrypted')->nullable()->after('currentamount');- }- );- // encrypt piggy bank targetamount- Schema::table(- 'piggy_banks', function (Blueprint $table) {- $table->string('targetamount_encrypted')->nullable()->after('targetamount');- }- );// encrypt preference name (add field)// encrypt preference data (add field)Schema::table(@@ -136,13 +43,6 @@ class ChangesForV3409 extends Migration});- // encrypt transaction amount- Schema::table(- 'transactions', function (Blueprint $table) {- $table->string('amount_encrypted')->nullable()->after('amount');- }- );-}}diff --git a/tests/controllers/charts/ChartBudgetControllerTest.php b/tests/controllers/charts/ChartBudgetControllerTest.phpindex 7c9777f5ef..4670313328 100644--- a/tests/controllers/charts/ChartBudgetControllerTest.php+++ b/tests/controllers/charts/ChartBudgetControllerTest.php@@ -76,6 +76,7 @@ class ChartBudgetControllerTest extends TestCase/*** @covers FireflyIII\Http\Controllers\Chart\BudgetController::frontpage+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)*/public function testFrontpage(){diff --git a/tests/helpers/ReminderHelperTest.php b/tests/helpers/ReminderHelperTest.phpindex 7e29e99860..82f289b41e 100644--- a/tests/helpers/ReminderHelperTest.php+++ b/tests/helpers/ReminderHelperTest.php@@ -8,6 +8,8 @@ use League\FactoryMuffin\Facade as FactoryMuffin;/*** Class ReminderHelperTest+ *+ * @SuppressWarnings(PHPMD.TooManyMethods)*/class ReminderHelperTest extends TestCase{diff --git a/tests/helpers/ReportHelperTest.php b/tests/helpers/ReportHelperTest.phpindex 9f5134f0c2..e321854f4f 100644--- a/tests/helpers/ReportHelperTest.php+++ b/tests/helpers/ReportHelperTest.php@@ -107,6 +107,7 @@ class ReportHelperTest extends TestCase/*** @covers FireflyIII\Helpers\Report\ReportHelper::getBillReport+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)*/public function testGetBillReport(){@@ -214,6 +215,7 @@ class ReportHelperTest extends TestCase/*** @covers FireflyIII\Helpers\Report\ReportHelper::getExpenseReport+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)*/public function testGetExpenseReport(){@@ -278,6 +280,7 @@ class ReportHelperTest extends TestCase/*** @covers FireflyIII\Helpers\Report\ReportHelper::getIncomeReport+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)*/public function testGetIncomeReport(){diff --git a/tests/helpers/ReportQueryTest.php b/tests/helpers/ReportQueryTest.phpindex 894d037af4..eb12e6e35d 100644--- a/tests/helpers/ReportQueryTest.php+++ b/tests/helpers/ReportQueryTest.php@@ -40,6 +40,7 @@ class ReportQueryTest extends TestCase/*** @covers FireflyIII\Helpers\Report\ReportQuery::expenseInPeriodCorrected* @covers FireflyIII\Helpers\Report\ReportQuery::queryJournalsWithTransactions+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)*/public function testExpenseInPeriodCorrected(){@@ -108,6 +109,7 @@ class ReportQueryTest extends TestCase/*** @covers FireflyIII\Helpers\Report\ReportQuery::expenseInPeriodCorrected* @covers FireflyIII\Helpers\Report\ReportQuery::queryJournalsWithTransactions+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)*/public function testExpenseInPeriodCorrectedShared(){@@ -228,6 +230,7 @@ class ReportQueryTest extends TestCase/*** @covers FireflyIII\Helpers\Report\ReportQuery::incomeInPeriodCorrected* @covers FireflyIII\Helpers\Report\ReportQuery::queryJournalsWithTransactions+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)*/public function testIncomeInPeriodCorrected(){@@ -295,6 +298,7 @@ class ReportQueryTest extends TestCase/*** @covers FireflyIII\Helpers\Report\ReportQuery::incomeInPeriodCorrected* @covers FireflyIII\Helpers\Report\ReportQuery::queryJournalsWithTransactions+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)*/public function testIncomeInPeriodCorrectedShared(){diff --git a/tests/models/AccountModelTest.php b/tests/models/AccountModelTest.phpindex 82636cf799..7537c9ea79 100644--- a/tests/models/AccountModelTest.php+++ b/tests/models/AccountModelTest.php@@ -69,7 +69,7 @@ class AccountModelTest extends TestCase{// create account:$account = FactoryMuffin::create('FireflyIII\Models\Account');- $user = FactoryMuffin::create('FireflyIII\User');+ FactoryMuffin::create('FireflyIII\User');// search for account with the same properties:$search = [@@ -118,7 +118,7 @@ class AccountModelTest extends TestCase{// create account:$account = FactoryMuffin::create('FireflyIII\Models\Account');- $user = FactoryMuffin::create('FireflyIII\User');+ FactoryMuffin::create('FireflyIII\User');// search for account with the same properties:$search = [diff --git a/tests/models/TransactionJournalModelTest.php b/tests/models/TransactionJournalModelTest.phpindex e9d625f616..dbdf86f035 100644--- a/tests/models/TransactionJournalModelTest.php+++ b/tests/models/TransactionJournalModelTest.php@@ -5,6 +5,7 @@ use League\FactoryMuffin\Facade as FactoryMuffin;/*** Class TransactionJournalModelTest+ * @SuppressWarnings(PHPMD.TooManyMethods)*/class TransactionJournalModelTest extends TestCase{diff --git a/tests/repositories/CategoryRepositoryTest.php b/tests/repositories/CategoryRepositoryTest.phpindex 6e235007ef..2ade3fae1e 100644--- a/tests/repositories/CategoryRepositoryTest.php+++ b/tests/repositories/CategoryRepositoryTest.php@@ -80,6 +80,7 @@ class CategoryRepositoryTest extends TestCase/*** @covers FireflyIII\Repositories\Category\CategoryRepository::getCategoriesAndExpensesCorrected+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)*/public function testGetCategoriesAndExpensesCorrected(){