Skip to content

Firefly III: a personal finances manager

Change scope of methods, add some notes. Prep for refactoring.

James Cole794316437547
diff --git a/app/Http/Controllers/Account/IndexController.php b/app/Http/Controllers/Account/IndexController.php
index 98da7143e4..b9e429ab91 100644
--- a/app/Http/Controllers/Account/IndexController.php
+++ b/app/Http/Controllers/Account/IndexController.php
@@ -127,7 +127,7 @@ class IndexController extends Controller
*
* @return null|mixed
*/
- protected function isInArray(array $array, int $entryId)
+ protected function isInArray(array $array, int $entryId) // helper for data (math, calculations)
{
$result = '0';
if (isset($array[$entryId])) {
diff --git a/app/Http/Controllers/Account/ReconcileController.php b/app/Http/Controllers/Account/ReconcileController.php
index 6e2e04fd09..b3adeaa54d 100644
--- a/app/Http/Controllers/Account/ReconcileController.php
+++ b/app/Http/Controllers/Account/ReconcileController.php
@@ -380,7 +380,7 @@ class ReconcileController extends Controller
*
* @throws FireflyException
*/
- private function redirectToOriginalAccount(Account $account)
+ protected function redirectToOriginalAccount(Account $account) // user redirection + nav
{
/** @var Transaction $transaction */
$transaction = $account->transactions()->first();
diff --git a/app/Http/Controllers/Account/ShowController.php b/app/Http/Controllers/Account/ShowController.php
index 7a7ee2a158..9b30915742 100644
--- a/app/Http/Controllers/Account/ShowController.php
+++ b/app/Http/Controllers/Account/ShowController.php
@@ -187,7 +187,7 @@ class ShowController extends Controller
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
- private function getPeriodOverview(Account $account, ?Carbon $date): Collection
+ protected function getPeriodOverview(Account $account, ?Carbon $date): Collection // period overview
{
$range = app('preferences')->get('viewRange', '1M')->data;
$start = $this->repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
@@ -252,7 +252,7 @@ class ShowController extends Controller
*
* @throws FireflyException
*/
- private function redirectToOriginalAccount(Account $account)
+ protected function redirectToOriginalAccount(Account $account) // user redirection + nav
{
/** @var Transaction $transaction */
$transaction = $account->transactions()->first();
diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php
index 273cc4c18e..59b0ccaf30 100644
--- a/app/Http/Controllers/Auth/RegisterController.php
+++ b/app/Http/Controllers/Auth/RegisterController.php
@@ -126,7 +126,7 @@ class RegisterController extends Controller
*
* @return \FireflyIII\User
*/
- protected function create(array $data): User
+ protected function create(array $data): User // create object
{
return User::create(
[
diff --git a/app/Http/Controllers/Budget/ShowController.php b/app/Http/Controllers/Budget/ShowController.php
index 55f3f5894e..cf385a8771 100644
--- a/app/Http/Controllers/Budget/ShowController.php
+++ b/app/Http/Controllers/Budget/ShowController.php
@@ -211,7 +211,7 @@ class ShowController extends Controller
*
* @return Collection
*/
- private function getLimits(Budget $budget, Carbon $start, Carbon $end): Collection
+ protected function getLimits(Budget $budget, Carbon $start, Carbon $end): Collection // get data + augment with info
{
// properties for cache
$cache = new CacheProperties;
@@ -245,7 +245,7 @@ class ShowController extends Controller
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
- private function getPeriodOverview(): Collection
+ protected function getPeriodOverview(): Collection
{
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
diff --git a/app/Http/Controllers/Category/NoCategoryController.php b/app/Http/Controllers/Category/NoCategoryController.php
index 2eda59c554..24af122196 100644
--- a/app/Http/Controllers/Category/NoCategoryController.php
+++ b/app/Http/Controllers/Category/NoCategoryController.php
@@ -145,7 +145,7 @@ class NoCategoryController extends Controller
* @return Collection
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
- private function getNoCategoryPeriodOverview(Carbon $theDate): Collection
+ protected function getNoCategoryPeriodOverview(Carbon $theDate): Collection // period overview method.
{
Log::debug(sprintf('Now in getNoCategoryPeriodOverview(%s)', $theDate->format('Y-m-d')));
$range = app('preferences')->get('viewRange', '1M')->data;
diff --git a/app/Http/Controllers/Category/ShowController.php b/app/Http/Controllers/Category/ShowController.php
index ed0acbb869..fed7bd8f07 100644
--- a/app/Http/Controllers/Category/ShowController.php
+++ b/app/Http/Controllers/Category/ShowController.php
@@ -165,7 +165,7 @@ class ShowController extends Controller
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
- private function getPeriodOverview(Category $category, Carbon $date): Collection
+ protected function getPeriodOverview(Category $category, Carbon $date): Collection // periodOverview method
{
$range = app('preferences')->get('viewRange', '1M')->data;
$first = $this->journalRepos->firstNull();
diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php
index 5a6bbdcd79..9bce231b13 100644
--- a/app/Http/Controllers/Chart/AccountController.php
+++ b/app/Http/Controllers/Chart/AccountController.php
@@ -457,7 +457,7 @@ class AccountController extends Controller
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
- private function accountBalanceChart(Collection $accounts, Carbon $start, Carbon $end): array
+ protected function accountBalanceChart(Collection $accounts, Carbon $start, Carbon $end): array // chart helper method.
{
// chart properties for cache:
$cache = new CacheProperties();
@@ -515,7 +515,7 @@ class AccountController extends Controller
*
* @return array
*/
- private function getBudgetNames(array $budgetIds): array
+ protected function getBudgetNames(array $budgetIds): array // extract info from array.
{
/** @var BudgetRepositoryInterface $repository */
$repository = app(BudgetRepositoryInterface::class);
@@ -539,7 +539,7 @@ class AccountController extends Controller
*
* @return array
*/
- private function getCategoryNames(array $categoryIds): array
+ protected function getCategoryNames(array $categoryIds): array // extract info from array.
{
/** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class);
diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php
index 644b761bd6..fde4d49516 100644
--- a/app/Http/Controllers/Chart/BudgetController.php
+++ b/app/Http/Controllers/Chart/BudgetController.php
@@ -468,7 +468,7 @@ class BudgetController extends Controller
*
* @return array
*/
- private function getAccountNames(array $accountIds): array
+ protected function getAccountNames(array $accountIds): array // extract info from array.
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
@@ -494,7 +494,7 @@ class BudgetController extends Controller
*
* @return array
*/
- private function getBudgetedInPeriod(Budget $budget, Carbon $start, Carbon $end): array
+ protected function getBudgetedInPeriod(Budget $budget, Carbon $start, Carbon $end): array // get data + augment with info
{
$key = app('navigation')->preferredCarbonFormat($start, $end);
$range = app('navigation')->preferredRangeFormat($start, $end);
@@ -522,7 +522,7 @@ class BudgetController extends Controller
*
* @return array
*/
- private function getCategoryNames(array $categoryIds): array
+ protected function getCategoryNames(array $categoryIds): array // extract info from arrat
{
/** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class);
@@ -552,7 +552,7 @@ class BudgetController extends Controller
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
- private function getExpensesForBudget(Collection $limits, Budget $budget, Carbon $start, Carbon $end): array
+ protected function getExpensesForBudget(Collection $limits, Budget $budget, Carbon $start, Carbon $end): array // get data + augment with info
{
$return = [];
if (0 === $limits->count()) {
@@ -595,7 +595,7 @@ class BudgetController extends Controller
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
*/
- private function spentInPeriodMulti(Budget $budget, Collection $limits): array
+ protected function spentInPeriodMulti(Budget $budget, Collection $limits): array // get data + augment with info
{
$return = [];
$format = (string)trans('config.month_and_day');
@@ -643,7 +643,7 @@ class BudgetController extends Controller
*
* @return string
*/
- private function spentInPeriodWithout(Carbon $start, Carbon $end): string
+ protected function spentInPeriodWithout(Carbon $start, Carbon $end): string // get data + augment with info
{
// collector
/** @var JournalCollectorInterface $collector */
diff --git a/app/Http/Controllers/Chart/BudgetReportController.php b/app/Http/Controllers/Chart/BudgetReportController.php
index 7bfbcaff22..65bab5efe3 100644
--- a/app/Http/Controllers/Chart/BudgetReportController.php
+++ b/app/Http/Controllers/Chart/BudgetReportController.php
@@ -228,7 +228,7 @@ class BudgetReportController extends Controller
*
* @return Collection
*/
- private function filterBudgetLimits(Collection $budgetLimits, Budget $budget, Carbon $start, Carbon $end): Collection
+ protected function filterBudgetLimits(Collection $budgetLimits, Budget $budget, Carbon $start, Carbon $end): Collection // filter data
{
$set = $budgetLimits->filter(
function (BudgetLimit $budgetLimit) use ($budget, $start, $end) {
@@ -257,7 +257,7 @@ class BudgetReportController extends Controller
*
* @return Collection
*/
- private function getExpenses(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end): Collection
+ protected function getExpenses(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end): Collection // get data + augment with info
{
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
@@ -278,7 +278,7 @@ class BudgetReportController extends Controller
*
* @return array
*/
- private function groupByBudget(Collection $set): array
+ protected function groupByBudget(Collection $set): array // filter + group data
{
// group by category ID:
$grouped = [];
diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php
index 458e0fb014..280442c8f2 100644
--- a/app/Http/Controllers/Chart/CategoryController.php
+++ b/app/Http/Controllers/Chart/CategoryController.php
@@ -307,7 +307,7 @@ class CategoryController extends Controller
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
- private function makePeriodChart(Category $category, Carbon $start, Carbon $end): array
+ protected function makePeriodChart(Category $category, Carbon $start, Carbon $end): array // chart helper method.
{
$cache = new CacheProperties;
$cache->addProperty($start);
diff --git a/app/Http/Controllers/Chart/CategoryReportController.php b/app/Http/Controllers/Chart/CategoryReportController.php
index a5b362e320..1bc16f6f70 100644
--- a/app/Http/Controllers/Chart/CategoryReportController.php
+++ b/app/Http/Controllers/Chart/CategoryReportController.php
@@ -302,7 +302,7 @@ class CategoryReportController extends Controller
*
*
*/
- private function getExpenses(Collection $accounts, Collection $categories, Carbon $start, Carbon $end): Collection
+ protected function getExpenses(Collection $accounts, Collection $categories, Carbon $start, Carbon $end): Collection // get data + augument
{
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
@@ -327,7 +327,7 @@ class CategoryReportController extends Controller
*
* @return Collection
*/
- private function getIncome(Collection $accounts, Collection $categories, Carbon $start, Carbon $end): Collection
+ protected function getIncome(Collection $accounts, Collection $categories, Carbon $start, Carbon $end): Collection // get data + augument
{
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
@@ -347,7 +347,7 @@ class CategoryReportController extends Controller
*
* @return array
*/
- private function groupByCategory(Collection $set): array
+ protected function groupByCategory(Collection $set): array // filter + group data
{
// group by category ID:
$grouped = [];
diff --git a/app/Http/Controllers/Chart/ExpenseReportController.php b/app/Http/Controllers/Chart/ExpenseReportController.php
index 31f7d28782..603efa3b54 100644
--- a/app/Http/Controllers/Chart/ExpenseReportController.php
+++ b/app/Http/Controllers/Chart/ExpenseReportController.php
@@ -199,7 +199,7 @@ class ExpenseReportController extends Controller
*
* @return array
*/
- protected function combineAccounts(Collection $accounts): array
+ protected function combineAccounts(Collection $accounts): array // filter + group data
{
$combined = [];
/** @var Account $expenseAccount */
@@ -227,7 +227,7 @@ class ExpenseReportController extends Controller
*
* @return Collection
*/
- private function getExpenses(Collection $accounts, Collection $opposing, Carbon $start, Carbon $end): Collection
+ protected function getExpenses(Collection $accounts, Collection $opposing, Carbon $start, Carbon $end): Collection // get data + augument
{
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
@@ -246,7 +246,7 @@ class ExpenseReportController extends Controller
*
* @return Collection
*/
- private function getIncome(Collection $accounts, Collection $opposing, Carbon $start, Carbon $end): Collection
+ protected function getIncome(Collection $accounts, Collection $opposing, Carbon $start, Carbon $end): Collection // get data + augument
{
/** @var JournalCollectorInterface $collector */
/** @var JournalCollectorInterface $collector */
@@ -263,7 +263,7 @@ class ExpenseReportController extends Controller
*
* @return array
*/
- private function groupByName(Collection $set): array
+ protected function groupByName(Collection $set): array // filter + group data
{
// group by opposing account name.
$grouped = [];
diff --git a/app/Http/Controllers/Chart/ReportController.php b/app/Http/Controllers/Chart/ReportController.php
index bfba313d82..aea82b8330 100644
--- a/app/Http/Controllers/Chart/ReportController.php
+++ b/app/Http/Controllers/Chart/ReportController.php
@@ -222,11 +222,11 @@ class ReportController extends Controller
/**
* Sum up an array.
*
- * @param $array
+ * @param array $array
*
* @return string
*/
- private function arraySum($array): string
+ protected function arraySum(array $array): string // filter + group data
{
$sum = '0';
foreach ($array as $entry) {
@@ -247,7 +247,7 @@ class ReportController extends Controller
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
- private function getChartData(Collection $accounts, Carbon $start, Carbon $end): array
+ protected function getChartData(Collection $accounts, Carbon $start, Carbon $end): array // chart helper function
{
$cache = new CacheProperties;
$cache->addProperty('chart.report.get-chart-data');
diff --git a/app/Http/Controllers/Chart/TagReportController.php b/app/Http/Controllers/Chart/TagReportController.php
index c8401452df..cef0cd5abd 100644
--- a/app/Http/Controllers/Chart/TagReportController.php
+++ b/app/Http/Controllers/Chart/TagReportController.php
@@ -355,7 +355,7 @@ class TagReportController extends Controller
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
- private function getExpenses(Collection $accounts, Collection $tags, Carbon $start, Carbon $end): Collection
+ protected function getExpenses(Collection $accounts, Collection $tags, Carbon $start, Carbon $end): Collection // get data + augument
{
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
@@ -382,7 +382,7 @@ class TagReportController extends Controller
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
- private function getIncome(Collection $accounts, Collection $tags, Carbon $start, Carbon $end): Collection
+ protected function getIncome(Collection $accounts, Collection $tags, Carbon $start, Carbon $end): Collection // get data + augument
{
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
@@ -402,7 +402,7 @@ class TagReportController extends Controller
*
* @return array
*/
- private function groupByTag(Collection $set): array
+ protected function groupByTag(Collection $set): array // filter + group data
{
// group by category ID:
$grouped = [];
diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php
index e3b70c6cc8..c2293cdb1c 100644
--- a/app/Http/Controllers/Controller.php
+++ b/app/Http/Controllers/Controller.php
@@ -27,6 +27,7 @@ use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
+use FireflyIII\Support\Http\Controllers\UserNavigation;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
@@ -42,7 +43,7 @@ use URL;
*/
class Controller extends BaseController
{
- use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
+ use AuthorizesRequests, DispatchesJobs, ValidatesRequests, UserNavigation;
/** @var string Format for date and time. */
protected $dateTimeFormat;
@@ -94,29 +95,7 @@ class Controller extends BaseController
);
}
- /**
- * Functionality:.
- *
- * - If the $identifier contains the word "delete" then a remembered uri with the text "/show/" in it will not be returned but instead the index (/)
- * will be returned.
- * - If the remembered uri contains "javascript/" the remembered uri will not be returned but instead the index (/) will be returned.
- *
- * @param string $identifier
- *
- * @return string
- */
- protected function getPreviousUri(string $identifier): string
- {
- $uri = (string)session($identifier);
- if (!(false === strpos($identifier, 'delete')) && !(false === strpos($uri, '/show/'))) {
- $uri = $this->redirectUri;
- }
- if (!(false === strpos($uri, 'jscript'))) {
- $uri = $this->redirectUri; // @codeCoverageIgnore
- }
- return $uri;
- }
/**
* Is transaction opening balance?
@@ -125,53 +104,20 @@ class Controller extends BaseController
*
* @return bool
*/
- protected function isOpeningBalance(TransactionJournal $journal): bool
+ protected function isOpeningBalance(TransactionJournal $journal): bool // get object info / validate input
{
return TransactionType::OPENING_BALANCE === $journal->transactionType->type;
}
- /**
- * Redirect to asset account that transaction belongs to.
- *
- * @param TransactionJournal $journal
- *
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
- */
- protected function redirectToAccount(TransactionJournal $journal)
- {
- $valid = [AccountType::DEFAULT, AccountType::ASSET];
- $transactions = $journal->transactions;
- /** @var Transaction $transaction */
- foreach ($transactions as $transaction) {
- $account = $transaction->account;
- if (\in_array($account->accountType->type, $valid, true)) {
- return redirect(route('accounts.show', [$account->id]));
- }
- }
- // @codeCoverageIgnoreStart
- session()->flash('error', (string)trans('firefly.cannot_redirect_to_account'));
-
- return redirect(route('index'));
- // @codeCoverageIgnoreEnd
- }
- /**
- * Remember previous URL.
- *
- * @param string $identifier
- */
- protected function rememberPreviousUri(string $identifier): void
- {
- session()->put($identifier, URL::previous());
- }
/**
* Get user's language.
*
* @return string
*/
- private function getLanguage(): string
+ protected function getLanguage(): string // get preference
{
/** @var string $language */
$language = app('preferences')->get('language', config('firefly.default_language', 'en_US'))->data;
@@ -182,7 +128,7 @@ class Controller extends BaseController
/**
* @return string
*/
- private function getPageName(): string
+ protected function getPageName(): string // get request info
{
return str_replace('.', '_', Route::currentRouteName());
}
@@ -192,7 +138,7 @@ class Controller extends BaseController
*
* @return string
*/
- private function getSpecificPageName(): string
+ protected function getSpecificPageName(): string // get request info
{
return null === Route::current()->parameter('what') ? '' : '_' . Route::current()->parameter('what');
}
@@ -202,7 +148,7 @@ class Controller extends BaseController
*
* @return bool
*/
- private function hasSeenDemo(): bool
+ protected function hasSeenDemo(): bool // get request info + get preference
{
$page = $this->getPageName();
$specificPage = $this->getSpecificPageName();
diff --git a/app/Http/Controllers/DebugController.php b/app/Http/Controllers/DebugController.php
index 0735d60db9..bb153411b0 100644
--- a/app/Http/Controllers/DebugController.php
+++ b/app/Http/Controllers/DebugController.php
@@ -248,7 +248,7 @@ class DebugController extends Controller
*
* @return string
*/
- protected function errorReporting(int $value): string
+ protected function errorReporting(int $value): string // get configuration
{
$array = [
-1 => 'ALL errors',
@@ -272,7 +272,7 @@ class DebugController extends Controller
*
* @return array
*/
- private function collectPackages(): array
+ protected function collectPackages(): array // get configuration
{
$packages = [];
$file = \dirname(__DIR__, 3) . '/vendor/composer/installed.json';
diff --git a/app/Http/Controllers/HelpController.php b/app/Http/Controllers/HelpController.php
index 830d63ab31..bfd6742556 100644
--- a/app/Http/Controllers/HelpController.php
+++ b/app/Http/Controllers/HelpController.php
@@ -76,7 +76,7 @@ class HelpController extends Controller
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
- private function getHelpText(string $route, string $language): string
+ protected function getHelpText(string $route, string $language): string // get from internet.
{
// get language and default variables.
$content = '<p>' . trans('firefly.route_has_no_help') . '</p>';
diff --git a/app/Http/Controllers/Import/JobConfigurationController.php b/app/Http/Controllers/Import/JobConfigurationController.php
index caaeee9825..ecb87bd45a 100644
--- a/app/Http/Controllers/Import/JobConfigurationController.php
+++ b/app/Http/Controllers/Import/JobConfigurationController.php
@@ -170,7 +170,7 @@ class JobConfigurationController extends Controller
*
* @throws FireflyException
*/
- private function makeConfigurator(ImportJob $importJob): JobConfigurationInterface
+ protected function makeConfigurator(ImportJob $importJob): JobConfigurationInterface // make object
{
$key = sprintf('import.configuration.%s', $importJob->provider);
$className = (string)config($key);
diff --git a/app/Http/Controllers/Import/JobStatusController.php b/app/Http/Controllers/Import/JobStatusController.php
index 56e7df8005..0c40335e66 100644
--- a/app/Http/Controllers/Import/JobStatusController.php
+++ b/app/Http/Controllers/Import/JobStatusController.php
@@ -231,7 +231,7 @@ class JobStatusController extends Controller
*
* @throws FireflyException
*/
- private function storeTransactions(ImportJob $importJob): void
+ protected function storeTransactions(ImportJob $importJob): void // make object + execute
{
/** @var ImportArrayStorage $storage */
$storage = app(ImportArrayStorage::class);
diff --git a/app/Http/Controllers/JavascriptController.php b/app/Http/Controllers/JavascriptController.php
index a3b962cfc5..7b6c5e8f13 100644
--- a/app/Http/Controllers/JavascriptController.php
+++ b/app/Http/Controllers/JavascriptController.php
@@ -146,7 +146,7 @@ class JavascriptController extends Controller
* @return array
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
- private function getDateRangeConfig(): array
+ protected function getDateRangeConfig(): array // get configuration + get preferences.
{
$viewRange = app('preferences')->get('viewRange', '1M')->data;
/** @var Carbon $start */
diff --git a/app/Http/Controllers/Json/BoxController.php b/app/Http/Controllers/Json/BoxController.php
index 94903a7010..b9cb4c092c 100644
--- a/app/Http/Controllers/Json/BoxController.php
+++ b/app/Http/Controllers/Json/BoxController.php
@@ -302,7 +302,7 @@ class BoxController extends Controller
*
* @return TransactionCurrency
*/
- private function getCurrencyOrDefault(Account $account): TransactionCurrency
+ protected function getCurrencyOrDefault(Account $account): TransactionCurrency // get a preference
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
@@ -330,7 +330,7 @@ class BoxController extends Controller
* @return bool
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
- private function notInSessionRange(Carbon $date): bool
+ protected function notInSessionRange(Carbon $date): bool // Validate a preference
{
/** @var Carbon $start */
$start = session('start', Carbon::now()->startOfMonth());
diff --git a/app/Http/Controllers/Json/IntroController.php b/app/Http/Controllers/Json/IntroController.php
index f146e06091..b52e7a1ea7 100644
--- a/app/Http/Controllers/Json/IntroController.php
+++ b/app/Http/Controllers/Json/IntroController.php
@@ -142,7 +142,7 @@ class IntroController
*
* @return array
*/
- private function getBasicSteps(string $route): array
+ protected function getBasicSteps(string $route): array // get config values
{
$routeKey = str_replace('.', '_', $route);
$elements = config(sprintf('intro.%s', $routeKey));
@@ -172,7 +172,7 @@ class IntroController
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
- private function getSpecificSteps(string $route, string $specificPage): array
+ protected function getSpecificSteps(string $route, string $specificPage): array // get config values
{
$steps = [];
$routeKey = '';
diff --git a/app/Http/Controllers/Json/ReconcileController.php b/app/Http/Controllers/Json/ReconcileController.php
index 695fe52b67..9ba91a78f9 100644
--- a/app/Http/Controllers/Json/ReconcileController.php
+++ b/app/Http/Controllers/Json/ReconcileController.php
@@ -210,7 +210,7 @@ class ReconcileController extends Controller
*
* @throws FireflyException
*/
- private function redirectToOriginalAccount(Account $account)
+ protected function redirectToOriginalAccount(Account $account) // user redirection + nav
{
/** @var Transaction $transaction */
$transaction = $account->transactions()->first();
diff --git a/app/Http/Controllers/NewUserController.php b/app/Http/Controllers/NewUserController.php
index 0b67b0b609..db3c17a000 100644
--- a/app/Http/Controllers/NewUserController.php
+++ b/app/Http/Controllers/NewUserController.php
@@ -128,7 +128,7 @@ class NewUserController extends Controller
*
* @return bool
*/
- private function createAssetAccount(NewUserFormRequest $request, TransactionCurrency $currency): bool
+ protected function createAssetAccount(NewUserFormRequest $request, TransactionCurrency $currency): bool // create stuff
{
$assetAccount = [
'name' => $request->get('bank_name'),
@@ -156,7 +156,7 @@ class NewUserController extends Controller
*
* @return bool
*/
- private function createCashWalletAccount(TransactionCurrency $currency, string $language): bool
+ protected function createCashWalletAccount(TransactionCurrency $currency, string $language): bool // create stuff
{
$assetAccount = [
'name' => (string)trans('firefly.cash_wallet', [], $language),
@@ -185,7 +185,7 @@ class NewUserController extends Controller
*
* @return bool
*/
- private function createSavingsAccount(NewUserFormRequest $request, TransactionCurrency $currency, string $language): bool
+ protected function createSavingsAccount(NewUserFormRequest $request, TransactionCurrency $currency, string $language): bool // create stuff
{
$savingsAccount = [
'name' => (string)trans('firefly.new_savings_account', ['bank_name' => $request->get('bank_name')], $language),
diff --git a/app/Http/Controllers/Popup/ReportController.php b/app/Http/Controllers/Popup/ReportController.php
index d6c5fef0c0..452733f4c9 100644
--- a/app/Http/Controllers/Popup/ReportController.php
+++ b/app/Http/Controllers/Popup/ReportController.php
@@ -127,7 +127,7 @@ class ReportController extends Controller
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
- private function balanceAmount(array $attributes): string
+ protected function balanceAmount(array $attributes): string // generate view for report.
{
$role = (int)$attributes['role'];
$budget = $this->budgetRepository->findNull((int)$attributes['budgetId']);
@@ -165,7 +165,7 @@ class ReportController extends Controller
*
* @return string
*/
- private function budgetSpentAmount(array $attributes): string
+ protected function budgetSpentAmount(array $attributes): string // generate view for report.
{
$budget = $this->budgetRepository->findNull((int)$attributes['budgetId']);
if (null === $budget) {
@@ -189,7 +189,7 @@ class ReportController extends Controller
*
* @return string
*/
- private function categoryEntry(array $attributes): string
+ protected function categoryEntry(array $attributes): string // generate view for report.
{
$category = $this->categoryRepository->findNull((int)$attributes['categoryId']);
@@ -215,7 +215,7 @@ class ReportController extends Controller
*
* @return string
*/
- private function expenseEntry(array $attributes): string
+ protected function expenseEntry(array $attributes): string // generate view for report.
{
$account = $this->accountRepository->findNull((int)$attributes['accountId']);
@@ -241,7 +241,7 @@ class ReportController extends Controller
*
* @return string
*/
- private function incomeEntry(array $attributes): string
+ protected function incomeEntry(array $attributes): string // generate view for report.
{
$account = $this->accountRepository->findNull((int)$attributes['accountId']);
@@ -267,7 +267,7 @@ class ReportController extends Controller
*
* @return array
*/
- private function parseAttributes(array $attributes): array
+ protected function parseAttributes(array $attributes): array // parse input + return result
{
$attributes['location'] = $attributes['location'] ?? '';
$attributes['accounts'] = AccountList::routeBinder($attributes['accounts'] ?? '', new Route('get', '', []));
diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php
index 2edae12e66..2219b128ce 100644
--- a/app/Http/Controllers/ProfileController.php
+++ b/app/Http/Controllers/ProfileController.php
@@ -450,7 +450,7 @@ class ProfileController extends Controller
*
* @throws ValidationException
*/
- protected function validatePassword(User $user, string $current, string $new): bool
+ protected function validatePassword(User $user, string $current, string $new): bool //get request info
{
if (!Hash::check($current, $user->password)) {
throw new ValidationException((string)trans('firefly.invalid_current_password'));
@@ -466,7 +466,7 @@ class ProfileController extends Controller
/**
* Create new RSA keys.
*/
- private function createOAuthKeys(): void
+ protected function createOAuthKeys(): void // create stuff
{
$rsa = new RSA();
$keys = $rsa->createKey(4096);
@@ -492,7 +492,7 @@ class ProfileController extends Controller
*
* @return string
*/
- private function getDomain(): string
+ protected function getDomain(): string // get request info
{
$url = url()->to('/');
$parts = parse_url($url);
diff --git a/app/Http/Controllers/Report/BudgetController.php b/app/Http/Controllers/Report/BudgetController.php
index 992511b3e5..2209ab707c 100644
--- a/app/Http/Controllers/Report/BudgetController.php
+++ b/app/Http/Controllers/Report/BudgetController.php
@@ -117,7 +117,7 @@ class BudgetController extends Controller
*
* @return array
*/
- private function filterBudgetPeriodReport(array $data): array
+ protected function filterBudgetPeriodReport(array $data): array // helper function for period overview.
{
/**
* @var int
diff --git a/app/Http/Controllers/Report/CategoryController.php b/app/Http/Controllers/Report/CategoryController.php
index 34693bf846..6337f92fde 100644
--- a/app/Http/Controllers/Report/CategoryController.php
+++ b/app/Http/Controllers/Report/CategoryController.php
@@ -173,7 +173,7 @@ class CategoryController extends Controller
*
* @return array
*/
- private function filterReport(array $data): array
+ protected function filterReport(array $data): array // filter data from report.
{
foreach ($data as $categoryId => $set) {
$sum = '0';
diff --git a/app/Http/Controllers/Report/ExpenseController.php b/app/Http/Controllers/Report/ExpenseController.php
index 7749607f7f..f09959b3f5 100644
--- a/app/Http/Controllers/Report/ExpenseController.php
+++ b/app/Http/Controllers/Report/ExpenseController.php
@@ -335,7 +335,7 @@ class ExpenseController extends Controller
*
* @return array
*/
- protected function combineAccounts(Collection $accounts): array
+ protected function combineAccounts(Collection $accounts): array // filter + group data
{
$combined = [];
/** @var Account $expenseAccount */
@@ -367,7 +367,7 @@ class ExpenseController extends Controller
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
- protected function earnedByCategory(Collection $assets, Collection $opposing, Carbon $start, Carbon $end): array
+ protected function earnedByCategory(Collection $assets, Collection $opposing, Carbon $start, Carbon $end): array // get data + augment with info
{
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
@@ -431,7 +431,7 @@ class ExpenseController extends Controller
*
* @return array
*/
- protected function earnedInPeriod(Collection $assets, Collection $opposing, Carbon $start, Carbon $end): array
+ protected function earnedInPeriod(Collection $assets, Collection $opposing, Carbon $start, Carbon $end): array // get data + augment with info
{
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
@@ -478,7 +478,7 @@ class ExpenseController extends Controller
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
- protected function spentByBudget(Collection $assets, Collection $opposing, Carbon $start, Carbon $end): array
+ protected function spentByBudget(Collection $assets, Collection $opposing, Carbon $start, Carbon $end): array // get data + augment with info
{
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
@@ -545,7 +545,7 @@ class ExpenseController extends Controller
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
- protected function spentByCategory(Collection $assets, Collection $opposing, Carbon $start, Carbon $end): array
+ protected function spentByCategory(Collection $assets, Collection $opposing, Carbon $start, Carbon $end): array // get data + augment with info
{
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
@@ -609,7 +609,7 @@ class ExpenseController extends Controller
*
* @return array
*/
- protected function spentInPeriod(Collection $assets, Collection $opposing, Carbon $start, Carbon $end): array
+ protected function spentInPeriod(Collection $assets, Collection $opposing, Carbon $start, Carbon $end): array // get data + augment with info
{
/** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class);
diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php
index df5d3baa9c..22b205bb66 100644
--- a/app/Http/Controllers/ReportController.php
+++ b/app/Http/Controllers/ReportController.php
@@ -423,7 +423,7 @@ class ReportController extends Controller
*
* @return string
*/
- private function accountReportOptions(): string
+ protected function accountReportOptions(): string // render a view
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
@@ -451,7 +451,7 @@ class ReportController extends Controller
*
* @return string
*/
- private function budgetReportOptions(): string
+ protected function budgetReportOptions(): string // render a view
{
/** @var BudgetRepositoryInterface $repository */
$repository = app(BudgetRepositoryInterface::class);
@@ -471,7 +471,7 @@ class ReportController extends Controller
*
* @return string
*/
- private function categoryReportOptions(): string
+ protected function categoryReportOptions(): string // render a view
{
/** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class);
@@ -491,7 +491,7 @@ class ReportController extends Controller
*
* @return string
*/
- private function noReportOptions(): string
+ protected function noReportOptions(): string // render a view
{
try {
$result = view('reports.options.no-options')->render();
@@ -508,7 +508,7 @@ class ReportController extends Controller
*
* @return string
*/
- private function tagReportOptions(): string
+ protected function tagReportOptions(): string // render a view
{
/** @var TagRepositoryInterface $repository */
$repository = app(TagRepositoryInterface::class);
diff --git a/app/Http/Controllers/Rule/CreateController.php b/app/Http/Controllers/Rule/CreateController.php
index 4bb1aeb807..2cc5c1eb06 100644
--- a/app/Http/Controllers/Rule/CreateController.php
+++ b/app/Http/Controllers/Rule/CreateController.php
@@ -206,7 +206,7 @@ class CreateController extends Controller
*
* @return array
*/
- private function getActionsForBill(Bill $bill): array
+ protected function getActionsForBill(Bill $bill): array // get info and augument
{
try {
$result = view(
@@ -237,7 +237,7 @@ class CreateController extends Controller
*
* @return array
*/
- private function getTriggersForBill(Bill $bill): array
+ protected function getTriggersForBill(Bill $bill): array // get info and augument
{
$result = [];
$triggers = ['currency_is', 'amount_more', 'amount_less', 'description_contains'];
diff --git a/app/Http/Controllers/Rule/EditController.php b/app/Http/Controllers/Rule/EditController.php
index edd265844a..c4c4623e68 100644
--- a/app/Http/Controllers/Rule/EditController.php
+++ b/app/Http/Controllers/Rule/EditController.php
@@ -154,7 +154,7 @@ class EditController extends Controller
*
* @return array
*/
- private function getCurrentActions(Rule $rule): array
+ protected function getCurrentActions(Rule $rule): array // get info from object and present.
{
$index = 0;
$actions = [];
@@ -192,7 +192,7 @@ class EditController extends Controller
* @return array
*
*/
- private function getCurrentTriggers(Rule $rule): array
+ protected function getCurrentTriggers(Rule $rule): array // get info from object and present.
{
$index = 0;
$triggers = [];
diff --git a/app/Http/Controllers/Rule/SelectController.php b/app/Http/Controllers/Rule/SelectController.php
index fbc3afc763..56af135847 100644
--- a/app/Http/Controllers/Rule/SelectController.php
+++ b/app/Http/Controllers/Rule/SelectController.php
@@ -263,7 +263,7 @@ class SelectController extends Controller
*
* @return array
*/
- private function getValidTriggerList(TestRuleFormRequest $request): array
+ protected function getValidTriggerList(TestRuleFormRequest $request): array // process input
{
$triggers = [];
$data = $request->get('rule_triggers');
diff --git a/app/Http/Controllers/System/InstallController.php b/app/Http/Controllers/System/InstallController.php
index d19adf6500..9ea63c37d9 100644
--- a/app/Http/Controllers/System/InstallController.php
+++ b/app/Http/Controllers/System/InstallController.php
@@ -183,7 +183,7 @@ class InstallController extends Controller
*
* @return bool
*/
- private function hasForbiddenFunctions(): bool
+ protected function hasForbiddenFunctions(): bool // validate system config
{
$list = ['proc_close'];
$forbidden = explode(',', ini_get('disable_functions'));
diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php
index 604c192ad4..14cc0d01d2 100644
--- a/app/Http/Controllers/TagController.php
+++ b/app/Http/Controllers/TagController.php
@@ -304,7 +304,7 @@ class TagController extends Controller
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
- private function getPeriodOverview(Tag $tag): Collection
+ protected function getPeriodOverview(Tag $tag): Collection // period overview for tags.
{
// get first and last tag date from tag:
$range = app('preferences')->get('viewRange', '1M')->data;
diff --git a/app/Http/Controllers/Transaction/ConvertController.php b/app/Http/Controllers/Transaction/ConvertController.php
index 897af76c00..77dd1eaed4 100644
--- a/app/Http/Controllers/Transaction/ConvertController.php
+++ b/app/Http/Controllers/Transaction/ConvertController.php
@@ -181,7 +181,7 @@ class ConvertController extends Controller
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
- private function getDestinationAccount(TransactionJournal $journal, TransactionType $destinationType, array $data): Account
+ protected function getDestinationAccount(TransactionJournal $journal, TransactionType $destinationType, array $data): Account // helper for conversion. Get info from obj.
{
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
@@ -242,7 +242,7 @@ class ConvertController extends Controller
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
- private function getSourceAccount(TransactionJournal $journal, TransactionType $destinationType, array $data): Account
+ protected function getSourceAccount(TransactionJournal $journal, TransactionType $destinationType, array $data): Account // helper for conversion. Get info from obj.
{
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
diff --git a/app/Http/Controllers/Transaction/SingleController.php b/app/Http/Controllers/Transaction/SingleController.php
index 67ca017160..3d18293080 100644
--- a/app/Http/Controllers/Transaction/SingleController.php
+++ b/app/Http/Controllers/Transaction/SingleController.php
@@ -450,7 +450,7 @@ class SingleController extends Controller
*
* @return bool
*/
- private function isSplitJournal(TransactionJournal $journal): bool
+ protected function isSplitJournal(TransactionJournal $journal): bool // validate objects
{
$count = $this->repository->countTransactions($journal);
diff --git a/app/Http/Controllers/Transaction/SplitController.php b/app/Http/Controllers/Transaction/SplitController.php
index d407c4b4c5..8ef7b6b68b 100644
--- a/app/Http/Controllers/Transaction/SplitController.php
+++ b/app/Http/Controllers/Transaction/SplitController.php
@@ -182,7 +182,7 @@ class SplitController extends Controller
* @return array
* @throws FireflyException
*/
- private function arrayFromJournal(Request $request, TransactionJournal $journal): array
+ protected function arrayFromJournal(Request $request, TransactionJournal $journal): array // convert user input.
{
$sourceAccounts = $this->repository->getJournalSourceAccounts($journal);
$destinationAccounts = $this->repository->getJournalDestinationAccounts($journal);
@@ -232,7 +232,7 @@ class SplitController extends Controller
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
- private function getTransactionDataFromJournal(TransactionJournal $journal): array
+ protected function getTransactionDataFromJournal(TransactionJournal $journal): array // convert object
{
// use collector to collect transactions.
$collector = app(JournalCollectorInterface::class);
@@ -274,7 +274,7 @@ class SplitController extends Controller
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
- private function updateWithPrevious($array, $old): array
+ protected function updateWithPrevious($array, $old): array // update object with new info
{
if (0 === \count($old) || !isset($old['transactions'])) {
return $array;
diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php
index 6bc490a5de..92150f68ae 100644
--- a/app/Http/Controllers/TransactionController.php
+++ b/app/Http/Controllers/TransactionController.php
@@ -258,7 +258,7 @@ class TransactionController extends Controller
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
- private function getPeriodOverview(string $what, Carbon $date): Collection
+ protected function getPeriodOverview(string $what, Carbon $date): Collection // period overview for transactions.
{
$range = app('preferences')->get('viewRange', '1M')->data;
$first = $this->repository->firstNull();
@@ -309,7 +309,7 @@ class TransactionController extends Controller
*
* @return array
*/
- private function sumPerCurrency(Collection $collection): array
+ protected function sumPerCurrency(Collection $collection): array // helper for transactions (math, calculations)
{
$return = [];
/** @var Transaction $transaction */
diff --git a/app/Support/Http/Controllers/UserNavigation.php b/app/Support/Http/Controllers/UserNavigation.php
new file mode 100644
index 0000000000..0425cd1db7
--- /dev/null
+++ b/app/Support/Http/Controllers/UserNavigation.php
@@ -0,0 +1,96 @@
+<?php
+/**
+ * UserNavigation.php
+ * Copyright (c) 2018 [email protected]
+ *
+ * This file is part of Firefly III.
+ *
+ * Firefly III is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Firefly III is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+declare(strict_types=1);
+
+namespace FireflyIII\Support\Http\Controllers;
+
+use FireflyIII\Models\AccountType;
+use FireflyIII\Models\Transaction;
+use FireflyIII\Models\TransactionJournal;
+use URL;
+
+/**
+ * Trait UserNavigation
+ *
+ * @package FireflyIII\Support\Http\Controllers
+ */
+trait UserNavigation
+{
+ /**
+ * Functionality:.
+ *
+ * - If the $identifier contains the word "delete" then a remembered uri with the text "/show/" in it will not be returned but instead the index (/)
+ * will be returned.
+ * - If the remembered uri contains "javascript/" the remembered uri will not be returned but instead the index (/) will be returned.
+ *
+ * @param string $identifier
+ *
+ * @return string
+ */
+ protected function getPreviousUri(string $identifier): string
+ {
+ $uri = (string)session($identifier);
+ if (!(false === strpos($identifier, 'delete')) && !(false === strpos($uri, '/show/'))) {
+ $uri = $this->redirectUri;
+ }
+ if (!(false === strpos($uri, 'jscript'))) {
+ $uri = $this->redirectUri; // @codeCoverageIgnore
+ }
+
+ return $uri;
+ }
+
+ /**
+ * Redirect to asset account that transaction belongs to.
+ *
+ * @param TransactionJournal $journal
+ *
+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ */
+ protected function redirectToAccount(TransactionJournal $journal)
+ {
+ $valid = [AccountType::DEFAULT, AccountType::ASSET];
+ $transactions = $journal->transactions;
+ /** @var Transaction $transaction */
+ foreach ($transactions as $transaction) {
+ $account = $transaction->account;
+ if (\in_array($account->accountType->type, $valid, true)) {
+ return redirect(route('accounts.show', [$account->id]));
+ }
+ }
+ // @codeCoverageIgnoreStart
+ session()->flash('error', (string)trans('firefly.cannot_redirect_to_account'));
+
+ return redirect(route('index'));
+ // @codeCoverageIgnoreEnd
+ }
+
+ /**
+ * Remember previous URL.
+ *
+ * @param string $identifier
+ */
+ protected function rememberPreviousUri(string $identifier): void
+ {
+ session()->put($identifier, URL::previous());
+ }
+}
\ No newline at end of file