From f0d3ca5d537da9f6b6464e9e65e17030df62907a Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 4 Aug 2018 17:30:06 +0200 Subject: [PATCH] Various code cleanup. --- app/Api/V1/Requests/RecurrenceRequest.php | 2 +- .../Report/Account/MonthReportGenerator.php | 17 ++++-- .../Report/Audit/MonthReportGenerator.php | 15 ++++-- .../Report/Budget/MonthReportGenerator.php | 10 +++- .../Report/Category/MonthReportGenerator.php | 35 ++++++------ .../Report/Standard/MonthReportGenerator.php | 19 ++++--- .../Standard/MultiYearReportGenerator.php | 19 ++++--- .../Report/Standard/YearReportGenerator.php | 20 ++++--- .../Report/Tag/MonthReportGenerator.php | 26 +++++---- .../Controllers/Budget/ShowController.php | 4 +- .../Controllers/Category/ShowController.php | 4 +- app/Http/Controllers/DebugController.php | 2 +- app/Http/Controllers/ExportController.php | 2 +- .../Controllers/Import/CallbackController.php | 2 + .../Controllers/Import/IndexController.php | 2 +- .../Controllers/Json/FrontpageController.php | 10 +++- app/Http/Controllers/JsonController.php | 18 +++++-- .../Controllers/Popup/ReportController.php | 4 +- .../Report/OperationsController.php | 2 +- app/Http/Controllers/ReportController.php | 53 ++++++++++++++----- .../Controllers/Rule/SelectController.php | 2 +- app/Http/Controllers/RuleGroupController.php | 2 +- app/Http/Controllers/SearchController.php | 11 ++-- .../Controllers/TransactionController.php | 2 +- app/Http/Requests/AccountFormRequest.php | 23 +++++++- app/Http/Requests/ExportFormRequest.php | 2 +- app/Http/Requests/RecurrenceFormRequest.php | 2 +- .../Requests/SelectTransactionsRequest.php | 2 +- app/Import/Storage/ImportArrayStorage.php | 4 ++ app/Models/Account.php | 8 +-- app/Models/AccountMeta.php | 6 +-- app/Models/AccountType.php | 20 ++++++- app/Models/Attachment.php | 6 ++- app/Models/AvailableBudget.php | 8 +-- app/Models/Bill.php | 13 +++-- app/Models/Budget.php | 22 ++++---- app/Models/BudgetLimit.php | 6 ++- app/Models/Category.php | 18 ++++--- app/Models/Configuration.php | 5 +- app/Models/CurrencyExchangeRate.php | 12 ++++- app/Models/ExportJob.php | 21 ++++++-- app/Models/ImportJob.php | 13 +++-- app/Models/LinkType.php | 9 ++-- app/Models/Note.php | 2 +- app/Models/PiggyBank.php | 21 ++++---- app/Models/PiggyBankEvent.php | 19 +++---- app/Models/PiggyBankRepetition.php | 10 ++-- app/Models/Preference.php | 11 ++-- app/Models/Recurrence.php | 8 +-- app/Models/RecurrenceMeta.php | 10 ++-- app/Models/RecurrenceRepetition.php | 9 +++- app/Models/RecurrenceTransaction.php | 14 +++-- app/Models/RecurrenceTransactionMeta.php | 9 +++- app/Models/Role.php | 6 +-- app/Models/Rule.php | 6 ++- app/Models/RuleAction.php | 7 +-- app/Models/RuleGroup.php | 18 ++++--- app/Models/RuleTrigger.php | 7 +-- app/Models/Tag.php | 18 ++++--- app/Models/Transaction.php | 43 +++++++++------ app/Models/TransactionCurrency.php | 13 ++--- app/Models/TransactionJournal.php | 35 ++++++------ app/Models/TransactionJournalLink.php | 23 +++++--- app/Models/TransactionJournalMeta.php | 6 +-- app/Models/TransactionType.php | 11 ++-- .../ExportJob/ExportJobRepository.php | 14 +++-- .../Recurring/RecurringRepository.php | 2 +- .../File/ConfigureMappingHandler.php | 1 + .../File/NewFileJobHandler.php | 3 +- .../Ynab/NewYnabJobHandler.php | 6 +++ .../Ynab/SelectAccountsHandler.php | 2 +- .../Routine/Bunq/StageImportDataHandler.php | 1 + .../Import/Routine/Fake/StageFinalHandler.php | 2 +- .../Import/Routine/File/CurrencyMapper.php | 2 +- .../Routine/File/ImportableConverter.php | 2 +- .../Import/Routine/Ynab/ImportDataHandler.php | 3 +- .../Routine/Ynab/StageGetAccessHandler.php | 2 + app/Support/Preferences.php | 5 +- app/Support/Search/Search.php | 2 +- app/Support/Twig/AmountFormat.php | 1 + .../Twig/Extension/TransactionJournal.php | 2 +- app/Support/Twig/General.php | 4 +- app/User.php | 2 +- app/Validation/TransactionValidation.php | 10 ++-- resources/lang/en_US/validation.php | 2 +- resources/views/form/amount-no-currency.twig | 1 + resources/views/form/number.twig | 1 + resources/views/transactions/show.twig | 4 +- 88 files changed, 552 insertions(+), 311 deletions(-) diff --git a/app/Api/V1/Requests/RecurrenceRequest.php b/app/Api/V1/Requests/RecurrenceRequest.php index fd348c733d..77adb8d242 100644 --- a/app/Api/V1/Requests/RecurrenceRequest.php +++ b/app/Api/V1/Requests/RecurrenceRequest.php @@ -84,7 +84,7 @@ class RecurrenceRequest extends Request */ public function rules(): array { - $today = Carbon::create()->addDay(); + $today = Carbon::now()->addDay(); return [ 'type' => 'required|in:withdrawal,transfer,deposit', diff --git a/app/Generator/Report/Account/MonthReportGenerator.php b/app/Generator/Report/Account/MonthReportGenerator.php index 49f0cbfbd7..ab135909f7 100644 --- a/app/Generator/Report/Account/MonthReportGenerator.php +++ b/app/Generator/Report/Account/MonthReportGenerator.php @@ -25,6 +25,8 @@ namespace FireflyIII\Generator\Report\Account; use Carbon\Carbon; use FireflyIII\Generator\Report\ReportGeneratorInterface; use Illuminate\Support\Collection; +use Log; +use Throwable; /** * Class MonthReportGenerator. @@ -44,7 +46,6 @@ class MonthReportGenerator implements ReportGeneratorInterface * Generate the report. * * @return string - * @throws \Throwable */ public function generate(): string { @@ -52,11 +53,17 @@ class MonthReportGenerator implements ReportGeneratorInterface $expenseIds = implode(',', $this->expense->pluck('id')->toArray()); $reportType = 'account'; $preferredPeriod = $this->preferredPeriod(); + try { + $result = view( + 'reports.account.report', + compact('accountIds', 'reportType', 'expenseIds', 'preferredPeriod') + )->with('start', $this->start)->with('end', $this->end)->render(); + } catch (Throwable $e) { + Log::error(sprintf('Cannot render reports.account.report: %s', $e->getMessage())); + $result = 'Could not render report view.'; + } - return view( - 'reports.account.report', - compact('accountIds', 'reportType', 'expenseIds', 'preferredPeriod') - )->with('start', $this->start)->with('end', $this->end)->render(); + return $result; } /** diff --git a/app/Generator/Report/Audit/MonthReportGenerator.php b/app/Generator/Report/Audit/MonthReportGenerator.php index 386f27ded2..3dcaa08952 100644 --- a/app/Generator/Report/Audit/MonthReportGenerator.php +++ b/app/Generator/Report/Audit/MonthReportGenerator.php @@ -34,6 +34,8 @@ use FireflyIII\Models\Transaction; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use Illuminate\Support\Collection; +use Log; +use Throwable; /** * Class MonthReportGenerator. @@ -52,7 +54,6 @@ class MonthReportGenerator implements ReportGeneratorInterface * * @return string * @throws FireflyException - * @throws \Throwable */ public function generate(): string { @@ -78,10 +79,16 @@ class MonthReportGenerator implements ReportGeneratorInterface 'internal_reference', 'notes', 'create_date', 'update_date', ]; + try { + $result = view('reports.audit.report', compact('reportType', 'accountIds', 'auditData', 'hideable', 'defaultShow')) + ->with('start', $this->start)->with('end', $this->end)->with('accounts', $this->accounts) + ->render(); + } catch (Throwable $e) { + Log::error(sprintf('Cannot render reports.audit.report: %s', $e->getMessage())); + $result = 'Could not render report view.'; + } - return view('reports.audit.report', compact('reportType', 'accountIds', 'auditData', 'hideable', 'defaultShow')) - ->with('start', $this->start)->with('end', $this->end)->with('accounts', $this->accounts) - ->render(); + return $result; } /** diff --git a/app/Generator/Report/Budget/MonthReportGenerator.php b/app/Generator/Report/Budget/MonthReportGenerator.php index ff4229ab26..39aaf1696e 100644 --- a/app/Generator/Report/Budget/MonthReportGenerator.php +++ b/app/Generator/Report/Budget/MonthReportGenerator.php @@ -35,6 +35,7 @@ use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionType; use Illuminate\Support\Collection; use Log; +use Throwable; /** * Class MonthReportGenerator. @@ -64,7 +65,6 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface * Generates the report. * * @return string - * @throws \Throwable */ public function generate(): string { @@ -77,11 +77,17 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface $topExpenses = $this->getTopExpenses(); // render! - return view('reports.budget.month', compact('accountIds', 'budgetIds', 'accountSummary', 'budgetSummary', 'averageExpenses', 'topExpenses')) + try { + $result= view('reports.budget.month', compact('accountIds', 'budgetIds', 'accountSummary', 'budgetSummary', 'averageExpenses', 'topExpenses')) ->with('start', $this->start)->with('end', $this->end) ->with('budgets', $this->budgets) ->with('accounts', $this->accounts) ->render(); + } catch (Throwable $e) { + Log::error(sprintf('Cannot render reports.account.report: %s', $e->getMessage())); + $result = 'Could not render report view.'; + } + return $result; } /** diff --git a/app/Generator/Report/Category/MonthReportGenerator.php b/app/Generator/Report/Category/MonthReportGenerator.php index ef187a575b..d454d85dd8 100644 --- a/app/Generator/Report/Category/MonthReportGenerator.php +++ b/app/Generator/Report/Category/MonthReportGenerator.php @@ -36,6 +36,7 @@ use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionType; use Illuminate\Support\Collection; use Log; +use Throwable; /** * Class MonthReportGenerator. @@ -68,7 +69,6 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface * Generates the report. * * @return string - * @throws \Throwable */ public function generate(): string { @@ -85,24 +85,23 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface $topIncome = $this->getTopIncome(); // render! - return view( - 'reports.category.month', - compact( - 'accountIds', - 'categoryIds', - 'topIncome', - 'reportType', - 'accountSummary', - 'categorySummary', - 'averageExpenses', - 'averageIncome', - 'topExpenses' + try { + return view( + 'reports.category.month', compact( + 'accountIds', 'categoryIds', 'topIncome', 'reportType', 'accountSummary', 'categorySummary', 'averageExpenses', + 'averageIncome', 'topExpenses' + ) ) - ) - ->with('start', $this->start)->with('end', $this->end) - ->with('categories', $this->categories) - ->with('accounts', $this->accounts) - ->render(); + ->with('start', $this->start)->with('end', $this->end) + ->with('categories', $this->categories) + ->with('accounts', $this->accounts) + ->render(); + } catch (Throwable $e) { + Log::error(sprintf('Cannot render reports.category.month: %s', $e->getMessage())); + $result = 'Could not render report view.'; + } + + return $result; } /** diff --git a/app/Generator/Report/Standard/MonthReportGenerator.php b/app/Generator/Report/Standard/MonthReportGenerator.php index e27f4d79ed..ad0a9c0b99 100644 --- a/app/Generator/Report/Standard/MonthReportGenerator.php +++ b/app/Generator/Report/Standard/MonthReportGenerator.php @@ -26,6 +26,8 @@ use Carbon\Carbon; use FireflyIII\Generator\Report\ReportGeneratorInterface; use FireflyIII\Helpers\Report\ReportHelperInterface; use Illuminate\Support\Collection; +use Log; +use Throwable; /** * Class MonthReportGenerator. @@ -43,7 +45,6 @@ class MonthReportGenerator implements ReportGeneratorInterface * Generates the report. * * @return string - * @throws \Throwable */ public function generate(): string { @@ -53,11 +54,17 @@ class MonthReportGenerator implements ReportGeneratorInterface $accountIds = implode(',', $this->accounts->pluck('id')->toArray()); $reportType = 'default'; - // continue! - return view( - 'reports.default.month', - compact('bills', 'accountIds', 'reportType') - )->with('start', $this->start)->with('end', $this->end)->render(); + try { + return view( + 'reports.default.month', + compact('bills', 'accountIds', 'reportType') + )->with('start', $this->start)->with('end', $this->end)->render(); + } catch (Throwable $e) { + Log::error(sprintf('Cannot render reports.default.month: %s', $e->getMessage())); + $result = 'Could not render report view.'; + } + + return $result; } /** diff --git a/app/Generator/Report/Standard/MultiYearReportGenerator.php b/app/Generator/Report/Standard/MultiYearReportGenerator.php index ec507b9386..9310554b33 100644 --- a/app/Generator/Report/Standard/MultiYearReportGenerator.php +++ b/app/Generator/Report/Standard/MultiYearReportGenerator.php @@ -25,6 +25,8 @@ namespace FireflyIII\Generator\Report\Standard; use Carbon\Carbon; use FireflyIII\Generator\Report\ReportGeneratorInterface; use Illuminate\Support\Collection; +use Log; +use Throwable; /** * Class MonthReportGenerator. @@ -42,7 +44,6 @@ class MultiYearReportGenerator implements ReportGeneratorInterface * Generates the report. * * @return string - * @throws \Throwable */ public function generate(): string { @@ -50,11 +51,17 @@ class MultiYearReportGenerator implements ReportGeneratorInterface $accountIds = implode(',', $this->accounts->pluck('id')->toArray()); $reportType = 'default'; - // continue! - return view( - 'reports.default.multi-year', - compact('accountIds', 'reportType') - )->with('start', $this->start)->with('end', $this->end)->render(); + try { + return view( + 'reports.default.multi-year', + compact('accountIds', 'reportType') + )->with('start', $this->start)->with('end', $this->end)->render(); + } catch (Throwable $e) { + Log::error(sprintf('Cannot render reports.default.multi-year: %s', $e->getMessage())); + $result = 'Could not render report view.'; + } + + return $result; } /** diff --git a/app/Generator/Report/Standard/YearReportGenerator.php b/app/Generator/Report/Standard/YearReportGenerator.php index 47f92f47ad..bec85e462a 100644 --- a/app/Generator/Report/Standard/YearReportGenerator.php +++ b/app/Generator/Report/Standard/YearReportGenerator.php @@ -25,6 +25,8 @@ namespace FireflyIII\Generator\Report\Standard; use Carbon\Carbon; use FireflyIII\Generator\Report\ReportGeneratorInterface; use Illuminate\Support\Collection; +use Log; +use Throwable; /** * Class MonthReportGenerator. @@ -42,7 +44,6 @@ class YearReportGenerator implements ReportGeneratorInterface * Generates the report. * * @return string - * @throws \Throwable */ public function generate(): string { @@ -50,13 +51,20 @@ class YearReportGenerator implements ReportGeneratorInterface $accountIds = implode(',', $this->accounts->pluck('id')->toArray()); $reportType = 'default'; - // continue! - return view( - 'reports.default.year', - compact('accountIds', 'reportType') - )->with('start', $this->start)->with('end', $this->end)->render(); + try { + $result = view( + 'reports.default.year', + compact('accountIds', 'reportType') + )->with('start', $this->start)->with('end', $this->end)->render(); + } catch (Throwable $e) { + Log::error(sprintf('Cannot render reports.account.report: %s', $e->getMessage())); + $result = 'Could not render report view.'; + } + + return $result; } + /** * Set the accounts. * diff --git a/app/Generator/Report/Tag/MonthReportGenerator.php b/app/Generator/Report/Tag/MonthReportGenerator.php index e367283624..84532e19f1 100644 --- a/app/Generator/Report/Tag/MonthReportGenerator.php +++ b/app/Generator/Report/Tag/MonthReportGenerator.php @@ -38,6 +38,7 @@ use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionType; use Illuminate\Support\Collection; use Log; +use Throwable; /** * Class MonthReportGenerator. @@ -70,7 +71,6 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface * Generate the report. * * @return string - * @throws \Throwable */ public function generate(): string { @@ -87,20 +87,18 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface $topIncome = $this->getTopIncome(); // render! - return view( - 'reports.tag.month', - compact( - 'accountIds', - 'tagTags', - 'reportType', - 'accountSummary', - 'tagSummary', - 'averageExpenses', - 'averageIncome', - 'topIncome', - 'topExpenses' + try { + $result = view( + 'reports.tag.month', compact( + 'accountIds', 'tagTags', 'reportType', 'accountSummary', 'tagSummary', 'averageExpenses', 'averageIncome', 'topIncome', 'topExpenses' ) - )->with('start', $this->start)->with('end', $this->end)->with('tags', $this->tags)->with('accounts', $this->accounts)->render(); + )->with('start', $this->start)->with('end', $this->end)->with('tags', $this->tags)->with('accounts', $this->accounts)->render(); + } catch (Throwable $e) { + Log::error(sprintf('Cannot render reports.tag.month: %s', $e->getMessage())); + $result = 'Could not render report view.'; + } + + return $result; } /** diff --git a/app/Http/Controllers/Budget/ShowController.php b/app/Http/Controllers/Budget/ShowController.php index 0b48280422..3e81b43390 100644 --- a/app/Http/Controllers/Budget/ShowController.php +++ b/app/Http/Controllers/Budget/ShowController.php @@ -142,7 +142,7 @@ class ShowController extends Controller public function show(Request $request, Budget $budget) { /** @var Carbon $start */ - $start = session('first', Carbon::create()->startOfYear()); + $start = session('first', Carbon::now()->startOfYear()); $end = new Carbon; $page = (int)$request->get('page'); $pageSize = (int)app('preferences')->get('listPageSize', 50)->data; @@ -196,7 +196,7 @@ class ShowController extends Controller $transactions = $collector->getPaginatedJournals(); $transactions->setPath(route('budgets.show', [$budget->id, $budgetLimit->id])); /** @var Carbon $start */ - $start = session('first', Carbon::create()->startOfYear()); + $start = session('first', Carbon::now()->startOfYear()); $end = new Carbon; $limits = $this->getLimits($budget, $start, $end); diff --git a/app/Http/Controllers/Category/ShowController.php b/app/Http/Controllers/Category/ShowController.php index eb0e54edfd..623cdaab9d 100644 --- a/app/Http/Controllers/Category/ShowController.php +++ b/app/Http/Controllers/Category/ShowController.php @@ -90,9 +90,9 @@ class ShowController extends Controller { Log::debug('Now in show()'); /** @var Carbon $start */ - $start = $start ?? session('start', Carbon::create()->startOfMonth()); + $start = $start ?? session('start', Carbon::now()->startOfMonth()); /** @var Carbon $end */ - $end = $end ?? session('end', Carbon::create()->startOfMonth()); + $end = $end ?? session('end', Carbon::now()->startOfMonth()); $subTitleIcon = 'fa-bar-chart'; $moment = ''; $page = (int)$request->get('page'); diff --git a/app/Http/Controllers/DebugController.php b/app/Http/Controllers/DebugController.php index 958c51f017..0735d60db9 100644 --- a/app/Http/Controllers/DebugController.php +++ b/app/Http/Controllers/DebugController.php @@ -120,7 +120,7 @@ class DebugController extends Controller $phpVersion = str_replace($search, $replace, PHP_VERSION); $phpOs = str_replace($search, $replace, PHP_OS); $interface = PHP_SAPI; - $now = Carbon::create()->format('Y-m-d H:i:s e'); + $now = Carbon::now()->format('Y-m-d H:i:s e'); $extensions = implode(', ', get_loaded_extensions()); $drivers = implode(', ', DB::availableDrivers()); $currentDriver = DB::getDriverName(); diff --git a/app/Http/Controllers/ExportController.php b/app/Http/Controllers/ExportController.php index 8426d5b2f7..102a10dbb3 100644 --- a/app/Http/Controllers/ExportController.php +++ b/app/Http/Controllers/ExportController.php @@ -125,7 +125,7 @@ class ExportController extends Controller $formats = array_keys(config('firefly.export_formats')); $defaultFormat = app('preferences')->get('export_format', config('firefly.default_export_format'))->data; $first = session('first')->format('Y-m-d'); - $today = Carbon::create()->format('Y-m-d'); + $today = Carbon::now()->format('Y-m-d'); return view('export.index', compact('job', 'formats', 'defaultFormat', 'first', 'today')); } diff --git a/app/Http/Controllers/Import/CallbackController.php b/app/Http/Controllers/Import/CallbackController.php index 9f7f7c62f6..2fb1e0b612 100644 --- a/app/Http/Controllers/Import/CallbackController.php +++ b/app/Http/Controllers/Import/CallbackController.php @@ -36,6 +36,8 @@ class CallbackController extends Controller { /** + * Callback specifically for YNAB logins. + * * @param Request $request * * @param ImportJobRepositoryInterface $repository diff --git a/app/Http/Controllers/Import/IndexController.php b/app/Http/Controllers/Import/IndexController.php index bf45a8c6c3..b24ab51fbb 100644 --- a/app/Http/Controllers/Import/IndexController.php +++ b/app/Http/Controllers/Import/IndexController.php @@ -37,7 +37,7 @@ use Log; */ class IndexController extends Controller { - /** @var array */ + /** @var array All available providers */ public $providers; /** @var ImportJobRepositoryInterface The import job repository */ public $repository; diff --git a/app/Http/Controllers/Json/FrontpageController.php b/app/Http/Controllers/Json/FrontpageController.php index b27dec9585..7a8247b79e 100644 --- a/app/Http/Controllers/Json/FrontpageController.php +++ b/app/Http/Controllers/Json/FrontpageController.php @@ -26,6 +26,8 @@ use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\PiggyBank; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; use Illuminate\Http\JsonResponse; +use Log; +use Throwable; /** * Class FrontpageController. @@ -38,7 +40,6 @@ class FrontpageController extends Controller * @param PiggyBankRepositoryInterface $repository * * @return JsonResponse - * @throws \Throwable */ public function piggyBanks(PiggyBankRepositoryInterface $repository): JsonResponse { @@ -64,7 +65,12 @@ class FrontpageController extends Controller } $html = ''; if (\count($info) > 0) { - $html = view('json.piggy-banks', compact('info'))->render(); + try { + $html = view('json.piggy-banks', compact('info'))->render(); + } catch (Throwable $e) { + Log::error(sprintf('Cannot render json.piggy-banks: %s', $e->getMessage())); + $html = 'Could not render view.'; + } } return response()->json(['html' => $html]); diff --git a/app/Http/Controllers/JsonController.php b/app/Http/Controllers/JsonController.php index a18561b929..a270d98a8b 100644 --- a/app/Http/Controllers/JsonController.php +++ b/app/Http/Controllers/JsonController.php @@ -24,6 +24,8 @@ namespace FireflyIII\Http\Controllers; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Log; +use Throwable; /** * Class JsonController. @@ -36,7 +38,6 @@ class JsonController extends Controller * @param Request $request * * @return JsonResponse - * @throws \Throwable */ public function action(Request $request): JsonResponse { @@ -46,7 +47,12 @@ class JsonController extends Controller foreach ($keys as $key) { $actions[$key] = (string)trans('firefly.rule_action_' . $key . '_choice'); } - $view = view('rules.partials.action', compact('actions', 'count'))->render(); + try { + $view = view('rules.partials.action', compact('actions', 'count'))->render(); + } catch (Throwable $e) { + Log::error(sprintf('Cannot render rules.partials.action: %s', $e->getMessage())); + $view = 'Could not render view.'; + } return response()->json(['html' => $view]); } @@ -57,7 +63,6 @@ class JsonController extends Controller * @param Request $request * * @return JsonResponse - * @throws \Throwable */ public function trigger(Request $request): JsonResponse { @@ -71,7 +76,12 @@ class JsonController extends Controller } asort($triggers); - $view = view('rules.partials.trigger', compact('triggers', 'count'))->render(); + try { + $view = view('rules.partials.trigger', compact('triggers', 'count'))->render(); + } catch (Throwable $e) { + Log::error(sprintf('Cannot render rules.partials.trigger: %s', $e->getMessage())); + $view = 'Could not render view.'; + } return response()->json(['html' => $view]); } diff --git a/app/Http/Controllers/Popup/ReportController.php b/app/Http/Controllers/Popup/ReportController.php index d07a09ab63..8e7d3e3cb6 100644 --- a/app/Http/Controllers/Popup/ReportController.php +++ b/app/Http/Controllers/Popup/ReportController.php @@ -274,7 +274,7 @@ class ReportController extends Controller $attributes['startDate'] = Carbon::createFromFormat('Ymd', $attributes['startDate']); } catch (InvalidArgumentException $e) { Log::debug(sprintf('Not important error message: %s', $e->getMessage())); - $date = Carbon::create()->startOfMonth(); + $date = Carbon::now()->startOfMonth(); $attributes['startDate'] = $date; } @@ -282,7 +282,7 @@ class ReportController extends Controller $attributes['endDate'] = Carbon::createFromFormat('Ymd', $attributes['endDate']); } catch (InvalidArgumentException $e) { Log::debug(sprintf('Not important error message: %s', $e->getMessage())); - $date = Carbon::create()->startOfMonth(); + $date = Carbon::now()->startOfMonth(); $attributes['endDate'] = $date; } diff --git a/app/Http/Controllers/Report/OperationsController.php b/app/Http/Controllers/Report/OperationsController.php index 04a5307c0b..b5223dd5b7 100644 --- a/app/Http/Controllers/Report/OperationsController.php +++ b/app/Http/Controllers/Report/OperationsController.php @@ -38,7 +38,7 @@ class OperationsController extends Controller private $tasker; /** - * + * OperationsController constructor. */ public function __construct() { diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index ff77965966..df5d3baa9c 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -36,6 +36,7 @@ use FireflyIII\Repositories\Tag\TagRepositoryInterface; use Illuminate\Http\RedirectResponse; use Illuminate\Support\Collection; use Log; +use Throwable; /** * Class ReportController. @@ -277,7 +278,6 @@ class ReportController extends Controller * * @return mixed * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @throws \Throwable */ public function options(string $reportType) { @@ -391,7 +391,6 @@ class ReportController extends Controller * @param Carbon $end * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|string - * * @throws \FireflyIII\Exceptions\FireflyException */ public function tagReport(Collection $accounts, Collection $tags, Carbon $start, Carbon $end) @@ -423,7 +422,6 @@ class ReportController extends Controller * Get options for account report. * * @return string - * @throws \Throwable */ private function accountReportOptions(): string { @@ -438,52 +436,77 @@ class ReportController extends Controller $set->push($exp); } } + try { + $result = view('reports.options.account', compact('set'))->render(); + } catch (Throwable $e) { + Log::error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage())); + $result = 'Could not render view.'; + } - return view('reports.options.account', compact('set'))->render(); + return $result; } /** * Get options for budget report. + * * @return string - * @throws \Throwable */ private function budgetReportOptions(): string { /** @var BudgetRepositoryInterface $repository */ $repository = app(BudgetRepositoryInterface::class); $budgets = $repository->getBudgets(); + try { + $result = view('reports.options.budget', compact('budgets'))->render(); + } catch (Throwable $e) { + Log::error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage())); + $result = 'Could not render view.'; + } - return view('reports.options.budget', compact('budgets'))->render(); + return $result; } /** * Get options for category report. + * * @return string - * @throws \Throwable */ private function categoryReportOptions(): string { /** @var CategoryRepositoryInterface $repository */ $repository = app(CategoryRepositoryInterface::class); $categories = $repository->getCategories(); + try { + $result = view('reports.options.category', compact('categories'))->render(); + } catch (Throwable $e) { + Log::error(sprintf('Cannot render reports.options.category: %s', $e->getMessage())); + $result = 'Could not render view.'; + } - return view('reports.options.category', compact('categories'))->render(); + return $result; } /** * Get options for default report. + * * @return string - * @throws \Throwable */ private function noReportOptions(): string { - return view('reports.options.no-options')->render(); + try { + $result = view('reports.options.no-options')->render(); + } catch (Throwable $e) { + Log::error(sprintf('Cannot render reports.options.no-options: %s', $e->getMessage())); + $result = 'Could not render view.'; + } + + return $result; } /** * Get options for tag report. + * * @return string - * @throws \Throwable */ private function tagReportOptions(): string { @@ -494,7 +517,13 @@ class ReportController extends Controller return $tag->tag; } ); + try { + $result = view('reports.options.tag', compact('tags'))->render(); + } catch (Throwable $e) { + Log::error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage())); + $result = 'Could not render view.'; + } - return view('reports.options.tag', compact('tags'))->render(); + return $result; } } diff --git a/app/Http/Controllers/Rule/SelectController.php b/app/Http/Controllers/Rule/SelectController.php index 6381fbf21c..b8c30229f2 100644 --- a/app/Http/Controllers/Rule/SelectController.php +++ b/app/Http/Controllers/Rule/SelectController.php @@ -118,7 +118,7 @@ class SelectController extends Controller { // does the user have shared accounts? $first = session('first')->format('Y-m-d'); - $today = Carbon::create()->format('Y-m-d'); + $today = Carbon::now()->format('Y-m-d'); $subTitle = (string)trans('firefly.apply_rule_selection', ['title' => $rule->title]); return view('rules.rule.select-transactions', compact('first', 'today', 'rule', 'subTitle')); diff --git a/app/Http/Controllers/RuleGroupController.php b/app/Http/Controllers/RuleGroupController.php index c814776eb8..8a99cd2ab7 100644 --- a/app/Http/Controllers/RuleGroupController.php +++ b/app/Http/Controllers/RuleGroupController.php @@ -208,7 +208,7 @@ class RuleGroupController extends Controller public function selectTransactions(RuleGroup $ruleGroup) { $first = session('first')->format('Y-m-d'); - $today = Carbon::create()->format('Y-m-d'); + $today = Carbon::now()->format('Y-m-d'); $subTitle = (string)trans('firefly.apply_rule_group_selection', ['title' => $ruleGroup->title]); return view('rules.rule-group.select-transactions', compact('first', 'today', 'ruleGroup', 'subTitle')); diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index 6308bd1770..57e1b9e949 100644 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -27,6 +27,8 @@ use FireflyIII\Support\Search\SearchInterface; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Collection; +use Log; +use Throwable; /** * Class SearchController. @@ -77,7 +79,6 @@ class SearchController extends Controller * @param SearchInterface $searcher * * @return \Illuminate\Http\JsonResponse - * @throws \Throwable */ public function search(Request $request, SearchInterface $searcher): JsonResponse { @@ -99,8 +100,12 @@ class SearchController extends Controller $transactions = $searcher->searchTransactions(); $cache->store($transactions); } - - $html = view('search.search', compact('transactions'))->render(); + try { + $html = view('search.search', compact('transactions'))->render(); + } catch (Throwable $e) { + Log::error(sprintf('Cannot render search.search: %s', $e->getMessage())); + $html = 'Could not render view.'; + } return response()->json(['count' => $transactions->count(), 'html' => $html]); } diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index c9685012a6..a989dda208 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -262,7 +262,7 @@ class TransactionController extends Controller { $range = app('preferences')->get('viewRange', '1M')->data; $first = $this->repository->firstNull(); - $start = Carbon::create()->subYear(); + $start = Carbon::now()->subYear(); $types = config('firefly.transactionTypesByWhat.' . $what); $entries = new Collection; if (null !== $first) { diff --git a/app/Http/Requests/AccountFormRequest.php b/app/Http/Requests/AccountFormRequest.php index f79500515a..d347aa7a9e 100644 --- a/app/Http/Requests/AccountFormRequest.php +++ b/app/Http/Requests/AccountFormRequest.php @@ -48,7 +48,7 @@ class AccountFormRequest extends Request */ public function getAccountData(): array { - return [ + $data = [ 'name' => $this->string('name'), 'active' => $this->boolean('active'), 'accountType' => $this->string('what'), @@ -64,7 +64,22 @@ class AccountFormRequest extends Request 'ccType' => $this->string('ccType'), 'ccMonthlyPaymentDate' => $this->string('ccMonthlyPaymentDate'), 'notes' => $this->string('notes'), + 'interest' => $this->string('interest'), + 'interest_period' => $this->string('interest_period'), ]; + + // if the account type is "liabilities" there are actually four types of liability + // that could have been selected. + if ($data['accountType'] === 'liabilities') { + $data['accountType'] = null; + $data['account_type_id'] = $this->integer('liability_type_id'); + // also reverse the opening balance: + if ('' !== $data['openingBalance']) { + $data['openingBalance'] = bcmul($data['openingBalance'], '-1'); + } + } + + return $data; } /** @@ -93,8 +108,14 @@ class AccountFormRequest extends Request 'amount_currency_id_openingBalance' => 'exists:transaction_currencies,id', 'amount_currency_id_virtualBalance' => 'exists:transaction_currencies,id', 'what' => 'in:' . $types, + 'interest_period' => 'in:daily,monthly,yearly', ]; + if ('liabilities' === $this->get('what')) { + $rules['openingBalance'] = 'numeric|required|more:0'; + $rules['openingBalanceDate'] = 'date|required'; + } + /** @var Account $account */ $account = $this->route()->parameter('account'); if (null !== $account) { diff --git a/app/Http/Requests/ExportFormRequest.php b/app/Http/Requests/ExportFormRequest.php index 942aca6870..d19441209c 100644 --- a/app/Http/Requests/ExportFormRequest.php +++ b/app/Http/Requests/ExportFormRequest.php @@ -50,7 +50,7 @@ class ExportFormRequest extends Request /** @var Carbon $sessionFirst */ $sessionFirst = clone session('first'); $first = $sessionFirst->subDay()->format('Y-m-d'); - $today = Carbon::create()->addDay()->format('Y-m-d'); + $today = Carbon::now()->addDay()->format('Y-m-d'); $formats = implode(',', array_keys(config('firefly.export_formats'))); // fixed diff --git a/app/Http/Requests/RecurrenceFormRequest.php b/app/Http/Requests/RecurrenceFormRequest.php index 47c389922e..7f2fba4f03 100644 --- a/app/Http/Requests/RecurrenceFormRequest.php +++ b/app/Http/Requests/RecurrenceFormRequest.php @@ -149,7 +149,7 @@ class RecurrenceFormRequest extends Request public function rules(): array { $today = new Carbon; - $tomorrow = Carbon::create()->addDay(); + $tomorrow = Carbon::now()->addDay(); $rules = [ // mandatory info for recurrence. 'title' => 'required|between:1,255|uniqueObjectForUser:recurrences,title', diff --git a/app/Http/Requests/SelectTransactionsRequest.php b/app/Http/Requests/SelectTransactionsRequest.php index 9207a51159..5697fdfb62 100644 --- a/app/Http/Requests/SelectTransactionsRequest.php +++ b/app/Http/Requests/SelectTransactionsRequest.php @@ -53,7 +53,7 @@ class SelectTransactionsRequest extends Request /** @var Carbon $sessionFirst */ $sessionFirst = clone session('first'); $first = $sessionFirst->subDay()->format('Y-m-d'); - $today = Carbon::create()->addDay()->format('Y-m-d'); + $today = Carbon::now()->addDay()->format('Y-m-d'); return [ 'start_date' => 'required|date|after:' . $first, diff --git a/app/Import/Storage/ImportArrayStorage.php b/app/Import/Storage/ImportArrayStorage.php index 1a736c5acc..ebe5eeb859 100644 --- a/app/Import/Storage/ImportArrayStorage.php +++ b/app/Import/Storage/ImportArrayStorage.php @@ -26,6 +26,7 @@ namespace FireflyIII\Import\Storage; use Carbon\Carbon; use DB; +use FireflyIII\Events\RequestedReportOnJournals; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Helpers\Filter\InternalTransferFilter; @@ -114,6 +115,9 @@ class ImportArrayStorage app('preferences')->mark(); + // email about this: + event(new RequestedReportOnJournals($this->importJob->user_id, $collection)); + return $collection; } diff --git a/app/Models/Account.php b/app/Models/Account.php index ba5aef5da0..b4d40cc1af 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -75,18 +75,20 @@ class Account extends Model 'active' => 'boolean', 'encrypted' => 'boolean', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['user_id', 'account_type_id', 'name', 'active', 'virtual_balance', 'iban']; - /** @var array */ + /** @var array Hidden from view */ protected $hidden = ['encrypted']; /** @var bool */ private $joinedAccountTypes; /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param string $value * * @return Account - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws NotFoundHttpException */ public static function routeBinder(string $value): Account { diff --git a/app/Models/AccountMeta.php b/app/Models/AccountMeta.php index 4f6e68e52c..ff36c2ec93 100644 --- a/app/Models/AccountMeta.php +++ b/app/Models/AccountMeta.php @@ -44,11 +44,9 @@ class AccountMeta extends Model 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['account_id', 'name', 'data']; - /** - * @var string - */ + /** @var string The table to store the data in */ protected $table = 'account_meta'; /** diff --git a/app/Models/AccountType.php b/app/Models/AccountType.php index 1446d0d6e3..2faad2e91a 100644 --- a/app/Models/AccountType.php +++ b/app/Models/AccountType.php @@ -35,25 +35,43 @@ use Illuminate\Database\Eloquent\Relations\HasMany; */ class AccountType extends Model { + /** @var string */ public const DEFAULT = 'Default account'; + /** @var string */ public const CASH = 'Cash account'; + /** @var string */ public const ASSET = 'Asset account'; + /** @var string */ public const EXPENSE = 'Expense account'; + /** @var string */ public const REVENUE = 'Revenue account'; + /** @var string */ public const INITIAL_BALANCE = 'Initial balance account'; + /** @var string */ public const BENEFICIARY = 'Beneficiary account'; + /** @var string */ public const IMPORT = 'Import account'; + /** @var string */ public const RECONCILIATION = 'Reconciliation account'; + /** @var string */ public const LOAN = 'Loan'; + /** @var string */ public const DEBT = 'Debt'; + /** @var string */ public const MORTGAGE = 'Mortgage'; + /** @var string */ public const CREDITCARD = 'Credit card'; + /** + * The attributes that should be casted to native types. + * + * @var array + */ protected $casts = [ 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['type']; /** diff --git a/app/Models/Attachment.php b/app/Models/Attachment.php index 591f2dfa71..967316202b 100644 --- a/app/Models/Attachment.php +++ b/app/Models/Attachment.php @@ -66,14 +66,16 @@ class Attachment extends Model 'deleted_at' => 'datetime', 'uploaded' => 'boolean', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['attachable_id', 'attachable_type', 'user_id', 'md5', 'filename', 'mime', 'title', 'description', 'size', 'uploaded']; /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param string $value * * @return Attachment - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws NotFoundHttpException */ public static function routeBinder(string $value): Attachment { diff --git a/app/Models/AvailableBudget.php b/app/Models/AvailableBudget.php index 4950cb7661..0e41aaf521 100644 --- a/app/Models/AvailableBudget.php +++ b/app/Models/AvailableBudget.php @@ -58,14 +58,16 @@ class AvailableBudget extends Model 'start_date' => 'date', 'end_date' => 'date', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['user_id', 'transaction_currency_id', 'amount', 'start_date', 'end_date']; /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param string $value * * @return AvailableBudget - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws NotFoundHttpException */ public static function routeBinder(string $value): AvailableBudget { @@ -84,7 +86,7 @@ class AvailableBudget extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ public function transactionCurrency(): BelongsTo { diff --git a/app/Models/Bill.php b/app/Models/Bill.php index f0b0ce6711..2354c460f0 100644 --- a/app/Models/Bill.php +++ b/app/Models/Bill.php @@ -77,22 +77,21 @@ class Bill extends Model 'name_encrypted' => 'boolean', 'match_encrypted' => 'boolean', ]; - /** - * @var array - */ + + /** @var array Fields that can be filled */ protected $fillable = ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip', 'automatch', 'active', 'transaction_currency_id']; - /** - * @var array - */ + /** @var array Hidden from view */ protected $hidden = ['amount_min_encrypted', 'amount_max_encrypted', 'name_encrypted', 'match_encrypted']; /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param string $value * * @return Bill - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws NotFoundHttpException */ public static function routeBinder(string $value): Bill { diff --git a/app/Models/Budget.php b/app/Models/Budget.php index ab87f02080..106739fcec 100644 --- a/app/Models/Budget.php +++ b/app/Models/Budget.php @@ -26,6 +26,8 @@ use Crypt; use FireflyIII\User; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Collection; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -58,16 +60,18 @@ class Budget extends Model 'active' => 'boolean', 'encrypted' => 'boolean', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['user_id', 'name', 'active']; - /** @var array */ + /** @var array Hidden from view */ protected $hidden = ['encrypted']; /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param string $value * * @return Budget - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws NotFoundHttpException */ public static function routeBinder(string $value): Budget { @@ -86,9 +90,9 @@ class Budget extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function budgetlimits(): \Illuminate\Database\Eloquent\Relations\HasMany + public function budgetlimits(): HasMany { return $this->hasMany(BudgetLimit::class); } @@ -126,18 +130,18 @@ class Budget extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return BelongsToMany */ - public function transactionJournals(): \Illuminate\Database\Eloquent\Relations\BelongsToMany + public function transactionJournals(): BelongsToMany { return $this->belongsToMany(TransactionJournal::class, 'budget_transaction_journal', 'budget_id'); } /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return BelongsToMany */ - public function transactions(): \Illuminate\Database\Eloquent\Relations\BelongsToMany + public function transactions(): BelongsToMany { return $this->belongsToMany(Transaction::class, 'budget_transaction', 'budget_id'); } diff --git a/app/Models/BudgetLimit.php b/app/Models/BudgetLimit.php index 15f11689a2..2306e375de 100644 --- a/app/Models/BudgetLimit.php +++ b/app/Models/BudgetLimit.php @@ -54,13 +54,17 @@ class BudgetLimit extends Model 'start_date' => 'date', 'end_date' => 'date', ]; + + /** @var array Fields that can be filled */ protected $fillable = ['budget_id', 'start_date', 'end_date', 'amount']; /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param string $value * * @return mixed - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws NotFoundHttpException */ public static function routeBinder(string $value): BudgetLimit { diff --git a/app/Models/Category.php b/app/Models/Category.php index 359dd039e3..92e657d78f 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -18,6 +18,7 @@ * You should have received a copy of the GNU General Public License * along with Firefly III. If not, see . */ + declare(strict_types=1); namespace FireflyIII\Models; @@ -27,6 +28,7 @@ use Crypt; use FireflyIII\User; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\SoftDeletes; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -55,16 +57,18 @@ class Category extends Model 'deleted_at' => 'datetime', 'encrypted' => 'boolean', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['user_id', 'name']; - /** @var array */ + /** @var array Hidden from view */ protected $hidden = ['encrypted']; /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param string $value * * @return Category - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws NotFoundHttpException */ public static function routeBinder(string $value): Category { @@ -114,18 +118,18 @@ class Category extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return BelongsToMany */ - public function transactionJournals(): \Illuminate\Database\Eloquent\Relations\BelongsToMany + public function transactionJournals(): BelongsToMany { return $this->belongsToMany(TransactionJournal::class, 'category_transaction_journal', 'category_id'); } /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return BelongsToMany */ - public function transactions(): \Illuminate\Database\Eloquent\Relations\BelongsToMany + public function transactions(): BelongsToMany { return $this->belongsToMany(Transaction::class, 'category_transaction', 'category_id'); } diff --git a/app/Models/Configuration.php b/app/Models/Configuration.php index 76eae0f9ed..771f9a86b2 100644 --- a/app/Models/Configuration.php +++ b/app/Models/Configuration.php @@ -44,10 +44,9 @@ class Configuration extends Model = [ 'created_at' => 'datetime', 'updated_at' => 'datetime', + 'deleted_at' => 'datetime', ]; - /** - * @var string - */ + /** @var string The table to store the data in */ protected $table = 'configuration'; /** diff --git a/app/Models/CurrencyExchangeRate.php b/app/Models/CurrencyExchangeRate.php index e77bb2484c..203b4d6bd2 100644 --- a/app/Models/CurrencyExchangeRate.php +++ b/app/Models/CurrencyExchangeRate.php @@ -43,8 +43,16 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; */ class CurrencyExchangeRate extends Model { - /** @var array */ - protected $dates = ['date']; + /** @var array Convert these fields to other data types */ + protected $casts + = [ + 'created_at' => 'datetime', + 'updated_at' => 'datetime', + 'user_id' => 'int', + 'from_currency_id' => 'int', + 'to_currency_id' => 'int', + 'date' => 'datetime', + ]; /** * @codeCoverageIgnore diff --git a/app/Models/ExportJob.php b/app/Models/ExportJob.php index 593b3ebc64..474d29f9da 100644 --- a/app/Models/ExportJob.php +++ b/app/Models/ExportJob.php @@ -24,6 +24,7 @@ namespace FireflyIII\Models; use FireflyIII\User; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** @@ -37,7 +38,11 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; */ class ExportJob extends Model { - /** @var array */ + /** + * The attributes that should be casted to native types. + * + * @var array + */ protected $casts = [ 'created_at' => 'datetime', @@ -45,6 +50,8 @@ class ExportJob extends Model ]; /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param string $value * * @return ExportJob @@ -67,9 +74,12 @@ class ExportJob extends Model } /** - * @codeCoverageIgnore + * Change the status of this export job. * * @param $status + * + * @deprecated + * @codeCoverageIgnore */ public function change($status): void { @@ -78,10 +88,13 @@ class ExportJob extends Model } /** + * Returns the user this objects belongs to. + * + * + * @return BelongsTo * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ - public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo + public function user(): BelongsTo { return $this->belongsTo(User::class); } diff --git a/app/Models/ImportJob.php b/app/Models/ImportJob.php index 6957faaf2e..ab8392a1f7 100644 --- a/app/Models/ImportJob.php +++ b/app/Models/ImportJob.php @@ -24,6 +24,7 @@ namespace FireflyIII\Models; use FireflyIII\User; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** @@ -61,10 +62,12 @@ class ImportJob extends Model 'transactions' => 'array', 'errors' => 'array', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['key', 'user_id', 'file_type', 'provider', 'status', 'stage', 'configuration', 'extended_status', 'transactions', 'errors']; /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param $value * * @return mixed @@ -97,18 +100,18 @@ class ImportJob extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ - public function tag(): \Illuminate\Database\Eloquent\Relations\BelongsTo + public function tag(): BelongsTo { return $this->belongsTo(Tag::class); } /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ - public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo + public function user(): BelongsTo { return $this->belongsTo(User::class); } diff --git a/app/Models/LinkType.php b/app/Models/LinkType.php index f5f1bd9e86..0e44074d61 100644 --- a/app/Models/LinkType.php +++ b/app/Models/LinkType.php @@ -24,6 +24,7 @@ namespace FireflyIII\Models; use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -55,10 +56,12 @@ class LinkType extends Model 'editable' => 'boolean', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['name', 'inward', 'outward', 'editable']; /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param $value * * @return LinkType @@ -79,9 +82,9 @@ class LinkType extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function transactionJournalLinks(): \Illuminate\Database\Eloquent\Relations\HasMany + public function transactionJournalLinks(): HasMany { return $this->hasMany(TransactionJournalLink::class); } diff --git a/app/Models/Note.php b/app/Models/Note.php index ee4accbce0..d67b00d82b 100644 --- a/app/Models/Note.php +++ b/app/Models/Note.php @@ -51,7 +51,7 @@ class Note extends Model 'updated_at' => 'datetime', 'deleted_at' => 'datetime', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['title', 'text', 'noteable_id', 'noteable_type']; /** diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php index 7436b5c35c..360d4b7c01 100644 --- a/app/Models/PiggyBank.php +++ b/app/Models/PiggyBank.php @@ -26,6 +26,7 @@ use Carbon\Carbon; use Crypt; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\SoftDeletes; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -67,18 +68,18 @@ class PiggyBank extends Model 'active' => 'boolean', 'encrypted' => 'boolean', ]; - /** @var array */ - protected $dates = ['startdate', 'targetdate']; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['name', 'account_id', 'order', 'targetamount', 'startdate', 'targetdate', 'active']; - /** @var array */ + /** @var array Hidden from view */ protected $hidden = ['targetamount_encrypted', 'encrypted']; /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param string $value * * @return PiggyBank - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws NotFoundHttpException */ public static function routeBinder(string $value): PiggyBank { @@ -96,7 +97,7 @@ class PiggyBank extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ public function account(): BelongsTo { @@ -131,18 +132,18 @@ class PiggyBank extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function piggyBankEvents(): \Illuminate\Database\Eloquent\Relations\HasMany + public function piggyBankEvents(): HasMany { return $this->hasMany(PiggyBankEvent::class); } /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function piggyBankRepetitions(): \Illuminate\Database\Eloquent\Relations\HasMany + public function piggyBankRepetitions(): HasMany { return $this->hasMany(PiggyBankRepetition::class); } diff --git a/app/Models/PiggyBankEvent.php b/app/Models/PiggyBankEvent.php index e01ed0a677..3cb7541896 100644 --- a/app/Models/PiggyBankEvent.php +++ b/app/Models/PiggyBankEvent.php @@ -24,6 +24,7 @@ namespace FireflyIII\Models; use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; /** * Class PiggyBankEvent. @@ -47,22 +48,16 @@ class PiggyBankEvent extends Model 'updated_at' => 'datetime', 'date' => 'date', ]; - /** @var array */ - protected $dates = ['date']; - /** - * @var array - */ + /** @var array Fields that can be filled */ protected $fillable = ['piggy_bank_id', 'transaction_journal_id', 'date', 'amount']; - /** - * @var array - */ + /** @var array Hidden from view */ protected $hidden = ['amount_encrypted']; /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ - public function piggyBank(): \Illuminate\Database\Eloquent\Relations\BelongsTo + public function piggyBank(): BelongsTo { return $this->belongsTo(PiggyBank::class); } @@ -79,9 +74,9 @@ class PiggyBankEvent extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ - public function transactionJournal(): \Illuminate\Database\Eloquent\Relations\BelongsTo + public function transactionJournal(): BelongsTo { return $this->belongsTo(TransactionJournal::class); } diff --git a/app/Models/PiggyBankRepetition.php b/app/Models/PiggyBankRepetition.php index a021ce61b6..450b91addc 100644 --- a/app/Models/PiggyBankRepetition.php +++ b/app/Models/PiggyBankRepetition.php @@ -25,6 +25,7 @@ namespace FireflyIII\Models; use Carbon\Carbon; use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; /** * Class PiggyBankRepetition. @@ -44,20 +45,17 @@ class PiggyBankRepetition extends Model = [ 'created_at' => 'datetime', 'updated_at' => 'datetime', - 'deleted_at' => 'datetime', 'startdate' => 'date', 'targetdate' => 'date', ]; - /** @var array */ - protected $dates = ['startdate', 'targetdate']; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['piggy_bank_id', 'startdate', 'targetdate', 'currentamount']; /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ - public function piggyBank(): \Illuminate\Database\Eloquent\Relations\BelongsTo + public function piggyBank(): BelongsTo { return $this->belongsTo(PiggyBank::class); } diff --git a/app/Models/Preference.php b/app/Models/Preference.php index cc9ccc0b15..a7e28d2bad 100644 --- a/app/Models/Preference.php +++ b/app/Models/Preference.php @@ -29,6 +29,7 @@ use FireflyIII\Exceptions\FireflyException; use FireflyIII\User; use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Log; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -55,14 +56,16 @@ class Preference extends Model 'updated_at' => 'datetime', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['user_id', 'data', 'name']; /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param string $value * * @return Preference - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws NotFoundHttpException */ public static function routeBinder(string $value): Preference { @@ -129,9 +132,9 @@ class Preference extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ - public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo + public function user(): BelongsTo { return $this->belongsTo(User::class); } diff --git a/app/Models/Recurrence.php b/app/Models/Recurrence.php index 243eece7b6..0c4ac5a9c0 100644 --- a/app/Models/Recurrence.php +++ b/app/Models/Recurrence.php @@ -82,17 +82,19 @@ class Recurrence extends Model 'active' => 'bool', 'apply_rules' => 'bool', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['user_id', 'transaction_type_id', 'title', 'description', 'first_date', 'repeat_until', 'latest_date', 'repetitions', 'apply_rules', 'active']; - /** @var string */ + /** @var string The table to store the data in */ protected $table = 'recurrences'; /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param string $value * * @return Recurrence - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws NotFoundHttpException */ public static function routeBinder(string $value): Recurrence { diff --git a/app/Models/RecurrenceMeta.php b/app/Models/RecurrenceMeta.php index dbd7424917..2dd414c907 100644 --- a/app/Models/RecurrenceMeta.php +++ b/app/Models/RecurrenceMeta.php @@ -37,7 +37,11 @@ use Illuminate\Database\Eloquent\SoftDeletes; class RecurrenceMeta extends Model { use SoftDeletes; - /** @var array */ + /** + * The attributes that should be casted to native types. + * + * @var array + */ protected $casts = [ 'created_at' => 'datetime', @@ -46,9 +50,9 @@ class RecurrenceMeta extends Model 'name' => 'string', 'value' => 'string', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['recurrence_id', 'name', 'value']; - /** @var string */ + /** @var string The table to store the data in */ protected $table = 'recurrences_meta'; /** diff --git a/app/Models/RecurrenceRepetition.php b/app/Models/RecurrenceRepetition.php index 89c54def54..cc26a97378 100644 --- a/app/Models/RecurrenceRepetition.php +++ b/app/Models/RecurrenceRepetition.php @@ -51,7 +51,11 @@ class RecurrenceRepetition extends Model /** @var int */ public const WEEKEND_TO_MONDAY = 4; use SoftDeletes; - /** @var array */ + /** + * The attributes that should be casted to native types. + * + * @var array + */ protected $casts = [ 'created_at' => 'datetime', @@ -62,8 +66,9 @@ class RecurrenceRepetition extends Model 'repetition_skip' => 'int', 'weekend' => 'int', ]; + /** @var array Fields that can be filled */ protected $fillable = ['recurrence_id', 'weekend', 'repetition_type', 'repetition_moment', 'repetition_skip']; - /** @var string */ + /** @var string The table to store the data in */ protected $table = 'recurrences_repetitions'; /** diff --git a/app/Models/RecurrenceTransaction.php b/app/Models/RecurrenceTransaction.php index 62ffd49d10..14812b9068 100644 --- a/app/Models/RecurrenceTransaction.php +++ b/app/Models/RecurrenceTransaction.php @@ -51,7 +51,11 @@ use Illuminate\Database\Eloquent\SoftDeletes; class RecurrenceTransaction extends Model { use SoftDeletes; - /** @var array */ + /** + * The attributes that should be casted to native types. + * + * @var array + */ protected $casts = [ 'created_at' => 'datetime', @@ -61,16 +65,16 @@ class RecurrenceTransaction extends Model 'foreign_amount' => 'string', 'description' => 'string', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['recurrence_id', 'transaction_currency_id', 'foreign_currency_id', 'source_id', 'destination_id', 'amount', 'foreign_amount', 'description']; - /** @var string */ + /** @var string The table to store the data in */ protected $table = 'recurrences_transactions'; /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ public function destinationAccount(): BelongsTo { @@ -106,7 +110,7 @@ class RecurrenceTransaction extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ public function sourceAccount(): BelongsTo { diff --git a/app/Models/RecurrenceTransactionMeta.php b/app/Models/RecurrenceTransactionMeta.php index e39aff977e..1f283ad0db 100644 --- a/app/Models/RecurrenceTransactionMeta.php +++ b/app/Models/RecurrenceTransactionMeta.php @@ -37,7 +37,11 @@ use Illuminate\Database\Eloquent\SoftDeletes; class RecurrenceTransactionMeta extends Model { use SoftDeletes; - /** @var array */ + /** + * The attributes that should be casted to native types. + * + * @var array + */ protected $casts = [ 'created_at' => 'datetime', @@ -46,8 +50,9 @@ class RecurrenceTransactionMeta extends Model 'name' => 'string', 'value' => 'string', ]; + /** @var array Fields that can be filled */ protected $fillable = ['rt_id', 'name', 'value']; - /** @var string */ + /** @var string The table to store the data in */ protected $table = 'rt_meta'; /** diff --git a/app/Models/Role.php b/app/Models/Role.php index c262631e60..319629e02f 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -45,14 +45,12 @@ class Role extends Model 'updated_at' => 'datetime', ]; - /** - * @var array - */ + /** @var array Fields that can be filled */ protected $fillable = ['name', 'display_name', 'description']; /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return BelongsToMany */ public function users(): BelongsToMany { diff --git a/app/Models/Rule.php b/app/Models/Rule.php index d7fbc0ba00..328ac6039d 100644 --- a/app/Models/Rule.php +++ b/app/Models/Rule.php @@ -70,14 +70,16 @@ class Rule extends Model 'id' => 'int', 'strict' => 'boolean', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['rule_group_id', 'order', 'active', 'title', 'description', 'user_id', 'strict']; /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param string $value * * @return Rule - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws NotFoundHttpException */ public static function routeBinder(string $value): Rule { diff --git a/app/Models/RuleAction.php b/app/Models/RuleAction.php index b0b7e9dcd3..0488e15806 100644 --- a/app/Models/RuleAction.php +++ b/app/Models/RuleAction.php @@ -24,6 +24,7 @@ namespace FireflyIII\Models; use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; /** * Class RuleAction. @@ -54,14 +55,14 @@ class RuleAction extends Model 'stop_processing' => 'boolean', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['rule_id', 'action_type', 'action_value', 'order', 'active', 'stop_processing']; /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ - public function rule(): \Illuminate\Database\Eloquent\Relations\BelongsTo + public function rule(): BelongsTo { return $this->belongsTo(Rule::class); } diff --git a/app/Models/RuleGroup.php b/app/Models/RuleGroup.php index bc2840175b..233ef34165 100644 --- a/app/Models/RuleGroup.php +++ b/app/Models/RuleGroup.php @@ -25,6 +25,8 @@ namespace FireflyIII\Models; use Carbon\Carbon; use FireflyIII\User; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Collection; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -60,16 +62,16 @@ class RuleGroup extends Model 'order' => 'int', ]; - /** - * @var array - */ + /** @var array Fields that can be filled */ protected $fillable = ['user_id', 'order', 'title', 'description', 'active']; /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param string $value * * @return RuleGroup - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws NotFoundHttpException */ public static function routeBinder(string $value): RuleGroup { @@ -88,18 +90,18 @@ class RuleGroup extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function rules(): \Illuminate\Database\Eloquent\Relations\HasMany + public function rules(): HasMany { return $this->hasMany(Rule::class); } /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ - public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo + public function user(): BelongsTo { return $this->belongsTo(User::class); } diff --git a/app/Models/RuleTrigger.php b/app/Models/RuleTrigger.php index 7c8da2f6e2..e2b8422251 100644 --- a/app/Models/RuleTrigger.php +++ b/app/Models/RuleTrigger.php @@ -24,6 +24,7 @@ namespace FireflyIII\Models; use Carbon\Carbon; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; /** * Class RuleTrigger. @@ -53,14 +54,14 @@ class RuleTrigger extends Model 'stop_processing' => 'boolean', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['rule_id', 'trigger_type', 'trigger_value', 'order', 'active', 'stop_processing']; /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ - public function rule(): \Illuminate\Database\Eloquent\Relations\BelongsTo + public function rule(): BelongsTo { return $this->belongsTo(Rule::class); } diff --git a/app/Models/Tag.php b/app/Models/Tag.php index f0e5c900dc..699c8991ee 100644 --- a/app/Models/Tag.php +++ b/app/Models/Tag.php @@ -25,6 +25,8 @@ namespace FireflyIII\Models; use Crypt; use FireflyIII\User; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Collection; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -60,16 +62,16 @@ class Tag extends Model 'date' => 'date', 'zoomLevel' => 'int', ]; - /** @var array */ - protected $dates = ['date']; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['user_id', 'tag', 'date', 'description', 'longitude', 'latitude', 'zoomLevel', 'tagMode']; /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param string $value * * @return Tag - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws NotFoundHttpException */ public static function routeBinder(string $value): Tag { @@ -146,18 +148,18 @@ class Tag extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return BelongsToMany */ - public function transactionJournals(): \Illuminate\Database\Eloquent\Relations\BelongsToMany + public function transactionJournals(): BelongsToMany { return $this->belongsToMany(TransactionJournal::class); } /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ - public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo + public function user(): BelongsTo { return $this->belongsTo(User::class); } diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index 2098c6788b..d20fbf8778 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -27,6 +27,7 @@ use FireflyIII\User; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\SoftDeletes; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -100,6 +101,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; */ class Transaction extends Model { + use SoftDeletes; /** * The attributes that should be casted to native types. * @@ -115,24 +117,23 @@ class Transaction extends Model 'bill_name_encrypted' => 'boolean', 'reconciled' => 'boolean', ]; - /** - * @var array - */ + /** @var array Fields that can be filled */ protected $fillable = ['account_id', 'transaction_journal_id', 'description', 'amount', 'identifier', 'transaction_currency_id', 'foreign_currency_id', 'foreign_amount', 'reconciled']; - /** - * @var array - */ + /** @var array Hidden from view */ protected $hidden = ['encrypted']; /** - * @codeCoverageIgnore + * Check if a table is joined. + * + * * * @param Builder $query * @param string $table * * @return bool + * @codeCoverageIgnore */ public static function isJoined(Builder $query, string $table): bool { @@ -150,10 +151,12 @@ class Transaction extends Model } /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param string $value * * @return Transaction - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws NotFoundHttpException */ public static function routeBinder(string $value): Transaction { @@ -171,11 +174,12 @@ class Transaction extends Model throw new NotFoundHttpException; } - use SoftDeletes; /** + * Get the account this object belongs to. + * * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ public function account(): BelongsTo { @@ -183,26 +187,32 @@ class Transaction extends Model } /** + * Get the budget(s) this object belongs to. + * * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return BelongsToMany */ - public function budgets(): \Illuminate\Database\Eloquent\Relations\BelongsToMany + public function budgets(): BelongsToMany { return $this->belongsToMany(Budget::class); } /** + * Get the category(ies) this object belongs to. + * * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return BelongsToMany */ - public function categories(): \Illuminate\Database\Eloquent\Relations\BelongsToMany + public function categories(): BelongsToMany { return $this->belongsToMany(Category::class); } /** + * Get the currency this object belongs to. + * * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ public function foreignCurrency(): BelongsTo { @@ -210,6 +220,8 @@ class Transaction extends Model } /** + * Check for transactions AFTER a specified date. + * * @codeCoverageIgnore * * @param Builder $query @@ -224,6 +236,7 @@ class Transaction extends Model } /** + * Check for transactions BEFORE the specified date. * @codeCoverageIgnore * * @param Builder $query diff --git a/app/Models/TransactionCurrency.php b/app/Models/TransactionCurrency.php index c44d6d350b..08358b492d 100644 --- a/app/Models/TransactionCurrency.php +++ b/app/Models/TransactionCurrency.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -52,16 +53,16 @@ class TransactionCurrency extends Model 'deleted_at' => 'datetime', 'decimal_places' => 'int', ]; - /** @var array */ - protected $dates = ['date']; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['name', 'code', 'symbol', 'decimal_places']; /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param string $value * * @return TransactionCurrency - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws NotFoundHttpException */ public static function routeBinder(string $value): TransactionCurrency { @@ -77,9 +78,9 @@ class TransactionCurrency extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function transactionJournals(): \Illuminate\Database\Eloquent\Relations\HasMany + public function transactionJournals(): HasMany { return $this->hasMany(TransactionJournal::class); } diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index 7eae36c4d3..ccdb49fa4c 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -28,6 +28,7 @@ use FireflyIII\User; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\MorphMany; @@ -91,15 +92,17 @@ class TransactionJournal extends Model 'completed' => 'boolean', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['user_id', 'transaction_type_id', 'bill_id', 'interest_date', 'book_date', 'process_date', 'transaction_currency_id', 'description', 'completed', 'date', 'rent_date', 'encrypted', 'tag_count',]; - /** @var array */ + /** @var array Hidden from view */ protected $hidden = ['encrypted']; /** + * Checks if tables are joined. + * * @param Builder $query * @param string $table * @@ -121,10 +124,12 @@ class TransactionJournal extends Model } /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param string $value * * @return TransactionJournal - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws NotFoundHttpException */ public static function routeBinder(string $value): TransactionJournal { @@ -154,16 +159,16 @@ class TransactionJournal extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ - public function bill(): \Illuminate\Database\Eloquent\Relations\BelongsTo + public function bill(): BelongsTo { return $this->belongsTo(Bill::class); } /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return BelongsToMany */ public function budgets(): BelongsToMany { @@ -172,7 +177,7 @@ class TransactionJournal extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return BelongsToMany */ public function categories(): BelongsToMany { @@ -259,7 +264,7 @@ class TransactionJournal extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ public function piggyBankEvents(): HasMany { @@ -333,7 +338,7 @@ class TransactionJournal extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + * @return BelongsToMany */ public function tags(): BelongsToMany { @@ -342,9 +347,9 @@ class TransactionJournal extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ - public function transactionCurrency(): \Illuminate\Database\Eloquent\Relations\BelongsTo + public function transactionCurrency(): BelongsTo { return $this->belongsTo(TransactionCurrency::class); } @@ -360,9 +365,9 @@ class TransactionJournal extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ - public function transactionType(): \Illuminate\Database\Eloquent\Relations\BelongsTo + public function transactionType(): BelongsTo { return $this->belongsTo(TransactionType::class); } @@ -378,9 +383,9 @@ class TransactionJournal extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ - public function user(): \Illuminate\Database\Eloquent\Relations\BelongsTo + public function user(): BelongsTo { return $this->belongsTo(User::class); } diff --git a/app/Models/TransactionJournalLink.php b/app/Models/TransactionJournalLink.php index 38de517ea4..92e5920f7a 100644 --- a/app/Models/TransactionJournalLink.php +++ b/app/Models/TransactionJournalLink.php @@ -45,12 +45,23 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; */ class TransactionJournalLink extends Model { - /** - * @var string - */ + /** @var string The table to store the data in */ protected $table = 'journal_links'; /** + * The attributes that should be casted to native types. + * + * @var array + */ + protected $casts + = [ + 'created_at' => 'datetime', + 'updated_at' => 'datetime', + ]; + + /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param string $value * * @return mixed @@ -76,7 +87,7 @@ class TransactionJournalLink extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ public function destination(): BelongsTo { @@ -101,7 +112,7 @@ class TransactionJournalLink extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ public function linkType(): BelongsTo { @@ -136,7 +147,7 @@ class TransactionJournalLink extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ public function source(): BelongsTo { diff --git a/app/Models/TransactionJournalMeta.php b/app/Models/TransactionJournalMeta.php index d27a7a5996..0eb222f6c3 100644 --- a/app/Models/TransactionJournalMeta.php +++ b/app/Models/TransactionJournalMeta.php @@ -49,9 +49,9 @@ class TransactionJournalMeta extends Model 'updated_at' => 'datetime', 'deleted_at' => 'datetime', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['transaction_journal_id', 'name', 'data', 'hash']; - /** @var string */ + /** @var string The table to store the data in */ protected $table = 'journal_meta'; /** @@ -80,7 +80,7 @@ class TransactionJournalMeta extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo + * @return BelongsTo */ public function transactionJournal(): BelongsTo { diff --git a/app/Models/TransactionType.php b/app/Models/TransactionType.php index f82f24769a..75c0f35b3d 100644 --- a/app/Models/TransactionType.php +++ b/app/Models/TransactionType.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -67,14 +68,16 @@ class TransactionType extends Model 'updated_at' => 'datetime', 'deleted_at' => 'datetime', ]; - /** @var array */ + /** @var array Fields that can be filled */ protected $fillable = ['type']; /** + * Route binder. Converts the key in the URL to the specified object (or throw 404). + * * @param string $type * * @return Model|null|static - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + * @throws NotFoundHttpException */ public static function routeBinder(string $type): TransactionType { @@ -126,9 +129,9 @@ class TransactionType extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\HasMany + * @return HasMany */ - public function transactionJournals(): \Illuminate\Database\Eloquent\Relations\HasMany + public function transactionJournals(): HasMany { return $this->hasMany(TransactionJournal::class); } diff --git a/app/Repositories/ExportJob/ExportJobRepository.php b/app/Repositories/ExportJob/ExportJobRepository.php index c8d50516a5..a74f7f6628 100644 --- a/app/Repositories/ExportJob/ExportJobRepository.php +++ b/app/Repositories/ExportJob/ExportJobRepository.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Repositories\ExportJob; use Carbon\Carbon; +use Exception; use FireflyIII\Models\ExportJob; use FireflyIII\User; use Illuminate\Contracts\Filesystem\FileNotFoundException; @@ -54,11 +55,10 @@ class ExportJobRepository implements ExportJobRepositoryInterface /** * @return bool - * @throws \Exception */ public function cleanup(): bool { - $dayAgo = Carbon::create()->subDay(); + $dayAgo = Carbon::now()->subDay(); $set = ExportJob::where('created_at', '<', $dayAgo->format('Y-m-d H:i:s')) ->whereIn('status', ['never_started', 'export_status_finished', 'export_downloaded']) ->get(); @@ -74,7 +74,11 @@ class ExportJobRepository implements ExportJobRepositoryInterface unlink(storage_path('export') . DIRECTORY_SEPARATOR . $file); } } - $entry->delete(); + try { + $entry->delete(); + } catch (Exception $e) { + Log::debug(sprintf('Could not delete object: %s', $e->getMessage())); + } } return true; @@ -142,8 +146,8 @@ class ExportJobRepository implements ExportJobRepositoryInterface */ public function getContent(ExportJob $job): string { - $disk = Storage::disk('export'); - $file = $job->key . '.zip'; + $disk = Storage::disk('export'); + $file = $job->key . '.zip'; try { $content = $disk->get($file); diff --git a/app/Repositories/Recurring/RecurringRepository.php b/app/Repositories/Recurring/RecurringRepository.php index 61ccbd4a79..62967a1d12 100644 --- a/app/Repositories/Recurring/RecurringRepository.php +++ b/app/Repositories/Recurring/RecurringRepository.php @@ -375,7 +375,7 @@ class RecurringRepository implements RecurringRepositoryInterface } if ('yearly' === $repetition->repetition_type) { // - $today = Carbon::create()->endOfYear(); + $today = Carbon::now()->endOfYear(); $repDate = Carbon::createFromFormat('Y-m-d', $repetition->repetition_moment); $diffInYears = $today->diffInYears($repDate); $repDate->addYears($diffInYears); // technically not necessary. diff --git a/app/Support/Import/JobConfiguration/File/ConfigureMappingHandler.php b/app/Support/Import/JobConfiguration/File/ConfigureMappingHandler.php index 568ff9d384..e8803b31b0 100644 --- a/app/Support/Import/JobConfiguration/File/ConfigureMappingHandler.php +++ b/app/Support/Import/JobConfiguration/File/ConfigureMappingHandler.php @@ -267,6 +267,7 @@ class ConfigureMappingHandler implements FileConfigurationInterface * - Add the value to the list of "values" that the user must map. * * @param Reader $reader + * @param array $config * @param array $columnConfig * * @return array diff --git a/app/Support/Import/JobConfiguration/File/NewFileJobHandler.php b/app/Support/Import/JobConfiguration/File/NewFileJobHandler.php index 047f8c5d39..6ce648d5aa 100644 --- a/app/Support/Import/JobConfiguration/File/NewFileJobHandler.php +++ b/app/Support/Import/JobConfiguration/File/NewFileJobHandler.php @@ -101,7 +101,7 @@ class NewFileJobHandler implements FileConfigurationInterface } /** - * @param ImportJob $job + * @param ImportJob $importJob */ public function setImportJob(ImportJob $importJob): void { @@ -114,7 +114,6 @@ class NewFileJobHandler implements FileConfigurationInterface /** * Store config from job. * - * @throws FireflyException */ public function storeConfiguration(): void { diff --git a/app/Support/Import/JobConfiguration/Ynab/NewYnabJobHandler.php b/app/Support/Import/JobConfiguration/Ynab/NewYnabJobHandler.php index 725bd38766..5a9ddaccda 100644 --- a/app/Support/Import/JobConfiguration/Ynab/NewYnabJobHandler.php +++ b/app/Support/Import/JobConfiguration/Ynab/NewYnabJobHandler.php @@ -87,6 +87,8 @@ class NewYnabJobHandler implements YnabJobConfigurationInterface * Get data for config view. * * @return array + * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \Psr\Container\ContainerExceptionInterface */ public function getNextData(): array { @@ -134,6 +136,8 @@ class NewYnabJobHandler implements YnabJobConfigurationInterface /** + * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \Psr\Container\ContainerExceptionInterface * @throws FireflyException */ private function getAccessToken(): void @@ -231,6 +235,8 @@ class NewYnabJobHandler implements YnabJobConfigurationInterface /** * @return bool + * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \Psr\Container\ContainerExceptionInterface */ private function hasRefreshToken(): bool { diff --git a/app/Support/Import/JobConfiguration/Ynab/SelectAccountsHandler.php b/app/Support/Import/JobConfiguration/Ynab/SelectAccountsHandler.php index 411eb78301..4dbf8fa49b 100644 --- a/app/Support/Import/JobConfiguration/Ynab/SelectAccountsHandler.php +++ b/app/Support/Import/JobConfiguration/Ynab/SelectAccountsHandler.php @@ -218,7 +218,7 @@ class SelectAccountsHandler implements YnabJobConfigurationInterface } /** - * @param int $accountId + * @param string $accountId * * @return string */ diff --git a/app/Support/Import/Routine/Bunq/StageImportDataHandler.php b/app/Support/Import/Routine/Bunq/StageImportDataHandler.php index f0067b57dd..cb3f2e2989 100644 --- a/app/Support/Import/Routine/Bunq/StageImportDataHandler.php +++ b/app/Support/Import/Routine/Bunq/StageImportDataHandler.php @@ -111,6 +111,7 @@ class StageImportDataHandler * @param LocalAccount $source * * @return array + * @throws FireflyException */ private function convertPayment(BunqPayment $payment, LocalAccount $source): array { diff --git a/app/Support/Import/Routine/Fake/StageFinalHandler.php b/app/Support/Import/Routine/Fake/StageFinalHandler.php index 23d02676ca..bb93636f90 100644 --- a/app/Support/Import/Routine/Fake/StageFinalHandler.php +++ b/app/Support/Import/Routine/Fake/StageFinalHandler.php @@ -47,7 +47,7 @@ class StageFinalHandler for ($i = 0; $i < 5; $i++) { $transaction = [ 'type' => 'withdrawal', - 'date' => Carbon::create()->format('Y-m-d'), + 'date' => Carbon::now()->format('Y-m-d'), 'tags' => '', 'user' => $this->importJob->user_id, diff --git a/app/Support/Import/Routine/File/CurrencyMapper.php b/app/Support/Import/Routine/File/CurrencyMapper.php index 21362912b5..83821c019f 100644 --- a/app/Support/Import/Routine/File/CurrencyMapper.php +++ b/app/Support/Import/Routine/File/CurrencyMapper.php @@ -71,7 +71,7 @@ class CurrencyMapper return $result; } } - if (!isset($data['code']) || null === $data['code']) { + if (!isset($data['code'])) { return null; } diff --git a/app/Support/Import/Routine/File/ImportableConverter.php b/app/Support/Import/Routine/File/ImportableConverter.php index 43445e96e6..d4a90fc9d8 100644 --- a/app/Support/Import/Routine/File/ImportableConverter.php +++ b/app/Support/Import/Routine/File/ImportableConverter.php @@ -212,7 +212,7 @@ class ImportableConverter return [ 'type' => $transactionType, - 'date' => $this->convertDateValue($importable->date) ?? Carbon::create()->format('Y-m-d'), + 'date' => $this->convertDateValue($importable->date) ?? Carbon::now()->format('Y-m-d'), 'tags' => $importable->tags, 'user' => $this->importJob->user_id, 'notes' => $importable->note, diff --git a/app/Support/Import/Routine/Ynab/ImportDataHandler.php b/app/Support/Import/Routine/Ynab/ImportDataHandler.php index f8edcac2e2..c6e4c0976c 100644 --- a/app/Support/Import/Routine/Ynab/ImportDataHandler.php +++ b/app/Support/Import/Routine/Ynab/ImportDataHandler.php @@ -64,7 +64,7 @@ class ImportDataHandler /** * @var string $ynabId - * @var int $localId + * @var string $localId */ foreach ($mapping as $ynabId => $localId) { $localAccount = $this->getLocalAccount((int)$localId); @@ -252,7 +252,6 @@ class ImportDataHandler /** * @param string $token - * @param string $budget * @param string $account * * @return array diff --git a/app/Support/Import/Routine/Ynab/StageGetAccessHandler.php b/app/Support/Import/Routine/Ynab/StageGetAccessHandler.php index 489a75766d..4c91d1abac 100644 --- a/app/Support/Import/Routine/Ynab/StageGetAccessHandler.php +++ b/app/Support/Import/Routine/Ynab/StageGetAccessHandler.php @@ -45,6 +45,8 @@ class StageGetAccessHandler /** * Send a token request to YNAB. Return with access token (if all goes well). * + * @throws \Psr\Container\NotFoundExceptionInterface + * @throws \Psr\Container\ContainerExceptionInterface * @throws FireflyException */ public function run(): void diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php index a7f3690562..b94901dcd1 100644 --- a/app/Support/Preferences.php +++ b/app/Support/Preferences.php @@ -171,10 +171,7 @@ class Preferences if (\is_array($lastActivity)) { $lastActivity = implode(',', $lastActivity); } - $hash = md5($lastActivity); - //Log::debug(sprintf('Value of last activity is %s, hash is %s', $lastActivity, $hash)); - - return $hash; + return md5($lastActivity); } /** diff --git a/app/Support/Search/Search.php b/app/Support/Search/Search.php index cc1e884954..85fb5ccf48 100644 --- a/app/Support/Search/Search.php +++ b/app/Support/Search/Search.php @@ -246,7 +246,7 @@ class Search implements SearchInterface private function extractModifier(string $string): void { $parts = explode(':', $string); - if (2 === \count($parts) && \strlen(trim((string)$parts[0])) > 0 && '' !== trim((string)$parts[1])) { + if (2 === \count($parts) && '' !== trim((string)$parts[1]) && \strlen(trim((string)$parts[0])) > 0) { $type = trim((string)$parts[0]); $value = trim((string)$parts[1]); if (\in_array($type, $this->validModifiers, true)) { diff --git a/app/Support/Twig/AmountFormat.php b/app/Support/Twig/AmountFormat.php index 52a7554885..9992740d8e 100644 --- a/app/Support/Twig/AmountFormat.php +++ b/app/Support/Twig/AmountFormat.php @@ -132,6 +132,7 @@ class AmountFormat extends Twig_Extension { return new Twig_SimpleFunction( 'formatAmountBySymbol', + /** @noinspection MoreThanThreeArgumentsInspection */ function (string $amount, string $symbol, int $decimalPlaces = null, bool $coloured = null): string { $decimalPlaces = $decimalPlaces ?? 2; $coloured = $coloured ?? true; diff --git a/app/Support/Twig/Extension/TransactionJournal.php b/app/Support/Twig/Extension/TransactionJournal.php index 32bfa25f3a..4c8f69ff96 100644 --- a/app/Support/Twig/Extension/TransactionJournal.php +++ b/app/Support/Twig/Extension/TransactionJournal.php @@ -136,7 +136,7 @@ class TransactionJournal extends Twig_Extension /** * @param JournalModel $journal * - * @return string + * @return array */ private function getTotalAmount(JournalModel $journal): array { diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.php index a92de4be5c..804378ffe2 100644 --- a/app/Support/Twig/General.php +++ b/app/Support/Twig/General.php @@ -103,9 +103,7 @@ class General extends Twig_Extension return new Twig_SimpleFunction( 'activeRoutePartialWhat', function ($context): string { - $args = \func_get_args(); - $route = $args[1]; // name of the route. - $what = $args[2]; // name of the route. + [, $route, $what] = \func_get_args(); $activeWhat = $context['what'] ?? false; if ($what === $activeWhat && !(false === stripos(Route::getCurrentRoute()->getName(), $route))) { diff --git a/app/User.php b/app/User.php index c8ff6c43c6..442c9fb290 100644 --- a/app/User.php +++ b/app/User.php @@ -302,7 +302,7 @@ class User extends Authenticatable * * @param string $token */ - public function sendPasswordResetNotification($token) + public function sendPasswordResetNotification($token): void { $ipAddress = Request::ip(); diff --git a/app/Validation/TransactionValidation.php b/app/Validation/TransactionValidation.php index 0c874afd03..1d42ead1bf 100644 --- a/app/Validation/TransactionValidation.php +++ b/app/Validation/TransactionValidation.php @@ -112,10 +112,10 @@ trait TransactionValidation { $data = $validator->getData(); $transactions = $data['transactions'] ?? []; - $journalDescription = (string)($data['description'] ?? ''); + $journalDescription = (string)($data['description'] ?? null); $validDescriptions = 0; foreach ($transactions as $index => $transaction) { - if (\strlen((string)($transaction['description'] ?? '')) > 0) { + if (\strlen((string)($transaction['description'] ?? null)) > 0) { $validDescriptions++; } } @@ -157,9 +157,9 @@ trait TransactionValidation { $data = $validator->getData(); $transactions = $data['transactions'] ?? []; - $journalDescription = (string)($data['description'] ?? ''); + $journalDescription = (string)($data['description'] ?? null); foreach ($transactions as $index => $transaction) { - $description = (string)($transaction['description'] ?? ''); + $description = (string)($transaction['description'] ?? null); // description cannot be equal to journal description. if ($description === $journalDescription) { $validator->errors()->add('transactions.' . $index . '.description', (string)trans('validation.equal_description')); @@ -249,7 +249,7 @@ trait TransactionValidation $data = $validator->getData(); $transactions = $data['transactions'] ?? []; foreach ($transactions as $index => $transaction) { - $description = (string)($transaction['description'] ?? ''); + $description = (string)($transaction['description'] ?? null); // filled description is mandatory for split transactions. if ('' === $description && \count($transactions) > 1) { $validator->errors()->add( diff --git a/resources/lang/en_US/validation.php b/resources/lang/en_US/validation.php index 58266f14c9..ad42c3d7ae 100644 --- a/resources/lang/en_US/validation.php +++ b/resources/lang/en_US/validation.php @@ -50,7 +50,7 @@ return [ 'at_least_one_action' => 'Rule must have at least one action.', 'base64' => 'This is not valid base64 encoded data.', 'model_id_invalid' => 'The given ID seems invalid for this model.', - 'more' => ':attribute must be larger than :value.', + 'more' => ':attribute must be larger than zero.', 'less' => ':attribute must be less than 10,000,000', 'active_url' => 'The :attribute is not a valid URL.', 'after' => 'The :attribute must be a date after :date.', diff --git a/resources/views/form/amount-no-currency.twig b/resources/views/form/amount-no-currency.twig index 005be0f54a..a5b2d39ba9 100644 --- a/resources/views/form/amount-no-currency.twig +++ b/resources/views/form/amount-no-currency.twig @@ -2,6 +2,7 @@
{{ Form.input('number', name, value, options) }} + {% include 'form/help' %} {% include 'form/feedback' %}
diff --git a/resources/views/form/number.twig b/resources/views/form/number.twig index 6951b19328..54be537886 100644 --- a/resources/views/form/number.twig +++ b/resources/views/form/number.twig @@ -3,6 +3,7 @@
{{ Form.input('number', name, value, options) }} + {% include 'form/help' %} {% include 'form/feedback' %}
diff --git a/resources/views/transactions/show.twig b/resources/views/transactions/show.twig index f63a467f28..f13da933a1 100644 --- a/resources/views/transactions/show.twig +++ b/resources/views/transactions/show.twig @@ -426,8 +426,8 @@