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

This commit is contained in:
James Cole
2018-08-09 16:07:33 +02:00
parent 32e58d0a60
commit 7943164375
41 changed files with 189 additions and 147 deletions

View File

@@ -127,7 +127,7 @@ class IndexController extends Controller
* *
* @return null|mixed * @return null|mixed
*/ */
protected function isInArray(array $array, int $entryId) protected function isInArray(array $array, int $entryId) // helper for data (math, calculations)
{ {
$result = '0'; $result = '0';
if (isset($array[$entryId])) { if (isset($array[$entryId])) {

View File

@@ -380,7 +380,7 @@ class ReconcileController extends Controller
* *
* @throws FireflyException * @throws FireflyException
*/ */
private function redirectToOriginalAccount(Account $account) protected function redirectToOriginalAccount(Account $account) // user redirection + nav
{ {
/** @var Transaction $transaction */ /** @var Transaction $transaction */
$transaction = $account->transactions()->first(); $transaction = $account->transactions()->first();

View File

@@ -187,7 +187,7 @@ class ShowController extends Controller
* *
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @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; $range = app('preferences')->get('viewRange', '1M')->data;
$start = $this->repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth(); $start = $this->repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
@@ -252,7 +252,7 @@ class ShowController extends Controller
* *
* @throws FireflyException * @throws FireflyException
*/ */
private function redirectToOriginalAccount(Account $account) protected function redirectToOriginalAccount(Account $account) // user redirection + nav
{ {
/** @var Transaction $transaction */ /** @var Transaction $transaction */
$transaction = $account->transactions()->first(); $transaction = $account->transactions()->first();

View File

@@ -126,7 +126,7 @@ class RegisterController extends Controller
* *
* @return \FireflyIII\User * @return \FireflyIII\User
*/ */
protected function create(array $data): User protected function create(array $data): User // create object
{ {
return User::create( return User::create(
[ [

View File

@@ -211,7 +211,7 @@ class ShowController extends Controller
* *
* @return Collection * @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 // properties for cache
$cache = new CacheProperties; $cache = new CacheProperties;
@@ -245,7 +245,7 @@ class ShowController extends Controller
* *
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/ */
private function getPeriodOverview(): Collection protected function getPeriodOverview(): Collection
{ {
/** @var JournalRepositoryInterface $repository */ /** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class); $repository = app(JournalRepositoryInterface::class);

View File

@@ -145,7 +145,7 @@ class NoCategoryController extends Controller
* @return Collection * @return Collection
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @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'))); Log::debug(sprintf('Now in getNoCategoryPeriodOverview(%s)', $theDate->format('Y-m-d')));
$range = app('preferences')->get('viewRange', '1M')->data; $range = app('preferences')->get('viewRange', '1M')->data;

View File

@@ -165,7 +165,7 @@ class ShowController extends Controller
* *
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @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; $range = app('preferences')->get('viewRange', '1M')->data;
$first = $this->journalRepos->firstNull(); $first = $this->journalRepos->firstNull();

View File

@@ -457,7 +457,7 @@ class AccountController extends Controller
* @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @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: // chart properties for cache:
$cache = new CacheProperties(); $cache = new CacheProperties();
@@ -515,7 +515,7 @@ class AccountController extends Controller
* *
* @return array * @return array
*/ */
private function getBudgetNames(array $budgetIds): array protected function getBudgetNames(array $budgetIds): array // extract info from array.
{ {
/** @var BudgetRepositoryInterface $repository */ /** @var BudgetRepositoryInterface $repository */
$repository = app(BudgetRepositoryInterface::class); $repository = app(BudgetRepositoryInterface::class);
@@ -539,7 +539,7 @@ class AccountController extends Controller
* *
* @return array * @return array
*/ */
private function getCategoryNames(array $categoryIds): array protected function getCategoryNames(array $categoryIds): array // extract info from array.
{ {
/** @var CategoryRepositoryInterface $repository */ /** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class); $repository = app(CategoryRepositoryInterface::class);

View File

@@ -468,7 +468,7 @@ class BudgetController extends Controller
* *
* @return array * @return array
*/ */
private function getAccountNames(array $accountIds): array protected function getAccountNames(array $accountIds): array // extract info from array.
{ {
/** @var AccountRepositoryInterface $repository */ /** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class); $repository = app(AccountRepositoryInterface::class);
@@ -494,7 +494,7 @@ class BudgetController extends Controller
* *
* @return array * @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); $key = app('navigation')->preferredCarbonFormat($start, $end);
$range = app('navigation')->preferredRangeFormat($start, $end); $range = app('navigation')->preferredRangeFormat($start, $end);
@@ -522,7 +522,7 @@ class BudgetController extends Controller
* *
* @return array * @return array
*/ */
private function getCategoryNames(array $categoryIds): array protected function getCategoryNames(array $categoryIds): array // extract info from arrat
{ {
/** @var CategoryRepositoryInterface $repository */ /** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class); $repository = app(CategoryRepositoryInterface::class);
@@ -552,7 +552,7 @@ class BudgetController extends Controller
* *
* @SuppressWarnings(PHPMD.CyclomaticComplexity) * @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 = []; $return = [];
if (0 === $limits->count()) { if (0 === $limits->count()) {
@@ -595,7 +595,7 @@ class BudgetController extends Controller
* @SuppressWarnings(PHPMD.CyclomaticComplexity) * @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 = []; $return = [];
$format = (string)trans('config.month_and_day'); $format = (string)trans('config.month_and_day');
@@ -643,7 +643,7 @@ class BudgetController extends Controller
* *
* @return string * @return string
*/ */
private function spentInPeriodWithout(Carbon $start, Carbon $end): string protected function spentInPeriodWithout(Carbon $start, Carbon $end): string // get data + augment with info
{ {
// collector // collector
/** @var JournalCollectorInterface $collector */ /** @var JournalCollectorInterface $collector */

View File

@@ -228,7 +228,7 @@ class BudgetReportController extends Controller
* *
* @return Collection * @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( $set = $budgetLimits->filter(
function (BudgetLimit $budgetLimit) use ($budget, $start, $end) { function (BudgetLimit $budgetLimit) use ($budget, $start, $end) {
@@ -257,7 +257,7 @@ class BudgetReportController extends Controller
* *
* @return Collection * @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 */ /** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -278,7 +278,7 @@ class BudgetReportController extends Controller
* *
* @return array * @return array
*/ */
private function groupByBudget(Collection $set): array protected function groupByBudget(Collection $set): array // filter + group data
{ {
// group by category ID: // group by category ID:
$grouped = []; $grouped = [];

View File

@@ -307,7 +307,7 @@ class CategoryController extends Controller
* *
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @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 = new CacheProperties;
$cache->addProperty($start); $cache->addProperty($start);

View File

@@ -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 */ /** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -327,7 +327,7 @@ class CategoryReportController extends Controller
* *
* @return Collection * @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 */ /** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -347,7 +347,7 @@ class CategoryReportController extends Controller
* *
* @return array * @return array
*/ */
private function groupByCategory(Collection $set): array protected function groupByCategory(Collection $set): array // filter + group data
{ {
// group by category ID: // group by category ID:
$grouped = []; $grouped = [];

View File

@@ -199,7 +199,7 @@ class ExpenseReportController extends Controller
* *
* @return array * @return array
*/ */
protected function combineAccounts(Collection $accounts): array protected function combineAccounts(Collection $accounts): array // filter + group data
{ {
$combined = []; $combined = [];
/** @var Account $expenseAccount */ /** @var Account $expenseAccount */
@@ -227,7 +227,7 @@ class ExpenseReportController extends Controller
* *
* @return Collection * @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 */ /** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -246,7 +246,7 @@ class ExpenseReportController extends Controller
* *
* @return Collection * @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 */
/** @var JournalCollectorInterface $collector */ /** @var JournalCollectorInterface $collector */
@@ -263,7 +263,7 @@ class ExpenseReportController extends Controller
* *
* @return array * @return array
*/ */
private function groupByName(Collection $set): array protected function groupByName(Collection $set): array // filter + group data
{ {
// group by opposing account name. // group by opposing account name.
$grouped = []; $grouped = [];

View File

@@ -222,11 +222,11 @@ class ReportController extends Controller
/** /**
* Sum up an array. * Sum up an array.
* *
* @param $array * @param array $array
* *
* @return string * @return string
*/ */
private function arraySum($array): string protected function arraySum(array $array): string // filter + group data
{ {
$sum = '0'; $sum = '0';
foreach ($array as $entry) { foreach ($array as $entry) {
@@ -247,7 +247,7 @@ class ReportController extends Controller
* *
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @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 = new CacheProperties;
$cache->addProperty('chart.report.get-chart-data'); $cache->addProperty('chart.report.get-chart-data');

View File

@@ -355,7 +355,7 @@ class TagReportController extends Controller
* *
* @SuppressWarnings(PHPMD.ExcessiveParameterList) * @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 */ /** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -382,7 +382,7 @@ class TagReportController extends Controller
* *
* @SuppressWarnings(PHPMD.ExcessiveParameterList) * @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 */ /** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -402,7 +402,7 @@ class TagReportController extends Controller
* *
* @return array * @return array
*/ */
private function groupByTag(Collection $set): array protected function groupByTag(Collection $set): array // filter + group data
{ {
// group by category ID: // group by category ID:
$grouped = []; $grouped = [];

View File

@@ -27,6 +27,7 @@ use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Support\Http\Controllers\UserNavigation;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs; use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Foundation\Validation\ValidatesRequests;
@@ -42,7 +43,7 @@ use URL;
*/ */
class Controller extends BaseController class Controller extends BaseController
{ {
use AuthorizesRequests, DispatchesJobs, ValidatesRequests; use AuthorizesRequests, DispatchesJobs, ValidatesRequests, UserNavigation;
/** @var string Format for date and time. */ /** @var string Format for date and time. */
protected $dateTimeFormat; 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? * Is transaction opening balance?
@@ -125,53 +104,20 @@ class Controller extends BaseController
* *
* @return bool * @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; 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. * Get user's language.
* *
* @return string * @return string
*/ */
private function getLanguage(): string protected function getLanguage(): string // get preference
{ {
/** @var string $language */ /** @var string $language */
$language = app('preferences')->get('language', config('firefly.default_language', 'en_US'))->data; $language = app('preferences')->get('language', config('firefly.default_language', 'en_US'))->data;
@@ -182,7 +128,7 @@ class Controller extends BaseController
/** /**
* @return string * @return string
*/ */
private function getPageName(): string protected function getPageName(): string // get request info
{ {
return str_replace('.', '_', Route::currentRouteName()); return str_replace('.', '_', Route::currentRouteName());
} }
@@ -192,7 +138,7 @@ class Controller extends BaseController
* *
* @return string * @return string
*/ */
private function getSpecificPageName(): string protected function getSpecificPageName(): string // get request info
{ {
return null === Route::current()->parameter('what') ? '' : '_' . Route::current()->parameter('what'); return null === Route::current()->parameter('what') ? '' : '_' . Route::current()->parameter('what');
} }
@@ -202,7 +148,7 @@ class Controller extends BaseController
* *
* @return bool * @return bool
*/ */
private function hasSeenDemo(): bool protected function hasSeenDemo(): bool // get request info + get preference
{ {
$page = $this->getPageName(); $page = $this->getPageName();
$specificPage = $this->getSpecificPageName(); $specificPage = $this->getSpecificPageName();

View File

@@ -248,7 +248,7 @@ class DebugController extends Controller
* *
* @return string * @return string
*/ */
protected function errorReporting(int $value): string protected function errorReporting(int $value): string // get configuration
{ {
$array = [ $array = [
-1 => 'ALL errors', -1 => 'ALL errors',
@@ -272,7 +272,7 @@ class DebugController extends Controller
* *
* @return array * @return array
*/ */
private function collectPackages(): array protected function collectPackages(): array // get configuration
{ {
$packages = []; $packages = [];
$file = \dirname(__DIR__, 3) . '/vendor/composer/installed.json'; $file = \dirname(__DIR__, 3) . '/vendor/composer/installed.json';

View File

@@ -76,7 +76,7 @@ class HelpController extends Controller
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity) * @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. // get language and default variables.
$content = '<p>' . trans('firefly.route_has_no_help') . '</p>'; $content = '<p>' . trans('firefly.route_has_no_help') . '</p>';

View File

@@ -170,7 +170,7 @@ class JobConfigurationController extends Controller
* *
* @throws FireflyException * @throws FireflyException
*/ */
private function makeConfigurator(ImportJob $importJob): JobConfigurationInterface protected function makeConfigurator(ImportJob $importJob): JobConfigurationInterface // make object
{ {
$key = sprintf('import.configuration.%s', $importJob->provider); $key = sprintf('import.configuration.%s', $importJob->provider);
$className = (string)config($key); $className = (string)config($key);

View File

@@ -231,7 +231,7 @@ class JobStatusController extends Controller
* *
* @throws FireflyException * @throws FireflyException
*/ */
private function storeTransactions(ImportJob $importJob): void protected function storeTransactions(ImportJob $importJob): void // make object + execute
{ {
/** @var ImportArrayStorage $storage */ /** @var ImportArrayStorage $storage */
$storage = app(ImportArrayStorage::class); $storage = app(ImportArrayStorage::class);

View File

@@ -146,7 +146,7 @@ class JavascriptController extends Controller
* @return array * @return array
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/ */
private function getDateRangeConfig(): array protected function getDateRangeConfig(): array // get configuration + get preferences.
{ {
$viewRange = app('preferences')->get('viewRange', '1M')->data; $viewRange = app('preferences')->get('viewRange', '1M')->data;
/** @var Carbon $start */ /** @var Carbon $start */

View File

@@ -302,7 +302,7 @@ class BoxController extends Controller
* *
* @return TransactionCurrency * @return TransactionCurrency
*/ */
private function getCurrencyOrDefault(Account $account): TransactionCurrency protected function getCurrencyOrDefault(Account $account): TransactionCurrency // get a preference
{ {
/** @var AccountRepositoryInterface $repository */ /** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class); $repository = app(AccountRepositoryInterface::class);
@@ -330,7 +330,7 @@ class BoxController extends Controller
* @return bool * @return bool
* @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/ */
private function notInSessionRange(Carbon $date): bool protected function notInSessionRange(Carbon $date): bool // Validate a preference
{ {
/** @var Carbon $start */ /** @var Carbon $start */
$start = session('start', Carbon::now()->startOfMonth()); $start = session('start', Carbon::now()->startOfMonth());

View File

@@ -142,7 +142,7 @@ class IntroController
* *
* @return array * @return array
*/ */
private function getBasicSteps(string $route): array protected function getBasicSteps(string $route): array // get config values
{ {
$routeKey = str_replace('.', '_', $route); $routeKey = str_replace('.', '_', $route);
$elements = config(sprintf('intro.%s', $routeKey)); $elements = config(sprintf('intro.%s', $routeKey));
@@ -172,7 +172,7 @@ class IntroController
* @return array * @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/ */
private function getSpecificSteps(string $route, string $specificPage): array protected function getSpecificSteps(string $route, string $specificPage): array // get config values
{ {
$steps = []; $steps = [];
$routeKey = ''; $routeKey = '';

View File

@@ -210,7 +210,7 @@ class ReconcileController extends Controller
* *
* @throws FireflyException * @throws FireflyException
*/ */
private function redirectToOriginalAccount(Account $account) protected function redirectToOriginalAccount(Account $account) // user redirection + nav
{ {
/** @var Transaction $transaction */ /** @var Transaction $transaction */
$transaction = $account->transactions()->first(); $transaction = $account->transactions()->first();

View File

@@ -128,7 +128,7 @@ class NewUserController extends Controller
* *
* @return bool * @return bool
*/ */
private function createAssetAccount(NewUserFormRequest $request, TransactionCurrency $currency): bool protected function createAssetAccount(NewUserFormRequest $request, TransactionCurrency $currency): bool // create stuff
{ {
$assetAccount = [ $assetAccount = [
'name' => $request->get('bank_name'), 'name' => $request->get('bank_name'),
@@ -156,7 +156,7 @@ class NewUserController extends Controller
* *
* @return bool * @return bool
*/ */
private function createCashWalletAccount(TransactionCurrency $currency, string $language): bool protected function createCashWalletAccount(TransactionCurrency $currency, string $language): bool // create stuff
{ {
$assetAccount = [ $assetAccount = [
'name' => (string)trans('firefly.cash_wallet', [], $language), 'name' => (string)trans('firefly.cash_wallet', [], $language),
@@ -185,7 +185,7 @@ class NewUserController extends Controller
* *
* @return bool * @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 = [ $savingsAccount = [
'name' => (string)trans('firefly.new_savings_account', ['bank_name' => $request->get('bank_name')], $language), 'name' => (string)trans('firefly.new_savings_account', ['bank_name' => $request->get('bank_name')], $language),

View File

@@ -127,7 +127,7 @@ class ReportController extends Controller
* *
* @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/ */
private function balanceAmount(array $attributes): string protected function balanceAmount(array $attributes): string // generate view for report.
{ {
$role = (int)$attributes['role']; $role = (int)$attributes['role'];
$budget = $this->budgetRepository->findNull((int)$attributes['budgetId']); $budget = $this->budgetRepository->findNull((int)$attributes['budgetId']);
@@ -165,7 +165,7 @@ class ReportController extends Controller
* *
* @return string * @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']); $budget = $this->budgetRepository->findNull((int)$attributes['budgetId']);
if (null === $budget) { if (null === $budget) {
@@ -189,7 +189,7 @@ class ReportController extends Controller
* *
* @return string * @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']); $category = $this->categoryRepository->findNull((int)$attributes['categoryId']);
@@ -215,7 +215,7 @@ class ReportController extends Controller
* *
* @return string * @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']); $account = $this->accountRepository->findNull((int)$attributes['accountId']);
@@ -241,7 +241,7 @@ class ReportController extends Controller
* *
* @return string * @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']); $account = $this->accountRepository->findNull((int)$attributes['accountId']);
@@ -267,7 +267,7 @@ class ReportController extends Controller
* *
* @return array * @return array
*/ */
private function parseAttributes(array $attributes): array protected function parseAttributes(array $attributes): array // parse input + return result
{ {
$attributes['location'] = $attributes['location'] ?? ''; $attributes['location'] = $attributes['location'] ?? '';
$attributes['accounts'] = AccountList::routeBinder($attributes['accounts'] ?? '', new Route('get', '', [])); $attributes['accounts'] = AccountList::routeBinder($attributes['accounts'] ?? '', new Route('get', '', []));

View File

@@ -450,7 +450,7 @@ class ProfileController extends Controller
* *
* @throws ValidationException * @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)) { if (!Hash::check($current, $user->password)) {
throw new ValidationException((string)trans('firefly.invalid_current_password')); throw new ValidationException((string)trans('firefly.invalid_current_password'));
@@ -466,7 +466,7 @@ class ProfileController extends Controller
/** /**
* Create new RSA keys. * Create new RSA keys.
*/ */
private function createOAuthKeys(): void protected function createOAuthKeys(): void // create stuff
{ {
$rsa = new RSA(); $rsa = new RSA();
$keys = $rsa->createKey(4096); $keys = $rsa->createKey(4096);
@@ -492,7 +492,7 @@ class ProfileController extends Controller
* *
* @return string * @return string
*/ */
private function getDomain(): string protected function getDomain(): string // get request info
{ {
$url = url()->to('/'); $url = url()->to('/');
$parts = parse_url($url); $parts = parse_url($url);

View File

@@ -117,7 +117,7 @@ class BudgetController extends Controller
* *
* @return array * @return array
*/ */
private function filterBudgetPeriodReport(array $data): array protected function filterBudgetPeriodReport(array $data): array // helper function for period overview.
{ {
/** /**
* @var int * @var int

View File

@@ -173,7 +173,7 @@ class CategoryController extends Controller
* *
* @return array * @return array
*/ */
private function filterReport(array $data): array protected function filterReport(array $data): array // filter data from report.
{ {
foreach ($data as $categoryId => $set) { foreach ($data as $categoryId => $set) {
$sum = '0'; $sum = '0';

View File

@@ -335,7 +335,7 @@ class ExpenseController extends Controller
* *
* @return array * @return array
*/ */
protected function combineAccounts(Collection $accounts): array protected function combineAccounts(Collection $accounts): array // filter + group data
{ {
$combined = []; $combined = [];
/** @var Account $expenseAccount */ /** @var Account $expenseAccount */
@@ -367,7 +367,7 @@ class ExpenseController extends Controller
* @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @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 */ /** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -431,7 +431,7 @@ class ExpenseController extends Controller
* *
* @return array * @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 */ /** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -478,7 +478,7 @@ class ExpenseController extends Controller
* @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @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 */ /** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -545,7 +545,7 @@ class ExpenseController extends Controller
* @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @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 */ /** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -609,7 +609,7 @@ class ExpenseController extends Controller
* *
* @return array * @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 */ /** @var JournalCollectorInterface $collector */
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);

View File

@@ -423,7 +423,7 @@ class ReportController extends Controller
* *
* @return string * @return string
*/ */
private function accountReportOptions(): string protected function accountReportOptions(): string // render a view
{ {
/** @var AccountRepositoryInterface $repository */ /** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class); $repository = app(AccountRepositoryInterface::class);
@@ -451,7 +451,7 @@ class ReportController extends Controller
* *
* @return string * @return string
*/ */
private function budgetReportOptions(): string protected function budgetReportOptions(): string // render a view
{ {
/** @var BudgetRepositoryInterface $repository */ /** @var BudgetRepositoryInterface $repository */
$repository = app(BudgetRepositoryInterface::class); $repository = app(BudgetRepositoryInterface::class);
@@ -471,7 +471,7 @@ class ReportController extends Controller
* *
* @return string * @return string
*/ */
private function categoryReportOptions(): string protected function categoryReportOptions(): string // render a view
{ {
/** @var CategoryRepositoryInterface $repository */ /** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class); $repository = app(CategoryRepositoryInterface::class);
@@ -491,7 +491,7 @@ class ReportController extends Controller
* *
* @return string * @return string
*/ */
private function noReportOptions(): string protected function noReportOptions(): string // render a view
{ {
try { try {
$result = view('reports.options.no-options')->render(); $result = view('reports.options.no-options')->render();
@@ -508,7 +508,7 @@ class ReportController extends Controller
* *
* @return string * @return string
*/ */
private function tagReportOptions(): string protected function tagReportOptions(): string // render a view
{ {
/** @var TagRepositoryInterface $repository */ /** @var TagRepositoryInterface $repository */
$repository = app(TagRepositoryInterface::class); $repository = app(TagRepositoryInterface::class);

View File

@@ -206,7 +206,7 @@ class CreateController extends Controller
* *
* @return array * @return array
*/ */
private function getActionsForBill(Bill $bill): array protected function getActionsForBill(Bill $bill): array // get info and augument
{ {
try { try {
$result = view( $result = view(
@@ -237,7 +237,7 @@ class CreateController extends Controller
* *
* @return array * @return array
*/ */
private function getTriggersForBill(Bill $bill): array protected function getTriggersForBill(Bill $bill): array // get info and augument
{ {
$result = []; $result = [];
$triggers = ['currency_is', 'amount_more', 'amount_less', 'description_contains']; $triggers = ['currency_is', 'amount_more', 'amount_less', 'description_contains'];

View File

@@ -154,7 +154,7 @@ class EditController extends Controller
* *
* @return array * @return array
*/ */
private function getCurrentActions(Rule $rule): array protected function getCurrentActions(Rule $rule): array // get info from object and present.
{ {
$index = 0; $index = 0;
$actions = []; $actions = [];
@@ -192,7 +192,7 @@ class EditController extends Controller
* @return array * @return array
* *
*/ */
private function getCurrentTriggers(Rule $rule): array protected function getCurrentTriggers(Rule $rule): array // get info from object and present.
{ {
$index = 0; $index = 0;
$triggers = []; $triggers = [];

View File

@@ -263,7 +263,7 @@ class SelectController extends Controller
* *
* @return array * @return array
*/ */
private function getValidTriggerList(TestRuleFormRequest $request): array protected function getValidTriggerList(TestRuleFormRequest $request): array // process input
{ {
$triggers = []; $triggers = [];
$data = $request->get('rule_triggers'); $data = $request->get('rule_triggers');

View File

@@ -183,7 +183,7 @@ class InstallController extends Controller
* *
* @return bool * @return bool
*/ */
private function hasForbiddenFunctions(): bool protected function hasForbiddenFunctions(): bool // validate system config
{ {
$list = ['proc_close']; $list = ['proc_close'];
$forbidden = explode(',', ini_get('disable_functions')); $forbidden = explode(',', ini_get('disable_functions'));

View File

@@ -304,7 +304,7 @@ class TagController extends Controller
* *
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @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: // get first and last tag date from tag:
$range = app('preferences')->get('viewRange', '1M')->data; $range = app('preferences')->get('viewRange', '1M')->data;

View File

@@ -181,7 +181,7 @@ class ConvertController extends Controller
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity) * @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 */ /** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class); $accountRepository = app(AccountRepositoryInterface::class);
@@ -242,7 +242,7 @@ class ConvertController extends Controller
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity) * @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 */ /** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class); $accountRepository = app(AccountRepositoryInterface::class);

View File

@@ -450,7 +450,7 @@ class SingleController extends Controller
* *
* @return bool * @return bool
*/ */
private function isSplitJournal(TransactionJournal $journal): bool protected function isSplitJournal(TransactionJournal $journal): bool // validate objects
{ {
$count = $this->repository->countTransactions($journal); $count = $this->repository->countTransactions($journal);

View File

@@ -182,7 +182,7 @@ class SplitController extends Controller
* @return array * @return array
* @throws FireflyException * @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); $sourceAccounts = $this->repository->getJournalSourceAccounts($journal);
$destinationAccounts = $this->repository->getJournalDestinationAccounts($journal); $destinationAccounts = $this->repository->getJournalDestinationAccounts($journal);
@@ -232,7 +232,7 @@ class SplitController extends Controller
* *
* @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/ */
private function getTransactionDataFromJournal(TransactionJournal $journal): array protected function getTransactionDataFromJournal(TransactionJournal $journal): array // convert object
{ {
// use collector to collect transactions. // use collector to collect transactions.
$collector = app(JournalCollectorInterface::class); $collector = app(JournalCollectorInterface::class);
@@ -274,7 +274,7 @@ class SplitController extends Controller
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity) * @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'])) { if (0 === \count($old) || !isset($old['transactions'])) {
return $array; return $array;

View File

@@ -258,7 +258,7 @@ class TransactionController extends Controller
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity) * @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; $range = app('preferences')->get('viewRange', '1M')->data;
$first = $this->repository->firstNull(); $first = $this->repository->firstNull();
@@ -309,7 +309,7 @@ class TransactionController extends Controller
* *
* @return array * @return array
*/ */
private function sumPerCurrency(Collection $collection): array protected function sumPerCurrency(Collection $collection): array // helper for transactions (math, calculations)
{ {
$return = []; $return = [];
/** @var Transaction $transaction */ /** @var Transaction $transaction */

View File

@@ -0,0 +1,96 @@
<?php
/**
* UserNavigation.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* 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());
}
}