Code cleanup.

This commit is contained in:
James Cole
2023-12-20 19:35:52 +01:00
parent c4f6366642
commit 64ec0cf62e
997 changed files with 12908 additions and 28136 deletions

View File

@@ -36,20 +36,15 @@ use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use FireflyIII\Support\Search\OperatorQuerySearch;
use Throwable;
/**
* Trait RenderPartialViews
*
*/
trait RenderPartialViews
{
/**
* View for transactions in a budget for an account.
*
* @param array $attributes
*
* @return string
* @throws FireflyException
*/
protected function budgetEntry(array $attributes): string // generate view for report.
@@ -72,9 +67,10 @@ trait RenderPartialViews
try {
$view = view('popup.report.balance-amount', compact('journals', 'budget', 'account'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
$view = 'Firefly III could not render the view. Please see the log files.';
throw new FireflyException($view, 0, $e);
}
@@ -84,7 +80,6 @@ trait RenderPartialViews
/**
* Get options for budget report.
*
* @return string
* @throws FireflyException
*/
protected function budgetReportOptions(): string // render a view
@@ -95,9 +90,10 @@ trait RenderPartialViews
try {
$result = view('reports.options.budget', compact('budgets'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
$result = 'Could not render view.';
throw new FireflyException($result, 0, $e);
}
@@ -107,9 +103,6 @@ trait RenderPartialViews
/**
* View for spent in a single budget.
*
* @param array $attributes
*
* @return string
* @throws FireflyException
*/
protected function budgetSpentAmount(array $attributes): string // generate view for report.
@@ -128,9 +121,10 @@ trait RenderPartialViews
try {
$view = view('popup.report.budget-spent-amount', compact('journals', 'budget'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
$view = 'Firefly III could not render the view. Please see the log files.';
throw new FireflyException($view, 0, $e);
}
@@ -140,9 +134,6 @@ trait RenderPartialViews
/**
* View for transactions in a category.
*
* @param array $attributes
*
* @return string
* @throws FireflyException
*/
protected function categoryEntry(array $attributes): string // generate view for report.
@@ -157,9 +148,10 @@ trait RenderPartialViews
try {
$view = view('popup.report.category-entry', compact('journals', 'category'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
$view = 'Firefly III could not render the view. Please see the log files.';
throw new FireflyException($view, 0, $e);
}
@@ -169,7 +161,6 @@ trait RenderPartialViews
/**
* Get options for category report.
*
* @return string
* @throws FireflyException
*/
protected function categoryReportOptions(): string // render a view
@@ -180,9 +171,10 @@ trait RenderPartialViews
try {
$result = view('reports.options.category', compact('categories'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Cannot render reports.options.category: %s', $e->getMessage()));
$result = 'Could not render view.';
throw new FireflyException($result, 0, $e);
}
@@ -192,7 +184,6 @@ trait RenderPartialViews
/**
* Get options for double report.
*
* @return string
* @throws FireflyException
*/
protected function doubleReportOptions(): string // render a view
@@ -220,12 +211,12 @@ trait RenderPartialViews
}
}
try {
$result = view('reports.options.double', compact('set'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
$result = 'Could not render view.';
throw new FireflyException($result, 0, $e);
}
@@ -235,9 +226,6 @@ trait RenderPartialViews
/**
* Returns all the expenses that went to the given expense account.
*
* @param array $attributes
*
* @return string
* @throws FireflyException
*/
protected function expenseEntry(array $attributes): string // generate view for report.
@@ -258,9 +246,10 @@ trait RenderPartialViews
try {
$view = view('popup.report.expense-entry', compact('journals', 'account'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
$view = 'Firefly III could not render the view. Please see the log files.';
throw new FireflyException($view, 0, $e);
}
@@ -270,9 +259,6 @@ trait RenderPartialViews
/**
* Get current (from system) rule actions.
*
* @param Rule $rule
*
* @return array
* @throws FireflyException
*/
protected function getCurrentActions(Rule $rule): array // get info from object and present.
@@ -281,9 +267,11 @@ trait RenderPartialViews
$actions = [];
// must be repos
$currentActions = $rule->ruleActions()->orderBy('order', 'ASC')->get();
/** @var RuleAction $entry */
foreach ($currentActions as $entry) {
$count = ($index + 1);
try {
$actions[] = view(
'rules.partials.action',
@@ -294,9 +282,10 @@ trait RenderPartialViews
'count' => $count,
]
)->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->debug(sprintf('Throwable was thrown in getCurrentActions(): %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
throw new FireflyException(sprintf('Could not render: %s', $e->getMessage()), 0, $e);
}
@@ -309,9 +298,6 @@ trait RenderPartialViews
/**
* Get current (from DB) rule triggers.
*
* @param Rule $rule
*
* @return array
* @throws FireflyException
*/
protected function getCurrentTriggers(Rule $rule): array // get info from object and present.
@@ -329,10 +315,12 @@ trait RenderPartialViews
$renderedEntries = [];
// must be repos
$currentTriggers = $rule->ruleTriggers()->orderBy('order', 'ASC')->get();
/** @var RuleTrigger $entry */
foreach ($currentTriggers as $entry) {
if ('user_action' !== $entry->trigger_type) {
$count = ($index + 1);
try {
$rootOperator = OperatorQuerySearch::getRootOperator((string)$entry->trigger_type);
if (str_starts_with($rootOperator, '-')) {
@@ -349,9 +337,10 @@ trait RenderPartialViews
'triggers' => $triggers,
]
)->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->debug(sprintf('Throwable was thrown in getCurrentTriggers(): %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
throw new FireflyException(sprintf('Could not render: %s', $e->getMessage()), 0, $e);
}
@@ -365,9 +354,6 @@ trait RenderPartialViews
/**
* Returns all the incomes that went to the given asset account.
*
* @param array $attributes
*
* @return string
* @throws FireflyException
*/
protected function incomeEntry(array $attributes): string // generate view for report.
@@ -387,9 +373,10 @@ trait RenderPartialViews
try {
$view = view('popup.report.income-entry', compact('journals', 'account'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
$view = 'Firefly III could not render the view. Please see the log files.';
throw new FireflyException($view, 0, $e);
}
@@ -399,16 +386,16 @@ trait RenderPartialViews
/**
* Get options for default report.
*
* @return string
* @throws FireflyException
*/
protected function noReportOptions(): string // render a view
{
try {
$result = view('reports.options.no-options')->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Cannot render reports.options.no-options: %s', $e->getMessage()));
$result = 'Could not render view.';
throw new FireflyException($result, 0, $e);
}
@@ -418,7 +405,6 @@ trait RenderPartialViews
/**
* Get options for tag report.
*
* @return string
* @throws FireflyException
*/
protected function tagReportOptions(): string // render a view
@@ -427,12 +413,12 @@ trait RenderPartialViews
$repository = app(TagRepositoryInterface::class);
$tags = $repository->get();
try {
$result = view('reports.options.tag', compact('tags'))->render();
} catch (Throwable $e) {
} catch (\Throwable $e) {
app('log')->error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
$result = 'Could not render view.';
throw new FireflyException($result, 0, $e);
}