From 5908c0ce8c9be3f300e46e2ed4be3057c577b7c0 Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 6 Aug 2018 19:14:30 +0200 Subject: [PATCH] Code cleanup and realign. --- .../V1/Controllers/BudgetLimitController.php | 1 - .../Controllers/ConfigurationController.php | 1 + app/Console/Commands/Import.php | 2 +- app/Console/Commands/ScanAttachments.php | 1 + .../Commands/UpgradeFireflyInstructions.php | 1 + app/Console/Commands/UseEncryption.php | 1 + app/Events/RequestedNewPassword.php | 4 +- app/Export/Collector/AttachmentCollector.php | 3 +- app/Export/ExpandedProcessor.php | 8 +- app/Factory/TransactionJournalFactory.php | 2 +- .../Report/Budget/MonthReportGenerator.php | 11 +- .../Report/Tag/MonthReportGenerator.php | 5 +- .../Events/VersionCheckEventHandler.php | 6 +- app/Helpers/Attachments/AttachmentHelper.php | 3 +- app/Helpers/Report/BalanceReportHelper.php | 1 + .../Controllers/Account/CreateController.php | 2 +- .../Account/ReconcileController.php | 2 +- .../Controllers/Account/ShowController.php | 2 +- app/Http/Controllers/Admin/LinkController.php | 1 + app/Http/Controllers/BillController.php | 4 - .../Controllers/Budget/IndexController.php | 6 +- .../Controllers/Budget/ShowController.php | 2 +- .../Category/NoCategoryController.php | 1 - .../Controllers/Chart/AccountController.php | 3 + app/Http/Controllers/Chart/BillController.php | 3 +- .../Controllers/Chart/BudgetController.php | 4 +- app/Http/Controllers/Controller.php | 1 + app/Http/Controllers/ExportController.php | 2 +- app/Http/Controllers/HomeController.php | 4 +- app/Http/Controllers/JavascriptController.php | 14 +- app/Http/Controllers/Json/BoxController.php | 2 +- .../Controllers/Popup/ReportController.php | 5 +- app/Http/Controllers/ProfileController.php | 2 + .../Recurring/CreateController.php | 2 +- .../Controllers/Recurring/EditController.php | 2 +- .../Controllers/Rule/CreateController.php | 4 - app/Http/Controllers/Rule/IndexController.php | 2 +- .../Controllers/System/InstallController.php | 1 + .../Transaction/LinkController.php | 1 + .../Controllers/TransactionController.php | 12 +- app/Http/Middleware/TrustProxies.php | 2 +- app/Http/Requests/AccountFormRequest.php | 2 +- app/Http/Requests/JournalFormRequest.php | 4 +- app/Http/Requests/RecurrenceFormRequest.php | 2 +- app/Http/Requests/Request.php | 3 +- app/Http/Requests/RuleFormRequest.php | 5 +- app/Import/Mapper/OpposingAccountIbans.php | 1 + .../Prerequisites/BunqPrerequisites.php | 4 +- app/Import/Routine/YnabRoutine.php | 43 ++-- app/Jobs/CreateRecurringTransactions.php | 3 +- app/Models/AccountType.php | 50 ++--- app/Models/Attachment.php | 2 +- app/Models/AvailableBudget.php | 2 +- app/Models/Bill.php | 4 +- app/Models/Budget.php | 4 +- app/Models/BudgetLimit.php | 2 +- app/Models/Category.php | 4 +- app/Models/CurrencyExchangeRate.php | 4 +- app/Models/ImportJob.php | 9 +- app/Models/PiggyBank.php | 2 +- app/Models/PiggyBankEvent.php | 2 +- app/Models/Preference.php | 4 +- app/Models/Recurrence.php | 2 +- app/Models/RecurrenceRepetition.php | 2 +- app/Models/RecurrenceTransactionMeta.php | 2 +- app/Models/Rule.php | 2 +- app/Models/RuleGroup.php | 4 +- app/Models/Transaction.php | 1 + app/Models/TransactionCurrency.php | 2 +- app/Models/TransactionJournal.php | 4 +- app/Models/TransactionJournalLink.php | 9 +- app/Providers/AppServiceProvider.php | 3 +- .../Account/AccountRepository.php | 4 + .../AttachmentRepositoryInterface.php | 1 + app/Repositories/Bill/BillRepository.php | 2 +- .../ExportJob/ExportJobRepository.php | 3 +- .../ExportJobRepositoryInterface.php | 1 + .../ImportJob/ImportJobRepository.php | 1 + .../ImportJobRepositoryInterface.php | 1 + .../Journal/JournalRepository.php | 2 + .../Journal/JournalRepositoryInterface.php | 1 - .../Tag/TagRepositoryInterface.php | 2 +- app/Services/Currency/FixerIOv2.php | 2 +- app/Services/Github/Request/UpdateRequest.php | 2 +- app/Services/IP/IpifyOrg.php | 4 +- .../Internal/Support/AccountServiceTrait.php | 2 +- .../Internal/Support/TransactionTypeTrait.php | 1 + .../Internal/Update/BillUpdateService.php | 2 +- .../Update/RecurrenceUpdateService.php | 3 +- app/Services/Password/PwndVerifierV2.php | 2 +- app/Services/Spectre/Object/Attempt.php | 1 + app/Services/Spectre/Object/Login.php | 1 + app/Services/Spectre/Object/Transaction.php | 1 + .../Spectre/Request/NewCustomerRequest.php | 5 +- .../Spectre/Request/SpectreRequest.php | 4 +- app/Support/Amount.php | 6 +- .../Ynab/SelectBudgetHandler.php | 2 +- .../Ynab/YnabJobConfigurationInterface.php | 1 + .../Routine/File/ImportableConverter.php | 1 + .../Import/Routine/Ynab/ImportDataHandler.php | 2 +- .../Routine/Ynab/StageGetAccessHandler.php | 6 +- .../Routine/Ynab/StageGetBudgetsHandler.php | 2 +- app/Support/Preferences.php | 1 + app/Support/Twig/General.php | 3 +- app/Support/Twig/Translation.php | 1 - app/TransactionRules/Processor.php | 2 +- app/TransactionRules/TransactionMatcher.php | 6 +- app/Transformers/AccountTransformer.php | 8 +- app/Transformers/BudgetTransformer.php | 2 +- .../CurrencyExchangeRateTransformer.php | 8 + .../PiggyBankEventTransformer.php | 4 +- app/Transformers/PiggyBankTransformer.php | 2 +- app/Transformers/PreferenceTransformer.php | 8 + app/Transformers/TagTransformer.php | 2 +- app/Transformers/UserTransformer.php | 2 +- app/User.php | 4 +- app/Validation/FireflyValidator.php | 72 +------ app/Validation/RecurrenceValidation.php | 68 +++--- app/Validation/TransactionValidation.php | 4 +- routes/web.php | 1 - .../AvailableBudgetControllerTest.php | 2 +- .../Api/V1/Controllers/BillControllerTest.php | 1 + .../Controllers/BudgetLimitControllerTest.php | 8 +- .../V1/Controllers/CurrencyControllerTest.php | 3 +- .../CurrencyExchangeRateControllerTest.php | 68 +++--- .../Controllers/RecurrenceControllerTest.php | 200 +++++++++--------- .../Account/CreateControllerTest.php | 1 - .../Account/DeleteControllerTest.php | 4 +- .../Account/EditControllerTest.php | 5 +- .../Account/ReconcileControllerTest.php | 4 +- .../Account/ShowControllerTest.php | 4 +- .../Admin/UpdateControllerTest.php | 4 +- .../Controllers/Admin/UserControllerTest.php | 2 +- .../Controllers/AttachmentControllerTest.php | 2 +- .../Auth/TwoFactorControllerTest.php | 4 +- .../Controllers/BillControllerTest.php | 171 ++++++++------- .../Category/ShowControllerTest.php | 9 +- .../Controllers/CurrencyControllerTest.php | 3 +- .../Controllers/HomeControllerTest.php | 14 +- .../Import/IndexControllerTest.php | 1 - .../Controllers/JavascriptControllerTest.php | 45 ++-- .../Json/AutoCompleteControllerTest.php | 33 ++- .../Controllers/Json/BoxControllerTest.php | 30 +-- .../Controllers/ProfileControllerTest.php | 8 +- .../Controllers/Rule/CreateControllerTest.php | 1 - .../Transaction/BulkControllerTest.php | 52 ++--- .../Transaction/LinkControllerTest.php | 58 +++-- .../Transaction/MassControllerTest.php | 4 +- .../Transaction/SingleControllerTest.php | 2 - .../Transaction/SplitControllerTest.php | 73 +++---- .../Controllers/TransactionControllerTest.php | 14 +- tests/Object/FakeApiContext.php | 3 +- tests/TestCase.php | 1 - tests/Unit/Factory/AccountFactoryTest.php | 100 ++++----- .../TransactionCurrencyFactoryTest.php | 28 +-- tests/Unit/Factory/TransactionFactoryTest.php | 6 +- .../TransactionJournalMetaFactoryTest.php | 4 +- .../Import/Converter/AmountCreditTest.php | 2 +- .../Import/Routine/SpectreRoutineTest.php | 64 +++--- .../Specifics/AbnAmroDescriptionTest.php | 20 +- .../Import/Specifics/IngDescriptionTest.php | 97 ++++----- .../Import/Specifics/PresidentsChoiceTest.php | 30 +-- .../Import/Storage/ImportArrayStorageTest.php | 3 - tests/Unit/Middleware/AuthenticateTest.php | 3 +- tests/Unit/Middleware/BinderTest.php | 2 +- tests/Unit/Middleware/IsDemoUserTest.php | 18 +- tests/Unit/Middleware/SandstormTest.php | 2 +- .../Update/TransactionUpdateServiceTest.php | 5 +- .../Bunq/ChooseAccountsHandlerTest.php | 4 +- .../Bunq/NewBunqJobHandlerTest.php | 1 - .../Spectre/DoAuthenticateHandlerTest.php | 1 + .../Routine/File/CurrencyMapperTest.php | 86 ++++---- .../Routine/File/ImportableCreatorTest.php | 8 +- .../Routine/File/MappingConvergerTest.php | 4 +- .../File/OpposingAccountMapperTest.php | 50 ++--- .../Actions/ClearBudgetTest.php | 2 +- .../Actions/ClearCategoryTest.php | 2 +- .../Triggers/BudgetIsTest.php | 4 +- .../Triggers/FromAccountEndsTest.php | 12 +- .../Triggers/FromAccountIsTest.php | 14 +- .../Triggers/FromAccountStartsTest.php | 12 +- .../Triggers/HasAttachmentTest.php | 10 +- .../Triggers/HasNoBudgetTest.php | 4 +- .../Triggers/ToAccountContainsTest.php | 12 +- .../Triggers/ToAccountEndsTest.php | 1 - .../Triggers/ToAccountIsTest.php | 14 +- .../Triggers/ToAccountStartsTest.php | 1 - .../Unit/Transformers/BillTransformerTest.php | 1 - 188 files changed, 1019 insertions(+), 1031 deletions(-) diff --git a/app/Api/V1/Controllers/BudgetLimitController.php b/app/Api/V1/Controllers/BudgetLimitController.php index 16cf1d095a..99127989cb 100644 --- a/app/Api/V1/Controllers/BudgetLimitController.php +++ b/app/Api/V1/Controllers/BudgetLimitController.php @@ -34,7 +34,6 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Collection; - use League\Fractal\Manager; use League\Fractal\Pagination\IlluminatePaginatorAdapter; use League\Fractal\Resource\Collection as FractalCollection; diff --git a/app/Api/V1/Controllers/ConfigurationController.php b/app/Api/V1/Controllers/ConfigurationController.php index aee513f7cb..c21b430b0c 100644 --- a/app/Api/V1/Controllers/ConfigurationController.php +++ b/app/Api/V1/Controllers/ConfigurationController.php @@ -54,6 +54,7 @@ class ConfigurationController extends Controller $admin = auth()->user(); if (!$this->repository->hasRole($admin, 'owner')) { + /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ throw new FireflyException('No access to method.'); // @codeCoverageIgnore } diff --git a/app/Console/Commands/Import.php b/app/Console/Commands/Import.php index 0f952e6af3..b7572cf061 100644 --- a/app/Console/Commands/Import.php +++ b/app/Console/Commands/Import.php @@ -64,7 +64,7 @@ class Import extends Command Log::debug('Start start-import command'); $jobKey = (string)$this->argument('key'); /** @var ImportJob $job */ - $job = ImportJob::where('key', $jobKey)->first(); + $job = ImportJob::where('key', $jobKey)->first(); if (null === $job) { $this->errorLine(sprintf('No job found with key "%s"', $jobKey)); diff --git a/app/Console/Commands/ScanAttachments.php b/app/Console/Commands/ScanAttachments.php index 0a77363a0a..cd76aa9377 100644 --- a/app/Console/Commands/ScanAttachments.php +++ b/app/Console/Commands/ScanAttachments.php @@ -82,6 +82,7 @@ class ScanAttachments extends Command $attachment->save(); $this->line(sprintf('Fixed attachment #%d', $attachment->id)); } + return 0; } } diff --git a/app/Console/Commands/UpgradeFireflyInstructions.php b/app/Console/Commands/UpgradeFireflyInstructions.php index d2e4730204..9aa8f33a1e 100644 --- a/app/Console/Commands/UpgradeFireflyInstructions.php +++ b/app/Console/Commands/UpgradeFireflyInstructions.php @@ -54,6 +54,7 @@ class UpgradeFireflyInstructions extends Command if ('install' === (string)$this->argument('task')) { $this->installInstructions(); } + return 0; } diff --git a/app/Console/Commands/UseEncryption.php b/app/Console/Commands/UseEncryption.php index bfc04db91c..7a67d71cf6 100644 --- a/app/Console/Commands/UseEncryption.php +++ b/app/Console/Commands/UseEncryption.php @@ -62,6 +62,7 @@ class UseEncryption extends Command $this->handleObjects('Category', 'name', 'encrypted'); $this->handleObjects('PiggyBank', 'name', 'encrypted'); $this->handleObjects('TransactionJournal', 'description', 'encrypted'); + return 0; } diff --git a/app/Events/RequestedNewPassword.php b/app/Events/RequestedNewPassword.php index 4452a8dfeb..ffd13ee344 100644 --- a/app/Events/RequestedNewPassword.php +++ b/app/Events/RequestedNewPassword.php @@ -36,10 +36,10 @@ class RequestedNewPassword extends Event /** @var string The users IP address */ public $ipAddress; - /** @var User The user */ - public $user; /** @var string The token */ public $token; + /** @var User The user */ + public $user; /** * Create a new event instance. This event is triggered when a users tries to reset his or her password. diff --git a/app/Export/Collector/AttachmentCollector.php b/app/Export/Collector/AttachmentCollector.php index 9eecde245b..49e8b1e20a 100644 --- a/app/Export/Collector/AttachmentCollector.php +++ b/app/Export/Collector/AttachmentCollector.php @@ -28,7 +28,6 @@ use Crypt; use FireflyIII\Models\Attachment; use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface; use Illuminate\Contracts\Encryption\DecryptException; -use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Support\Collection; use Log; use Storage; @@ -108,7 +107,7 @@ class AttachmentCollector extends BasicCollector implements CollectorInterface if ($this->uploadDisk->exists($file)) { try { $decrypted = Crypt::decrypt($this->uploadDisk->get($file)); - } catch (FileNotFoundException|DecryptException $e) { + } catch (DecryptException $e) { Log::error('Catchable error: could not decrypt attachment #' . $attachment->id . ' because: ' . $e->getMessage()); return false; diff --git a/app/Export/ExpandedProcessor.php b/app/Export/ExpandedProcessor.php index 27fdc83822..2c15573719 100644 --- a/app/Export/ExpandedProcessor.php +++ b/app/Export/ExpandedProcessor.php @@ -54,7 +54,7 @@ class ExpandedProcessor implements ProcessorInterface { /** @var Collection All accounts */ public $accounts; - /** @var string The export format*/ + /** @var string The export format */ public $exportFormat; /** @var bool Should include attachments */ public $includeAttachments; @@ -62,7 +62,7 @@ class ExpandedProcessor implements ProcessorInterface public $includeOldUploads; /** @var ExportJob The export job itself */ public $job; - /** @var array The settings*/ + /** @var array The settings */ public $settings; /** @var Collection The entries to export. */ private $exportEntries; @@ -222,7 +222,7 @@ class ExpandedProcessor implements ProcessorInterface { $exporterClass = config('firefly.export_formats.' . $this->exportFormat); /** @var ExporterInterface $exporter */ - $exporter = app($exporterClass); + $exporter = app($exporterClass); $exporter->setJob($this->job); $exporter->setEntries($this->exportEntries); $exporter->run(); @@ -260,7 +260,7 @@ class ExpandedProcessor implements ProcessorInterface /** * Delete files. */ - private function deleteFiles():void + private function deleteFiles(): void { $disk = Storage::disk('export'); foreach ($this->getFiles() as $file) { diff --git a/app/Factory/TransactionJournalFactory.php b/app/Factory/TransactionJournalFactory.php index 9096d8099d..1dbd565934 100644 --- a/app/Factory/TransactionJournalFactory.php +++ b/app/Factory/TransactionJournalFactory.php @@ -104,7 +104,7 @@ class TransactionJournalFactory // store date meta fields (if present): $fields = ['sepa-cc', 'sepa-ct-op', 'sepa-ct-id', 'sepa-db', 'sepa-country', 'sepa-ep', 'sepa-ci', 'interest_date', 'book_date', 'process_date', 'due_date', 'recurrence_id', 'payment_date', 'invoice_date', 'internal_reference', 'bunq_payment_id', 'importHash', 'importHashV2', - 'external_id','sepa-batch-id']; + 'external_id', 'sepa-batch-id']; foreach ($fields as $field) { $this->storeMeta($journal, $data, $field); diff --git a/app/Generator/Report/Budget/MonthReportGenerator.php b/app/Generator/Report/Budget/MonthReportGenerator.php index 39aaf1696e..f613fd8f84 100644 --- a/app/Generator/Report/Budget/MonthReportGenerator.php +++ b/app/Generator/Report/Budget/MonthReportGenerator.php @@ -78,15 +78,16 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface // render! 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(); + $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/Tag/MonthReportGenerator.php b/app/Generator/Report/Tag/MonthReportGenerator.php index 84532e19f1..1b1294583c 100644 --- a/app/Generator/Report/Tag/MonthReportGenerator.php +++ b/app/Generator/Report/Tag/MonthReportGenerator.php @@ -90,8 +90,9 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface try { $result = view( 'reports.tag.month', compact( - 'accountIds', 'tagTags', 'reportType', 'accountSummary', 'tagSummary', 'averageExpenses', 'averageIncome', 'topIncome', 'topExpenses' - ) + '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(); } catch (Throwable $e) { Log::error(sprintf('Cannot render reports.tag.month: %s', $e->getMessage())); diff --git a/app/Handlers/Events/VersionCheckEventHandler.php b/app/Handlers/Events/VersionCheckEventHandler.php index 46b371772e..6213a10f8c 100644 --- a/app/Handlers/Events/VersionCheckEventHandler.php +++ b/app/Handlers/Events/VersionCheckEventHandler.php @@ -27,14 +27,12 @@ namespace FireflyIII\Handlers\Events; use FireflyConfig; use FireflyIII\Events\RequestedVersionCheckStatus; - use FireflyIII\Helpers\Update\UpdateTrait; use FireflyIII\Repositories\User\UserRepositoryInterface; - - use FireflyIII\User; use Log; + /** * Class VersionCheckEventHandler */ @@ -81,7 +79,7 @@ class VersionCheckEventHandler $latestRelease = $this->getLatestRelease(); $versionCheck = $this->versionCheck($latestRelease); - $resultString = $this->parseResult($versionCheck, $latestRelease); + $resultString = $this->parseResult($versionCheck, $latestRelease); if (0 !== $versionCheck && '' !== $resultString) { // flash info session()->flash('info', $resultString); diff --git a/app/Helpers/Attachments/AttachmentHelper.php b/app/Helpers/Attachments/AttachmentHelper.php index d840a2a812..8714dfec07 100644 --- a/app/Helpers/Attachments/AttachmentHelper.php +++ b/app/Helpers/Attachments/AttachmentHelper.php @@ -25,7 +25,6 @@ namespace FireflyIII\Helpers\Attachments; use Crypt; use FireflyIII\Models\Attachment; use Illuminate\Contracts\Encryption\DecryptException; -use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection; use Illuminate\Support\MessageBag; @@ -80,7 +79,7 @@ class AttachmentHelper implements AttachmentHelperInterface try { $content = Crypt::decrypt($this->uploadDisk->get(sprintf('at-%d.data', $attachment->id))); - } catch (DecryptException|FileNotFoundException $e) { + } catch (DecryptException $e) { Log::error(sprintf('Could not decrypt data of attachment #%d: %s', $attachment->id, $e->getMessage())); $content = ''; } diff --git a/app/Helpers/Report/BalanceReportHelper.php b/app/Helpers/Report/BalanceReportHelper.php index 1daec53c1c..c2d807f530 100644 --- a/app/Helpers/Report/BalanceReportHelper.php +++ b/app/Helpers/Report/BalanceReportHelper.php @@ -160,6 +160,7 @@ class BalanceReportHelper implements BalanceReportHelperInterface { $set = $balance->getBalanceLines(); $newSet = new Collection; + /** @var BalanceLine $entry */ foreach ($set as $entry) { if (null !== $entry->getBudget()->id) { $sum = '0'; diff --git a/app/Http/Controllers/Account/CreateController.php b/app/Http/Controllers/Account/CreateController.php index f78ac9e166..38feabb864 100644 --- a/app/Http/Controllers/Account/CreateController.php +++ b/app/Http/Controllers/Account/CreateController.php @@ -107,7 +107,7 @@ class CreateController extends Controller } $request->session()->forget('accounts.create.fromStore'); - return view('accounts.create', compact('subTitleIcon', 'what','interestPeriods', 'subTitle', 'roles', 'liabilityTypes')); + return view('accounts.create', compact('subTitleIcon', 'what', 'interestPeriods', 'subTitle', 'roles', 'liabilityTypes')); } diff --git a/app/Http/Controllers/Account/ReconcileController.php b/app/Http/Controllers/Account/ReconcileController.php index 99c3ab623c..6e2e04fd09 100644 --- a/app/Http/Controllers/Account/ReconcileController.php +++ b/app/Http/Controllers/Account/ReconcileController.php @@ -147,7 +147,7 @@ class ReconcileController extends Controller /** @var Carbon $start */ $start = clone session('start', app('navigation')->startOfPeriod(new Carbon, $range)); /** @var Carbon $end */ - $end = clone session('end', app('navigation')->endOfPeriod(new Carbon, $range)); + $end = clone session('end', app('navigation')->endOfPeriod(new Carbon, $range)); } if (null === $end) { /** @var Carbon $end */ diff --git a/app/Http/Controllers/Account/ShowController.php b/app/Http/Controllers/Account/ShowController.php index a5273323c4..e5a08761c9 100644 --- a/app/Http/Controllers/Account/ShowController.php +++ b/app/Http/Controllers/Account/ShowController.php @@ -93,7 +93,7 @@ class ShowController extends Controller /** @var Carbon $start */ $start = $start ?? session('start'); /** @var Carbon $end */ - $end = $end ?? session('end'); + $end = $end ?? session('end'); if ($end < $start) { throw new FireflyException('End is after start!'); // @codeCoverageIgnore } diff --git a/app/Http/Controllers/Admin/LinkController.php b/app/Http/Controllers/Admin/LinkController.php index fd877c1e5d..b16db6a4de 100644 --- a/app/Http/Controllers/Admin/LinkController.php +++ b/app/Http/Controllers/Admin/LinkController.php @@ -55,6 +55,7 @@ class LinkController extends Controller /** * Make a new link form. + * * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View */ public function create() diff --git a/app/Http/Controllers/BillController.php b/app/Http/Controllers/BillController.php index efc6dfb0b5..767d9cea49 100644 --- a/app/Http/Controllers/BillController.php +++ b/app/Http/Controllers/BillController.php @@ -28,7 +28,6 @@ use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Http\Requests\BillFormRequest; use FireflyIII\Models\Bill; use FireflyIII\Repositories\Bill\BillRepositoryInterface; -use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; use FireflyIII\TransactionRules\TransactionMatcher; use FireflyIII\Transformers\BillTransformer; use Illuminate\Http\RedirectResponse; @@ -51,8 +50,6 @@ class BillController extends Controller private $attachments; /** @var BillRepositoryInterface Bill repository */ private $billRepository; - /** @var RuleGroupRepositoryInterface Rule group repository */ - private $ruleGroupRepos; /** * BillController constructor. @@ -72,7 +69,6 @@ class BillController extends Controller app('view')->share('mainTitleIcon', 'fa-calendar-o'); $this->attachments = app(AttachmentHelperInterface::class); $this->billRepository = app(BillRepositoryInterface::class); - $this->ruleGroupRepos = app(RuleGroupRepositoryInterface::class); return $next($request); } diff --git a/app/Http/Controllers/Budget/IndexController.php b/app/Http/Controllers/Budget/IndexController.php index f23cd4f159..726a730356 100644 --- a/app/Http/Controllers/Budget/IndexController.php +++ b/app/Http/Controllers/Budget/IndexController.php @@ -78,9 +78,9 @@ class IndexController extends Controller public function index(Request $request, string $moment = null) { /** @var string $range */ - $range = app('preferences')->get('viewRange', '1M')->data; + $range = app('preferences')->get('viewRange', '1M')->data; /** @var Carbon $start */ - $start = session('start', new Carbon); + $start = session('start', new Carbon); /** @var Carbon $end */ $end = session('end', new Carbon); $page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page'); @@ -92,7 +92,7 @@ class IndexController extends Controller try { $start = new Carbon($moment); /** @var Carbon $end */ - $end = app('navigation')->endOfPeriod($start, $range); + $end = app('navigation')->endOfPeriod($start, $range); } catch (Exception $e) { // start and end are already defined. Log::debug(sprintf('start and end are already defined: %s', $e->getMessage())); diff --git a/app/Http/Controllers/Budget/ShowController.php b/app/Http/Controllers/Budget/ShowController.php index 3e81b43390..d9ff4999f5 100644 --- a/app/Http/Controllers/Budget/ShowController.php +++ b/app/Http/Controllers/Budget/ShowController.php @@ -127,7 +127,7 @@ class ShowController extends Controller $transactions = $collector->getPaginatedJournals(); $transactions->setPath(route('budgets.no-budget')); - return view('budgets.no-budget', compact('transactions', 'subTitle', 'moment', 'start', 'end')); + return view('budgets.no-budget', compact('transactions', 'subTitle', 'moment', 'start', 'end')); } diff --git a/app/Http/Controllers/Category/NoCategoryController.php b/app/Http/Controllers/Category/NoCategoryController.php index 59b03f4a1f..720befb907 100644 --- a/app/Http/Controllers/Category/NoCategoryController.php +++ b/app/Http/Controllers/Category/NoCategoryController.php @@ -29,7 +29,6 @@ use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Helpers\Filter\InternalTransferFilter; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\TransactionType; - use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Support\CacheProperties; use Illuminate\Http\Request; diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php index 124cc00da6..d05ca1dc5e 100644 --- a/app/Http/Controllers/Chart/AccountController.php +++ b/app/Http/Controllers/Chart/AccountController.php @@ -129,6 +129,7 @@ class AccountController extends Controller if ($cache->has()) { return response()->json($cache->get()); // @codeCoverageIgnore } + /** @var JournalCollectorInterface $collector */ $collector = app(JournalCollectorInterface::class); $collector->setAccounts(new Collection([$account]))->setRange($start, $end)->withBudgetInformation()->setTypes([TransactionType::WITHDRAWAL]); $transactions = $collector->getJournals(); @@ -192,6 +193,7 @@ class AccountController extends Controller return response()->json($cache->get()); // @codeCoverageIgnore } + /** @var JournalCollectorInterface $collector */ $collector = app(JournalCollectorInterface::class); $collector->setAccounts(new Collection([$account]))->setRange($start, $end)->withCategoryInformation()->setTypes([TransactionType::WITHDRAWAL]); $transactions = $collector->getJournals(); @@ -283,6 +285,7 @@ class AccountController extends Controller } // grab all journals: + /** @var JournalCollectorInterface $collector */ $collector = app(JournalCollectorInterface::class); $collector->setAccounts(new Collection([$account]))->setRange($start, $end)->withCategoryInformation()->setTypes([TransactionType::DEPOSIT]); $transactions = $collector->getJournals(); diff --git a/app/Http/Controllers/Chart/BillController.php b/app/Http/Controllers/Chart/BillController.php index ab4fb05f79..55ea1819ff 100644 --- a/app/Http/Controllers/Chart/BillController.php +++ b/app/Http/Controllers/Chart/BillController.php @@ -102,7 +102,8 @@ class BillController extends Controller } $results = $collector->setAllAssetAccounts()->setBills(new Collection([$bill]))->getJournals(); - $results = $results->sortBy( + /** @var Collection $results */ + $results = $results->sortBy( function (Transaction $transaction) { return $transaction->date->format('U'); } diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php index 801be0814c..644b761bd6 100644 --- a/app/Http/Controllers/Chart/BudgetController.php +++ b/app/Http/Controllers/Chart/BudgetController.php @@ -325,12 +325,12 @@ class BudgetController extends Controller /** * Shows a budget list with spent/left/overspent. * - * @return \Symfony\Component\HttpFoundation\Response + * @return JsonResponse * * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ - public function frontpage(): \Symfony\Component\HttpFoundation\Response + public function frontpage(): JsonResponse { $start = session('start', Carbon::now()->startOfMonth()); $end = session('end', Carbon::now()->endOfMonth()); diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index a90a31dc8f..e3b70c6cc8 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -168,6 +168,7 @@ class Controller extends BaseController /** * Get user's language. + * * @return string */ private function getLanguage(): string diff --git a/app/Http/Controllers/ExportController.php b/app/Http/Controllers/ExportController.php index 102a10dbb3..379702255c 100644 --- a/app/Http/Controllers/ExportController.php +++ b/app/Http/Controllers/ExportController.php @@ -78,7 +78,7 @@ class ExportController extends Controller } $content = $repository->getContent($job); - $job->change('export_downloaded'); + $repository->changeStatus($job, 'export_downloaded'); /** @var LaravelResponse $response */ $response = response($content, 200); $response diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index cf2b749385..c087184932 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -108,7 +108,9 @@ class HomeController extends Controller } $subTitle = (string)trans('firefly.welcomeBack'); $transactions = []; - $frontPage = app('preferences')->get('frontPageAccounts', $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray()); + $frontPage = app('preferences')->get( + 'frontPageAccounts', $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray() + ); /** @var Carbon $start */ $start = session('start', Carbon::now()->startOfMonth()); /** @var Carbon $end */ diff --git a/app/Http/Controllers/JavascriptController.php b/app/Http/Controllers/JavascriptController.php index d9432135bf..a3b962cfc5 100644 --- a/app/Http/Controllers/JavascriptController.php +++ b/app/Http/Controllers/JavascriptController.php @@ -150,15 +150,15 @@ class JavascriptController extends Controller { $viewRange = app('preferences')->get('viewRange', '1M')->data; /** @var Carbon $start */ - $start = session('start'); + $start = session('start'); /** @var Carbon $end */ - $end = session('end'); + $end = session('end'); /** @var Carbon $first */ - $first = session('first'); - $title = sprintf('%s - %s', $start->formatLocalized($this->monthAndDayFormat), $end->formatLocalized($this->monthAndDayFormat)); - $isCustom = true === session('is_custom_range', false); - $today = new Carbon; - $ranges = [ + $first = session('first'); + $title = sprintf('%s - %s', $start->formatLocalized($this->monthAndDayFormat), $end->formatLocalized($this->monthAndDayFormat)); + $isCustom = true === session('is_custom_range', false); + $today = new Carbon; + $ranges = [ // first range is the current range: $title => [$start, $end], ]; diff --git a/app/Http/Controllers/Json/BoxController.php b/app/Http/Controllers/Json/BoxController.php index f059036100..94903a7010 100644 --- a/app/Http/Controllers/Json/BoxController.php +++ b/app/Http/Controllers/Json/BoxController.php @@ -202,7 +202,7 @@ class BoxController extends Controller /** @var Carbon $start */ $start = session('start', Carbon::now()->startOfMonth()); /** @var Carbon $end */ - $end = session('end', Carbon::now()->endOfMonth()); + $end = session('end', Carbon::now()->endOfMonth()); $cache = new CacheProperties; $cache->addProperty($start); diff --git a/app/Http/Controllers/Popup/ReportController.php b/app/Http/Controllers/Popup/ReportController.php index 8e7d3e3cb6..d6c5fef0c0 100644 --- a/app/Http/Controllers/Popup/ReportController.php +++ b/app/Http/Controllers/Popup/ReportController.php @@ -80,6 +80,7 @@ class ReportController extends Controller /** * Generate popup view. + * * @param Request $request * * @return JsonResponse @@ -274,7 +275,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::now()->startOfMonth(); + $date = Carbon::now()->startOfMonth(); $attributes['startDate'] = $date; } @@ -282,7 +283,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::now()->startOfMonth(); + $date = Carbon::now()->startOfMonth(); $attributes['endDate'] = $date; } diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 944a221915..2edae12e66 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -340,6 +340,7 @@ class ProfileController extends Controller session()->flash('success', (string)trans('firefly.saved_preferences')); app('preferences')->mark(); + return redirect(route('profile.index')); } @@ -371,6 +372,7 @@ class ProfileController extends Controller /** * Regenerate access token. + * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function regenerate() diff --git a/app/Http/Controllers/Recurring/CreateController.php b/app/Http/Controllers/Recurring/CreateController.php index 38bde82fe2..88e5abd5a4 100644 --- a/app/Http/Controllers/Recurring/CreateController.php +++ b/app/Http/Controllers/Recurring/CreateController.php @@ -86,7 +86,7 @@ class CreateController extends Controller $this->rememberPreviousUri('recurring.create.uri'); } $request->session()->forget('recurring.create.fromStore'); - $repetitionEnds = [ + $repetitionEnds = [ 'forever' => (string)trans('firefly.repeat_forever'), 'until_date' => (string)trans('firefly.repeat_until_date'), 'times' => (string)trans('firefly.repeat_times'), diff --git a/app/Http/Controllers/Recurring/EditController.php b/app/Http/Controllers/Recurring/EditController.php index 400bd07a5b..ebae84cf4d 100644 --- a/app/Http/Controllers/Recurring/EditController.php +++ b/app/Http/Controllers/Recurring/EditController.php @@ -86,7 +86,7 @@ class EditController extends Controller $budgets = app('expandedform')->makeSelectListWithEmpty($this->budgets->getActiveBudgets()); /** @var RecurrenceRepetition $repetition */ - $repetition = $recurrence->recurrenceRepetitions()->first(); + $repetition = $recurrence->recurrenceRepetitions()->first(); $currentRepType = $repetition->repetition_type; if ('' !== $repetition->repetition_moment) { $currentRepType .= ',' . $repetition->repetition_moment; diff --git a/app/Http/Controllers/Rule/CreateController.php b/app/Http/Controllers/Rule/CreateController.php index e475de3551..4bb1aeb807 100644 --- a/app/Http/Controllers/Rule/CreateController.php +++ b/app/Http/Controllers/Rule/CreateController.php @@ -28,7 +28,6 @@ use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Requests\RuleFormRequest; use FireflyIII\Models\Bill; use FireflyIII\Models\RuleGroup; -use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\Rule\RuleRepositoryInterface; use FireflyIII\Support\Http\Controllers\RuleManagement; use Illuminate\Http\RedirectResponse; @@ -42,8 +41,6 @@ use Throwable; class CreateController extends Controller { use RuleManagement; - /** @var BillRepositoryInterface Bill repository */ - private $billRepos; /** @var RuleRepositoryInterface Rule repository */ private $ruleRepos; @@ -59,7 +56,6 @@ class CreateController extends Controller app('view')->share('title', (string)trans('firefly.rules')); app('view')->share('mainTitleIcon', 'fa-random'); - $this->billRepos = app(BillRepositoryInterface::class); $this->ruleRepos = app(RuleRepositoryInterface::class); return $next($request); diff --git a/app/Http/Controllers/Rule/IndexController.php b/app/Http/Controllers/Rule/IndexController.php index 5de05fc9a8..13a6d21978 100644 --- a/app/Http/Controllers/Rule/IndexController.php +++ b/app/Http/Controllers/Rule/IndexController.php @@ -130,7 +130,7 @@ class IndexController extends Controller /** * Move rule ip. - * + * * @param Rule $rule * * @return RedirectResponse|\Illuminate\Routing\Redirector diff --git a/app/Http/Controllers/System/InstallController.php b/app/Http/Controllers/System/InstallController.php index 23056a5642..d19adf6500 100644 --- a/app/Http/Controllers/System/InstallController.php +++ b/app/Http/Controllers/System/InstallController.php @@ -34,6 +34,7 @@ use phpseclib\Crypt\RSA; /** * Class InstallController + * * @codeCoverageIgnore */ class InstallController extends Controller diff --git a/app/Http/Controllers/Transaction/LinkController.php b/app/Http/Controllers/Transaction/LinkController.php index ed11993a1e..ab938ff166 100644 --- a/app/Http/Controllers/Transaction/LinkController.php +++ b/app/Http/Controllers/Transaction/LinkController.php @@ -136,6 +136,7 @@ class LinkController extends Controller /** * Switch link from A <> B to B <> A. + * * @param TransactionJournalLink $link * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index a989dda208..6bc490a5de 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -260,9 +260,9 @@ class TransactionController extends Controller */ private function getPeriodOverview(string $what, Carbon $date): Collection { - $range = app('preferences')->get('viewRange', '1M')->data; - $first = $this->repository->firstNull(); - $start = Carbon::now()->subYear(); + $range = app('preferences')->get('viewRange', '1M')->data; + $first = $this->repository->firstNull(); + $start = Carbon::now()->subYear(); $types = config('firefly.transactionTypesByWhat.' . $what); $entries = new Collection; if (null !== $first) { @@ -289,9 +289,9 @@ class TransactionController extends Controller /** @noinspection PhpUndefinedMethodInspection */ $entries->push( [ - 'name' => $dateName, - 'sums' => $sums, - 'sum' => $sum, + 'name' => $dateName, + 'sums' => $sums, + 'sum' => $sum, 'start' => $currentDate['start']->format('Y-m-d'), 'end' => $currentDate['end']->format('Y-m-d'), ] diff --git a/app/Http/Middleware/TrustProxies.php b/app/Http/Middleware/TrustProxies.php index 3377dd6720..59900edc22 100644 --- a/app/Http/Middleware/TrustProxies.php +++ b/app/Http/Middleware/TrustProxies.php @@ -45,7 +45,7 @@ class TrustProxies extends Middleware { $trustedProxies = (string)env('TRUSTED_PROXIES', null); $this->proxies = explode(',', $trustedProxies); - if ($trustedProxies === '**') { + if ('**' === $trustedProxies) { $this->proxies = '**'; } parent::__construct($config); diff --git a/app/Http/Requests/AccountFormRequest.php b/app/Http/Requests/AccountFormRequest.php index d347aa7a9e..5aa3b47519 100644 --- a/app/Http/Requests/AccountFormRequest.php +++ b/app/Http/Requests/AccountFormRequest.php @@ -70,7 +70,7 @@ class AccountFormRequest extends Request // if the account type is "liabilities" there are actually four types of liability // that could have been selected. - if ($data['accountType'] === 'liabilities') { + if ('liabilities' === $data['accountType']) { $data['accountType'] = null; $data['account_type_id'] = $this->integer('liability_type_id'); // also reverse the opening balance: diff --git a/app/Http/Requests/JournalFormRequest.php b/app/Http/Requests/JournalFormRequest.php index e63b041a1f..ee45cfe6ce 100644 --- a/app/Http/Requests/JournalFormRequest.php +++ b/app/Http/Requests/JournalFormRequest.php @@ -270,7 +270,7 @@ class JournalFormRequest extends Request */ private function validateDeposit(Validator $validator): void { - $data = $validator->getData(); + $data = $validator->getData(); $selectedCurrency = (int)($data['amount_currency_id_amount'] ?? 0); $accountCurrency = (int)($data['destination_account_currency'] ?? 0); $nativeAmount = (string)($data['native_amount'] ?? ''); @@ -290,7 +290,7 @@ class JournalFormRequest extends Request */ private function validateTransfer(Validator $validator): void { - $data = $validator->getData(); + $data = $validator->getData(); $sourceCurrency = (int)($data['source_account_currency'] ?? 0); $destinationCurrency = (int)($data['destination_account_currency'] ?? 0); $sourceAmount = (string)($data['source_amount'] ?? ''); diff --git a/app/Http/Requests/RecurrenceFormRequest.php b/app/Http/Requests/RecurrenceFormRequest.php index 7f2fba4f03..a20ffccbe1 100644 --- a/app/Http/Requests/RecurrenceFormRequest.php +++ b/app/Http/Requests/RecurrenceFormRequest.php @@ -150,7 +150,7 @@ class RecurrenceFormRequest extends Request { $today = new Carbon; $tomorrow = Carbon::now()->addDay(); - $rules = [ + $rules = [ // mandatory info for recurrence. 'title' => 'required|between:1,255|uniqueObjectForUser:recurrences,title', 'first_date' => 'required|date|after:' . $today->format('Y-m-d'), diff --git a/app/Http/Requests/Request.php b/app/Http/Requests/Request.php index f03a05093d..9a1873fbdd 100644 --- a/app/Http/Requests/Request.php +++ b/app/Http/Requests/Request.php @@ -61,9 +61,10 @@ class Request extends FormRequest public function float(string $field): ?float { $res = $this->get($field); - if(null === $res) { + if (null === $res) { return null; } + return (float)$res; } diff --git a/app/Http/Requests/RuleFormRequest.php b/app/Http/Requests/RuleFormRequest.php index de1e104185..b9bc3dcbdb 100644 --- a/app/Http/Requests/RuleFormRequest.php +++ b/app/Http/Requests/RuleFormRequest.php @@ -61,6 +61,7 @@ class RuleFormRequest extends Request 'rule_triggers' => $this->getRuleTriggerData(), 'rule_actions' => $this->getRuleActionData(), ]; + return $data; } @@ -109,8 +110,8 @@ class RuleFormRequest extends Request */ private function getRuleActionData(): array { - $return = []; - $actionData= $this->get('rule_actions'); + $return = []; + $actionData = $this->get('rule_actions'); if (\is_array($actionData)) { foreach ($actionData as $action) { $stopProcessing = $action['stop_processing'] ?? '0'; diff --git a/app/Import/Mapper/OpposingAccountIbans.php b/app/Import/Mapper/OpposingAccountIbans.php index ad15bf94e6..d11a75323a 100644 --- a/app/Import/Mapper/OpposingAccountIbans.php +++ b/app/Import/Mapper/OpposingAccountIbans.php @@ -33,6 +33,7 @@ class OpposingAccountIbans implements MapperInterface { /** * Get map of opposing accounts. + * * @return array */ public function getMap(): array diff --git a/app/Import/Prerequisites/BunqPrerequisites.php b/app/Import/Prerequisites/BunqPrerequisites.php index 1aeecf1499..55f07df71d 100644 --- a/app/Import/Prerequisites/BunqPrerequisites.php +++ b/app/Import/Prerequisites/BunqPrerequisites.php @@ -22,8 +22,8 @@ declare(strict_types=1); namespace FireflyIII\Import\Prerequisites; -use bunq\Exception\BunqException; use bunq\Util\BunqEnumApiEnvironmentType; +use Exception; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Services\Bunq\ApiContext; use FireflyIII\Services\IP\IPRetrievalInterface; @@ -134,7 +134,7 @@ class BunqPrerequisites implements PrerequisitesInterface try { $json = $apiContext->toJson(); // @codeCoverageIgnoreStart - } catch (BunqException $e) { + } catch (Exception $e) { $messages = new MessageBag(); $messages->add('bunq_error', $e->getMessage()); diff --git a/app/Import/Routine/YnabRoutine.php b/app/Import/Routine/YnabRoutine.php index 7a7fe731b6..6540d36c19 100644 --- a/app/Import/Routine/YnabRoutine.php +++ b/app/Import/Routine/YnabRoutine.php @@ -86,17 +86,18 @@ class YnabRoutine implements RoutineInterface if (\count($budgets) > 1) { $this->repository->setStage($this->importJob, 'select_budgets'); $this->repository->setStatus($this->importJob, 'need_job_config'); + return; } - if (\count($budgets) === 1) { + if (1 === \count($budgets)) { $this->repository->setStatus($this->importJob, 'ready_to_run'); $this->repository->setStage($this->importJob, 'get_accounts'); } return; } - if('get_accounts' === $this->importJob->stage) { + if ('get_accounts' === $this->importJob->stage) { $this->repository->setStatus($this->importJob, 'running'); /** @var GetAccountsHandler $handler */ @@ -106,9 +107,10 @@ class YnabRoutine implements RoutineInterface $this->repository->setStage($this->importJob, 'select_accounts'); $this->repository->setStatus($this->importJob, 'need_job_config'); + return; } - if('go-for-import' === $this->importJob->stage) { + if ('go-for-import' === $this->importJob->stage) { $this->repository->setStatus($this->importJob, 'running'); $this->repository->setStage($this->importJob, 'do_import'); /** @var ImportDataHandler $handler */ @@ -117,26 +119,27 @@ class YnabRoutine implements RoutineInterface $handler->run(); $this->repository->setStatus($this->importJob, 'provider_finished'); $this->repository->setStage($this->importJob, 'final'); + return; } -// if ('match_accounts' === $this->importJob->stage) { -// // $this->repository->setStatus($this->importJob, 'running'); -// /** @var StageGetBudgetsHandler $handler */ -// $handler = app(StageGetBudgetsHandler::class); -// $handler->setImportJob($this->importJob); -// $handler->run(); -// $this->repository->setStage($this->importJob, 'get_transactions'); -// } -// -// if ('get_transactions' === $this->importJob->stage) { -// // $this->repository->setStatus($this->importJob, 'running'); -// /** @var StageGetBudgetsHandler $handler */ -// $handler = app(StageGetBudgetsHandler::class); -// $handler->setImportJob($this->importJob); -// $handler->run(); -// $this->repository->setStage($this->importJob, 'get_transactions'); -// } + // if ('match_accounts' === $this->importJob->stage) { + // // $this->repository->setStatus($this->importJob, 'running'); + // /** @var StageGetBudgetsHandler $handler */ + // $handler = app(StageGetBudgetsHandler::class); + // $handler->setImportJob($this->importJob); + // $handler->run(); + // $this->repository->setStage($this->importJob, 'get_transactions'); + // } + // + // if ('get_transactions' === $this->importJob->stage) { + // // $this->repository->setStatus($this->importJob, 'running'); + // /** @var StageGetBudgetsHandler $handler */ + // $handler = app(StageGetBudgetsHandler::class); + // $handler->setImportJob($this->importJob); + // $handler->run(); + // $this->repository->setStage($this->importJob, 'get_transactions'); + // } throw new FireflyException(sprintf('YNAB import routine cannot handle stage "%s"', $this->importJob->stage)); } } diff --git a/app/Jobs/CreateRecurringTransactions.php b/app/Jobs/CreateRecurringTransactions.php index 16c0bcd15d..b5f9ec9e12 100644 --- a/app/Jobs/CreateRecurringTransactions.php +++ b/app/Jobs/CreateRecurringTransactions.php @@ -55,7 +55,7 @@ class CreateRecurringTransactions implements ShouldQueue /** @var Carbon The current date */ private $date; - /** @var JournalRepositoryInterface Journal repository */ + /** @var JournalRepositoryInterface Journal repository */ private $journalRepository; /** @var RecurringRepositoryInterface Recurring transactions repository. */ private $repository; @@ -155,6 +155,7 @@ class CreateRecurringTransactions implements ShouldQueue function (Rule $rule) use ($journal) { Log::debug(sprintf('Going to apply rule #%d to journal %d.', $rule->id, $journal->id)); $processor = Processor::make($rule); + /** @noinspection ExceptionsAnnotatingAndHandlingInspection */ $processor->handleTransactionJournal($journal); if ($rule->stop_processing) { return; diff --git a/app/Models/AccountType.php b/app/Models/AccountType.php index 2faad2e91a..ae4fd5369d 100644 --- a/app/Models/AccountType.php +++ b/app/Models/AccountType.php @@ -35,32 +35,32 @@ 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 */ + /** @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'; + /** @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. * diff --git a/app/Models/Attachment.php b/app/Models/Attachment.php index 967316202b..8c700089e7 100644 --- a/app/Models/Attachment.php +++ b/app/Models/Attachment.php @@ -84,7 +84,7 @@ class Attachment extends Model /** @var User $user */ $user = auth()->user(); /** @var Attachment $attachment */ - $attachment = $user->attachments()->find($attachmentId); + $attachment = $user->attachments()->find($attachmentId); if (null !== $attachment) { return $attachment; } diff --git a/app/Models/AvailableBudget.php b/app/Models/AvailableBudget.php index 0e41aaf521..0276ba7084 100644 --- a/app/Models/AvailableBudget.php +++ b/app/Models/AvailableBudget.php @@ -76,7 +76,7 @@ class AvailableBudget extends Model /** @var User $user */ $user = auth()->user(); /** @var AvailableBudget $availableBudget */ - $availableBudget = $user->availableBudgets()->find($availableBudgetId); + $availableBudget = $user->availableBudgets()->find($availableBudgetId); if (null !== $availableBudget) { return $availableBudget; } diff --git a/app/Models/Bill.php b/app/Models/Bill.php index 2354c460f0..610d2695ce 100644 --- a/app/Models/Bill.php +++ b/app/Models/Bill.php @@ -110,9 +110,9 @@ class Bill extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\MorphMany + * @return MorphMany */ - public function attachments(): \Illuminate\Database\Eloquent\Relations\MorphMany + public function attachments(): MorphMany { return $this->morphMany(Attachment::class, 'attachable'); } diff --git a/app/Models/Budget.php b/app/Models/Budget.php index 106739fcec..0ef5142e05 100644 --- a/app/Models/Budget.php +++ b/app/Models/Budget.php @@ -41,7 +41,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @property int $user_id * @property-read string $email * @property bool encrypted - * @property Collection budgetlimits + * @property Collection budgetlimits */ class Budget extends Model { @@ -80,7 +80,7 @@ class Budget extends Model /** @var User $user */ $user = auth()->user(); /** @var Budget $budget */ - $budget = $user->budgets()->find($budgetId); + $budget = $user->budgets()->find($budgetId); if (null !== $budget) { return $budget; } diff --git a/app/Models/BudgetLimit.php b/app/Models/BudgetLimit.php index 2306e375de..f0d975d3c8 100644 --- a/app/Models/BudgetLimit.php +++ b/app/Models/BudgetLimit.php @@ -48,7 +48,7 @@ class BudgetLimit extends Model * @var array */ protected $casts - = [ + = [ 'created_at' => 'datetime', 'updated_at' => 'datetime', 'start_date' => 'date', diff --git a/app/Models/Category.php b/app/Models/Category.php index 92e657d78f..67459e3a24 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -39,7 +39,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @property int $id * @property float $spent // used in category reports * @property Carbon|null lastActivity - * @property bool encrypted + * @property bool encrypted */ class Category extends Model { @@ -77,7 +77,7 @@ class Category extends Model /** @var User $user */ $user = auth()->user(); /** @var Category $category */ - $category = $user->categories()->find($categoryId); + $category = $user->categories()->find($categoryId); if (null !== $category) { return $category; } diff --git a/app/Models/CurrencyExchangeRate.php b/app/Models/CurrencyExchangeRate.php index 203b4d6bd2..6a50c0d874 100644 --- a/app/Models/CurrencyExchangeRate.php +++ b/app/Models/CurrencyExchangeRate.php @@ -46,8 +46,8 @@ class CurrencyExchangeRate extends Model /** @var array Convert these fields to other data types */ protected $casts = [ - 'created_at' => 'datetime', - 'updated_at' => 'datetime', + 'created_at' => 'datetime', + 'updated_at' => 'datetime', 'user_id' => 'int', 'from_currency_id' => 'int', 'to_currency_id' => 'int', diff --git a/app/Models/ImportJob.php b/app/Models/ImportJob.php index ab8392a1f7..aebbf35b45 100644 --- a/app/Models/ImportJob.php +++ b/app/Models/ImportJob.php @@ -25,6 +25,7 @@ namespace FireflyIII\Models; use FireflyIII\User; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\MorphMany; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** @@ -43,7 +44,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @property Tag $tag * @property array $errors * @property array extended_status - * @property int id + * @property int id */ class ImportJob extends Model { @@ -77,7 +78,7 @@ class ImportJob extends Model public static function routeBinder(string $value): ImportJob { if (auth()->check()) { - $key = trim($value); + $key = trim($value); /** @var User $user */ $user = auth()->user(); /** @var ImportJob $importJob */ @@ -91,9 +92,9 @@ class ImportJob extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\MorphMany + * @return MorphMany */ - public function attachments(): \Illuminate\Database\Eloquent\Relations\MorphMany + public function attachments(): MorphMany { return $this->morphMany(Attachment::class, 'attachable'); } diff --git a/app/Models/PiggyBank.php b/app/Models/PiggyBank.php index 360d4b7c01..289e7f79b3 100644 --- a/app/Models/PiggyBank.php +++ b/app/Models/PiggyBank.php @@ -45,7 +45,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @property int $order * @property bool $active * @property int $account_id - * @property bool encrypted + * @property bool encrypted * */ class PiggyBank extends Model diff --git a/app/Models/PiggyBankEvent.php b/app/Models/PiggyBankEvent.php index 3cb7541896..6cc3042832 100644 --- a/app/Models/PiggyBankEvent.php +++ b/app/Models/PiggyBankEvent.php @@ -33,7 +33,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; * @property int $transaction_journal_id * @property int $piggy_bank_id * @property int $id - * @property Carbon date + * @property Carbon date */ class PiggyBankEvent extends Model { diff --git a/app/Models/Preference.php b/app/Models/Preference.php index a7e28d2bad..f24effcfe1 100644 --- a/app/Models/Preference.php +++ b/app/Models/Preference.php @@ -41,7 +41,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @property Carbon $updated_at * @property Carbon $created_at * @property int $id - * @property User user + * @property User user */ class Preference extends Model { @@ -74,7 +74,7 @@ class Preference extends Model /** @var User $user */ $user = auth()->user(); /** @var Preference $preference */ - $preference = $user->preferences()->find($preferenceId); + $preference = $user->preferences()->find($preferenceId); if (null !== $preference) { return $preference; } diff --git a/app/Models/Recurrence.php b/app/Models/Recurrence.php index 0c4ac5a9c0..3bdcc2c58d 100644 --- a/app/Models/Recurrence.php +++ b/app/Models/Recurrence.php @@ -103,7 +103,7 @@ class Recurrence extends Model /** @var User $user */ $user = auth()->user(); /** @var Recurrence $recurrence */ - $recurrence = $user->recurrences()->find($recurrenceId); + $recurrence = $user->recurrences()->find($recurrenceId); if (null !== $recurrence) { return $recurrence; } diff --git a/app/Models/RecurrenceRepetition.php b/app/Models/RecurrenceRepetition.php index cc26a97378..fc72034c92 100644 --- a/app/Models/RecurrenceRepetition.php +++ b/app/Models/RecurrenceRepetition.php @@ -57,7 +57,7 @@ class RecurrenceRepetition extends Model * @var array */ protected $casts - = [ + = [ 'created_at' => 'datetime', 'updated_at' => 'datetime', 'deleted_at' => 'datetime', diff --git a/app/Models/RecurrenceTransactionMeta.php b/app/Models/RecurrenceTransactionMeta.php index 1f283ad0db..9f96b0fb5b 100644 --- a/app/Models/RecurrenceTransactionMeta.php +++ b/app/Models/RecurrenceTransactionMeta.php @@ -43,7 +43,7 @@ class RecurrenceTransactionMeta extends Model * @var array */ protected $casts - = [ + = [ 'created_at' => 'datetime', 'updated_at' => 'datetime', 'deleted_at' => 'datetime', diff --git a/app/Models/Rule.php b/app/Models/Rule.php index 328ac6039d..58fe37ac10 100644 --- a/app/Models/Rule.php +++ b/app/Models/Rule.php @@ -88,7 +88,7 @@ class Rule extends Model /** @var User $user */ $user = auth()->user(); /** @var Rule $rule */ - $rule = $user->rules()->find($ruleId); + $rule = $user->rules()->find($ruleId); if (null !== $rule) { return $rule; } diff --git a/app/Models/RuleGroup.php b/app/Models/RuleGroup.php index 233ef34165..14f85f5491 100644 --- a/app/Models/RuleGroup.php +++ b/app/Models/RuleGroup.php @@ -43,7 +43,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @property int $id * @property int $order * @property Collection $rules - * @property string description + * @property string description */ class RuleGroup extends Model { @@ -80,7 +80,7 @@ class RuleGroup extends Model /** @var User $user */ $user = auth()->user(); /** @var RuleGroup $ruleGroup */ - $ruleGroup = $user->ruleGroups()->find($ruleGroupId); + $ruleGroup = $user->ruleGroups()->find($ruleGroupId); if (null !== $ruleGroup) { return $ruleGroup; } diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index d20fbf8778..bc52be8698 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -237,6 +237,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 08358b492d..5f85ace223 100644 --- a/app/Models/TransactionCurrency.php +++ b/app/Models/TransactionCurrency.php @@ -34,7 +34,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @property string $symbol * @property int $decimal_places * @property int $id - * @property string name + * @property string name * */ class TransactionCurrency extends Model diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php index ccdb49fa4c..266974a4b5 100644 --- a/app/Models/TransactionJournal.php +++ b/app/Models/TransactionJournal.php @@ -150,9 +150,9 @@ class TransactionJournal extends Model /** * @codeCoverageIgnore - * @return \Illuminate\Database\Eloquent\Relations\MorphMany + * @return MorphMany */ - public function attachments(): \Illuminate\Database\Eloquent\Relations\MorphMany + public function attachments(): MorphMany { return $this->morphMany(Attachment::class, 'attachable'); } diff --git a/app/Models/TransactionJournalLink.php b/app/Models/TransactionJournalLink.php index 92e5920f7a..8107ce07a0 100644 --- a/app/Models/TransactionJournalLink.php +++ b/app/Models/TransactionJournalLink.php @@ -45,9 +45,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; */ class TransactionJournalLink extends Model { - /** @var string The table to store the data in */ - protected $table = 'journal_links'; - /** * The attributes that should be casted to native types. * @@ -55,9 +52,11 @@ class TransactionJournalLink extends Model */ protected $casts = [ - 'created_at' => 'datetime', - 'updated_at' => 'datetime', + 'created_at' => 'datetime', + 'updated_at' => 'datetime', ]; + /** @var string The table to store the data in */ + protected $table = 'journal_links'; /** * Route binder. Converts the key in the URL to the specified object (or throw 404). diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index d91edc80e3..f426485c0f 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -26,6 +26,7 @@ use Illuminate\Support\Facades\Schema; use Illuminate\Support\ServiceProvider; use Laravel\Passport\Passport; use URL; + /** * @codeCoverageIgnore * Class AppServiceProvider. @@ -38,7 +39,7 @@ class AppServiceProvider extends ServiceProvider public function boot(): void { Schema::defaultStringLength(191); - if('heroku' === env('APP_ENV')) { + if ('heroku' === env('APP_ENV')) { URL::forceScheme('https'); } } diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index 8489a62a80..0961ba3f9b 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -303,6 +303,7 @@ class AccountRepository implements AccountRepositoryInterface if (null === $note) { return null; } + return $note->text; } @@ -450,6 +451,9 @@ class AccountRepository implements AccountRepositoryInterface * @param array $data * * @return Account + * @throws \FireflyIII\Exceptions\FireflyException + * @throws FireflyException + * @throws FireflyException */ public function update(Account $account, array $data): Account { diff --git a/app/Repositories/Attachment/AttachmentRepositoryInterface.php b/app/Repositories/Attachment/AttachmentRepositoryInterface.php index 527d00f88e..b59378c58d 100644 --- a/app/Repositories/Attachment/AttachmentRepositoryInterface.php +++ b/app/Repositories/Attachment/AttachmentRepositoryInterface.php @@ -50,6 +50,7 @@ interface AttachmentRepositoryInterface /** * @param int $attachmentId + * * @return Attachment|null */ public function findWithoutUser(int $attachmentId): ?Attachment; diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php index 390916ce24..a7587fff83 100644 --- a/app/Repositories/Bill/BillRepository.php +++ b/app/Repositories/Bill/BillRepository.php @@ -323,7 +323,7 @@ class BillRepository implements BillRepositoryInterface */ public function getPayDatesInRange(Bill $bill, Carbon $start, Carbon $end): Collection { - $set = new Collection; + $set = new Collection; $currentStart = clone $start; Log::debug(sprintf('Now at bill "%s" (%s)', $bill->name, $bill->repeat_freq)); Log::debug(sprintf('First currentstart is %s', $currentStart->format('Y-m-d'))); diff --git a/app/Repositories/ExportJob/ExportJobRepository.php b/app/Repositories/ExportJob/ExportJobRepository.php index a74f7f6628..756af68450 100644 --- a/app/Repositories/ExportJob/ExportJobRepository.php +++ b/app/Repositories/ExportJob/ExportJobRepository.php @@ -48,7 +48,8 @@ class ExportJobRepository implements ExportJobRepositoryInterface public function changeStatus(ExportJob $job, string $status): bool { Log::debug(sprintf('Change status of job #%d to "%s"', $job->id, $status)); - $job->change($status); + $job->status = $status; + $job->save(); return true; } diff --git a/app/Repositories/ExportJob/ExportJobRepositoryInterface.php b/app/Repositories/ExportJob/ExportJobRepositoryInterface.php index 65d51523a4..d1a35f47a9 100644 --- a/app/Repositories/ExportJob/ExportJobRepositoryInterface.php +++ b/app/Repositories/ExportJob/ExportJobRepositoryInterface.php @@ -57,6 +57,7 @@ interface ExportJobRepositoryInterface /** * @param string $key + * * @return ExportJob|null */ public function findByKey(string $key): ?ExportJob; diff --git a/app/Repositories/ImportJob/ImportJobRepository.php b/app/Repositories/ImportJob/ImportJobRepository.php index 43efe32767..120e612f40 100644 --- a/app/Repositories/ImportJob/ImportJobRepository.php +++ b/app/Repositories/ImportJob/ImportJobRepository.php @@ -184,6 +184,7 @@ class ImportJobRepository implements ImportJobRepositoryInterface $newConfig = array_merge($currentConfig, $configuration); $job->configuration = $newConfig; $job->save(); + //Log::debug(sprintf('Set config of job "%s" to: ', $job->key), $newConfig); return $job; diff --git a/app/Repositories/ImportJob/ImportJobRepositoryInterface.php b/app/Repositories/ImportJob/ImportJobRepositoryInterface.php index 6d151a4588..42248dd461 100644 --- a/app/Repositories/ImportJob/ImportJobRepositoryInterface.php +++ b/app/Repositories/ImportJob/ImportJobRepositoryInterface.php @@ -54,6 +54,7 @@ interface ImportJobRepositoryInterface /** * @param string $key + * * @return ImportJob|null */ public function findByKey(string $key): ?ImportJob; diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php index 64715c42af..c89d31e2fd 100644 --- a/app/Repositories/Journal/JournalRepository.php +++ b/app/Repositories/Journal/JournalRepository.php @@ -707,6 +707,8 @@ class JournalRepository implements JournalRepositoryInterface * * @return TransactionJournal * + * @throws FireflyException + * @throws FireflyException */ public function update(TransactionJournal $journal, array $data): TransactionJournal { diff --git a/app/Repositories/Journal/JournalRepositoryInterface.php b/app/Repositories/Journal/JournalRepositoryInterface.php index 6b26aaa30a..0b38323d41 100644 --- a/app/Repositories/Journal/JournalRepositoryInterface.php +++ b/app/Repositories/Journal/JournalRepositoryInterface.php @@ -25,7 +25,6 @@ namespace FireflyIII\Repositories\Journal; use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Account; - use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournalMeta; diff --git a/app/Repositories/Tag/TagRepositoryInterface.php b/app/Repositories/Tag/TagRepositoryInterface.php index c85b819de3..bedfef3cb7 100644 --- a/app/Repositories/Tag/TagRepositoryInterface.php +++ b/app/Repositories/Tag/TagRepositoryInterface.php @@ -60,7 +60,7 @@ interface TagRepositoryInterface * * @return Tag|null */ - public function findByTag(string $tag):?Tag; + public function findByTag(string $tag): ?Tag; /** * @param int $tagId diff --git a/app/Services/Currency/FixerIOv2.php b/app/Services/Currency/FixerIOv2.php index 2d5f250f8a..0bbfbc556d 100644 --- a/app/Services/Currency/FixerIOv2.php +++ b/app/Services/Currency/FixerIOv2.php @@ -68,7 +68,7 @@ class FixerIOv2 implements ExchangeRateInterface } // build URI - $uri = sprintf( + $uri = sprintf( 'http://data.fixer.io/api/%s?access_key=%s&base=%s&symbols=%s', $date->format('Y-m-d'), $apiKey, $fromCurrency->code, $toCurrency->code ); diff --git a/app/Services/Github/Request/UpdateRequest.php b/app/Services/Github/Request/UpdateRequest.php index 44a0bc17b7..1616db8701 100644 --- a/app/Services/Github/Request/UpdateRequest.php +++ b/app/Services/Github/Request/UpdateRequest.php @@ -60,7 +60,7 @@ class UpdateRequest implements GithubRequest } try { $releaseXml = new SimpleXMLElement($res->getBody()->getContents(), LIBXML_NOCDATA); - } catch (RunTimeException $e) { + } catch (RuntimeException $e) { Log::error(sprintf('Could not get body from github updat result: %s', $e->getMessage())); $releaseXml = new SimpleXMLElement(''); } diff --git a/app/Services/IP/IpifyOrg.php b/app/Services/IP/IpifyOrg.php index a171b3f8eb..f5abb40d5e 100644 --- a/app/Services/IP/IpifyOrg.php +++ b/app/Services/IP/IpifyOrg.php @@ -27,7 +27,7 @@ use Exception; use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; use Log; -use RunTimeException; +use RuntimeException; /** * Class IpifyOrg @@ -58,7 +58,7 @@ class IpifyOrg implements IPRetrievalInterface } try { $body = (string)$res->getBody()->getContents(); - } catch (RunTimeException $e) { + } catch (RuntimeException $e) { Log::error(sprintf('Could not get body from ipify.org result: %s', $e->getMessage())); $body = null; } diff --git a/app/Services/Internal/Support/AccountServiceTrait.php b/app/Services/Internal/Support/AccountServiceTrait.php index 6877ba13bb..8d4e2f3e33 100644 --- a/app/Services/Internal/Support/AccountServiceTrait.php +++ b/app/Services/Internal/Support/AccountServiceTrait.php @@ -49,7 +49,7 @@ trait AccountServiceTrait /** @var array */ public $validCCFields = ['accountRole', 'ccMonthlyPaymentDate', 'ccType', 'accountNumber', 'currency_id', 'BIC']; /** @var array */ - public $validFields = ['accountNumber', 'currency_id', 'BIC','interest','interest_period']; + public $validFields = ['accountNumber', 'currency_id', 'BIC', 'interest', 'interest_period']; /** * @param Account $account diff --git a/app/Services/Internal/Support/TransactionTypeTrait.php b/app/Services/Internal/Support/TransactionTypeTrait.php index 4372c736d8..e877e3be76 100644 --- a/app/Services/Internal/Support/TransactionTypeTrait.php +++ b/app/Services/Internal/Support/TransactionTypeTrait.php @@ -22,6 +22,7 @@ declare(strict_types=1); namespace FireflyIII\Services\Internal\Support; + use FireflyIII\Exceptions\FireflyException; use FireflyIII\Factory\TransactionTypeFactory; use FireflyIII\Models\TransactionType; diff --git a/app/Services/Internal/Update/BillUpdateService.php b/app/Services/Internal/Update/BillUpdateService.php index 72c811bee2..1c849d4fb4 100644 --- a/app/Services/Internal/Update/BillUpdateService.php +++ b/app/Services/Internal/Update/BillUpdateService.php @@ -51,7 +51,7 @@ class BillUpdateService $bill->repeat_freq = $data['repeat_freq']; $bill->skip = $data['skip']; $bill->automatch = true; - $bill->active = $data['active']??true; + $bill->active = $data['active'] ?? true; $bill->save(); // update note: diff --git a/app/Services/Internal/Update/RecurrenceUpdateService.php b/app/Services/Internal/Update/RecurrenceUpdateService.php index b33a8b2297..7205b4c9ff 100644 --- a/app/Services/Internal/Update/RecurrenceUpdateService.php +++ b/app/Services/Internal/Update/RecurrenceUpdateService.php @@ -25,7 +25,6 @@ namespace FireflyIII\Services\Internal\Update; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Recurrence; - use FireflyIII\Services\Internal\Support\RecurringTransactionTrait; use FireflyIII\Services\Internal\Support\TransactionServiceTrait; use FireflyIII\Services\Internal\Support\TransactionTypeTrait; @@ -65,7 +64,7 @@ class RecurrenceUpdateService $recurrence->apply_rules = $data['recurrence']['apply_rules'] ?? $recurrence->apply_rules; $recurrence->active = $data['recurrence']['active'] ?? $recurrence->active; - if(isset($data['recurrence']['repetition_end'])) { + if (isset($data['recurrence']['repetition_end'])) { if (\in_array($data['recurrence']['repetition_end'], ['forever ', 'until_date'])) { $recurrence->repetitions = 0; } diff --git a/app/Services/Password/PwndVerifierV2.php b/app/Services/Password/PwndVerifierV2.php index 87e936b846..b78fdeb67b 100644 --- a/app/Services/Password/PwndVerifierV2.php +++ b/app/Services/Password/PwndVerifierV2.php @@ -67,7 +67,7 @@ class PwndVerifierV2 implements Verifier } try { $strpos = stripos($res->getBody()->getContents(), $rest); - } catch (RunTimeException $e) { + } catch (RuntimeException $e) { Log::error(sprintf('Could not get body from Pwnd result: %s', $e->getMessage())); $strpos = false; } diff --git a/app/Services/Spectre/Object/Attempt.php b/app/Services/Spectre/Object/Attempt.php index 53aff5124a..210ad00088 100644 --- a/app/Services/Spectre/Object/Attempt.php +++ b/app/Services/Spectre/Object/Attempt.php @@ -28,6 +28,7 @@ use Carbon\Carbon; /** * * Class Attempt + * * @codeCoverageIgnore * @SuppressWarnings(PHPMD.ShortVariable) * @SuppressWarnings(PHPMD.TooManyFields) diff --git a/app/Services/Spectre/Object/Login.php b/app/Services/Spectre/Object/Login.php index 6d536ac7ce..23b120e0a9 100644 --- a/app/Services/Spectre/Object/Login.php +++ b/app/Services/Spectre/Object/Login.php @@ -28,6 +28,7 @@ use Carbon\Carbon; /** * Class Login + * * @codeCoverageIgnore * @SuppressWarnings(PHPMD.ShortVariable) * @SuppressWarnings(PHPMD.TooManyFields) diff --git a/app/Services/Spectre/Object/Transaction.php b/app/Services/Spectre/Object/Transaction.php index 866ffddbb2..974bf01cc6 100644 --- a/app/Services/Spectre/Object/Transaction.php +++ b/app/Services/Spectre/Object/Transaction.php @@ -27,6 +27,7 @@ use Carbon\Carbon; /** * Class Transaction + * * @codeCoverageIgnore * * @SuppressWarnings(PHPMD.ShortVariable) diff --git a/app/Services/Spectre/Request/NewCustomerRequest.php b/app/Services/Spectre/Request/NewCustomerRequest.php index 099a40cfd9..36e4946387 100644 --- a/app/Services/Spectre/Request/NewCustomerRequest.php +++ b/app/Services/Spectre/Request/NewCustomerRequest.php @@ -24,6 +24,7 @@ namespace FireflyIII\Services\Spectre\Request; use FireflyIII\Services\Spectre\Object\Customer; use Log; + /** * Class NewCustomerRequest */ @@ -37,12 +38,12 @@ class NewCustomerRequest extends SpectreRequest */ public function call(): void { - $data = [ + $data = [ 'data' => [ 'identifier' => 'default_ff3_customer', ], ]; - $uri = '/api/v4/customers/'; + $uri = '/api/v4/customers/'; Log::debug(sprintf('Going to call %s with info:', $uri), $data); $response = $this->sendSignedSpectrePost($uri, $data); // create customer: diff --git a/app/Services/Spectre/Request/SpectreRequest.php b/app/Services/Spectre/Request/SpectreRequest.php index cbf62ebe71..d392fad037 100644 --- a/app/Services/Spectre/Request/SpectreRequest.php +++ b/app/Services/Spectre/Request/SpectreRequest.php @@ -211,7 +211,7 @@ abstract class SpectreRequest $statusCode = $res->getStatusCode(); try { $returnBody = $res->getBody()->getContents(); - } catch (RunTimeException $e) { + } catch (RuntimeException $e) { Log::error(sprintf('Could not get body from SpectreRequest::GET result: %s', $e->getMessage())); $returnBody = ''; } @@ -261,7 +261,7 @@ abstract class SpectreRequest try { $body = $res->getBody()->getContents(); - } catch (RunTimeException $e) { + } catch (RuntimeException $e) { Log::error(sprintf('Could not get body from SpectreRequest::POST result: %s', $e->getMessage())); $body = ''; } diff --git a/app/Support/Amount.php b/app/Support/Amount.php index 48c98cc177..e2fa4c17c0 100644 --- a/app/Support/Amount.php +++ b/app/Support/Amount.php @@ -56,7 +56,7 @@ class Amount $space = ' '; // require space between symbol and amount? - if ($sepBySpace === false) { + if (false === $sepBySpace) { $space = ''; // no } @@ -134,8 +134,8 @@ class Amount // some complicated switches to format the amount correctly: $precedes = $amount < 0 ? $info['n_cs_precedes'] : $info['p_cs_precedes']; $separated = $amount < 0 ? $info['n_sep_by_space'] : $info['p_sep_by_space']; - $space = $separated === true ? ' ' : ''; - $result = $precedes === false ? $formatted . $space . $format->symbol : $format->symbol . $space . $formatted; + $space = true === $separated ? ' ' : ''; + $result = false === $precedes ? $formatted . $space . $format->symbol : $format->symbol . $space . $formatted; if (true === $coloured) { if ($amount > 0) { diff --git a/app/Support/Import/JobConfiguration/Ynab/SelectBudgetHandler.php b/app/Support/Import/JobConfiguration/Ynab/SelectBudgetHandler.php index a65d7be089..92a14d57c1 100644 --- a/app/Support/Import/JobConfiguration/Ynab/SelectBudgetHandler.php +++ b/app/Support/Import/JobConfiguration/Ynab/SelectBudgetHandler.php @@ -59,7 +59,7 @@ class SelectBudgetHandler implements YnabJobConfigurationInterface Log::debug('Now in SelectBudgetHandler::configComplete'); $configuration = $this->repository->getConfiguration($this->importJob); $selectedBudget = $configuration['selected_budget'] ?? ''; - if ($selectedBudget !== '') { + if ('' !== $selectedBudget) { Log::debug(sprintf('Selected budget is %s, config is complete. Return true.', $selectedBudget)); $this->repository->setStage($this->importJob, 'get_accounts'); diff --git a/app/Support/Import/JobConfiguration/Ynab/YnabJobConfigurationInterface.php b/app/Support/Import/JobConfiguration/Ynab/YnabJobConfigurationInterface.php index 5458d1ef53..bc9bcc3d2e 100644 --- a/app/Support/Import/JobConfiguration/Ynab/YnabJobConfigurationInterface.php +++ b/app/Support/Import/JobConfiguration/Ynab/YnabJobConfigurationInterface.php @@ -22,6 +22,7 @@ declare(strict_types=1); namespace FireflyIII\Support\Import\JobConfiguration\Ynab; + use FireflyIII\Models\ImportJob; use Illuminate\Support\MessageBag; diff --git a/app/Support/Import/Routine/File/ImportableConverter.php b/app/Support/Import/Routine/File/ImportableConverter.php index d4a90fc9d8..b12cb52216 100644 --- a/app/Support/Import/Routine/File/ImportableConverter.php +++ b/app/Support/Import/Routine/File/ImportableConverter.php @@ -147,6 +147,7 @@ class ImportableConverter Log::error($e->getTraceAsString()); } } + return $result; } diff --git a/app/Support/Import/Routine/Ynab/ImportDataHandler.php b/app/Support/Import/Routine/Ynab/ImportDataHandler.php index c6e4c0976c..0e97b2f5ea 100644 --- a/app/Support/Import/Routine/Ynab/ImportDataHandler.php +++ b/app/Support/Import/Routine/Ynab/ImportDataHandler.php @@ -150,7 +150,7 @@ class ImportDataHandler $destination = $this->mapper->map($possibleDestinationId, $amount, $destinationData); if (1 === bccomp($amount, '0')) { [$source, $destination] = [$destination, $source]; - $type = $type === 'transfer' ? 'transfer' : 'deposit'; + $type = 'transfer' === $type ? 'transfer' : 'deposit'; Log::debug(sprintf('Amount is %s, so switch source/dest and make this a %s', $amount, $type)); } diff --git a/app/Support/Import/Routine/Ynab/StageGetAccessHandler.php b/app/Support/Import/Routine/Ynab/StageGetAccessHandler.php index 4c91d1abac..c155a4e0ca 100644 --- a/app/Support/Import/Routine/Ynab/StageGetAccessHandler.php +++ b/app/Support/Import/Routine/Ynab/StageGetAccessHandler.php @@ -70,14 +70,14 @@ class StageGetAccessHandler } $statusCode = $res->getStatusCode(); try { - $content = trim($res->getBody()->getContents()); - } catch(RuntimeException $e) { + $content = trim($res->getBody()->getContents()); + } catch (RuntimeException $e) { Log::error($e->getMessage()); Log::error($e->getTraceAsString()); throw new FireflyException($e->getMessage()); } - $json = json_decode($content, true) ?? []; + $json = json_decode($content, true) ?? []; Log::debug(sprintf('Status code from YNAB is %d', $statusCode)); Log::debug(sprintf('Body of result is %s', $content), $json); diff --git a/app/Support/Import/Routine/Ynab/StageGetBudgetsHandler.php b/app/Support/Import/Routine/Ynab/StageGetBudgetsHandler.php index 642298d4bb..fd8c3dbeb6 100644 --- a/app/Support/Import/Routine/Ynab/StageGetBudgetsHandler.php +++ b/app/Support/Import/Routine/Ynab/StageGetBudgetsHandler.php @@ -58,7 +58,7 @@ class StageGetBudgetsHandler $configuration['budgets'] = $request->budgets; $this->repository->setConfiguration($this->importJob, $configuration); Log::debug(sprintf('Found %d budgets', \count($request->budgets))); - if (\count($request->budgets) === 0) { + if (0 === \count($request->budgets)) { throw new FireflyException('It seems this user has zero budgets or an error prevented Firefly III from reading them.'); } } diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php index b94901dcd1..c1a097efc6 100644 --- a/app/Support/Preferences.php +++ b/app/Support/Preferences.php @@ -171,6 +171,7 @@ class Preferences if (\is_array($lastActivity)) { $lastActivity = implode(',', $lastActivity); } + return md5($lastActivity); } diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.php index 804378ffe2..e26f79374d 100644 --- a/app/Support/Twig/General.php +++ b/app/Support/Twig/General.php @@ -46,7 +46,7 @@ class General extends Twig_Extension $this->balance(), $this->formatFilesize(), $this->mimeIcon(), - $this->markdown() + $this->markdown(), ]; } @@ -249,6 +249,7 @@ class General extends Twig_Extension if ($repository->hasRole(auth()->user(), $role)) { return true; } + return false; } ); diff --git a/app/Support/Twig/Translation.php b/app/Support/Twig/Translation.php index e00093a7c9..6aa55ceec3 100644 --- a/app/Support/Twig/Translation.php +++ b/app/Support/Twig/Translation.php @@ -69,7 +69,6 @@ class Translation extends Twig_Extension 'journalLinkTranslation', function (string $direction, string $original) { $key = sprintf('firefly.%s_%s', $original, $direction); - return $key; $translation = trans($key); if ($key === $translation) { diff --git a/app/TransactionRules/Processor.php b/app/TransactionRules/Processor.php index a3de4387f0..6acf0fcd64 100644 --- a/app/TransactionRules/Processor.php +++ b/app/TransactionRules/Processor.php @@ -86,7 +86,7 @@ final class Processor Log::debug(sprintf('Push trigger %d', $trigger->id)); $self->triggers->push(TriggerFactory::getTrigger($trigger)); } - if ($includeActions === true) { + if (true === $includeActions) { $self->actions = $rule->ruleActions()->orderBy('order', 'ASC')->get(); } diff --git a/app/TransactionRules/TransactionMatcher.php b/app/TransactionRules/TransactionMatcher.php index b417311aae..3d1ba9d317 100644 --- a/app/TransactionRules/TransactionMatcher.php +++ b/app/TransactionRules/TransactionMatcher.php @@ -195,15 +195,15 @@ class TransactionMatcher $allTriggers = $this->rule->ruleTriggers()->whereIn('trigger_type', $valid)->get(); /** @var RuleTrigger $trigger */ foreach ($allTriggers as $trigger) { - if ($trigger->trigger_type === 'amount_less') { + if ('amount_less' === $trigger->trigger_type) { $this->maxAmount = $trigger->trigger_value; Log::debug(sprintf('Set max amount to be %s', $trigger->trigger_value)); } - if ($trigger->trigger_type === 'amount_more') { + if ('amount_more' === $trigger->trigger_type) { $this->minAmount = $trigger->trigger_value; Log::debug(sprintf('Set min amount to be %s', $trigger->trigger_value)); } - if ($trigger->trigger_type === 'amount_exactly') { + if ('amount_exactly' === $trigger->trigger_type) { $this->exactAmount = $trigger->trigger_value; Log::debug(sprintf('Set exact amount to be %s', $trigger->trigger_value)); } diff --git a/app/Transformers/AccountTransformer.php b/app/Transformers/AccountTransformer.php index 64ec626911..c6cc0e3af2 100644 --- a/app/Transformers/AccountTransformer.php +++ b/app/Transformers/AccountTransformer.php @@ -148,7 +148,7 @@ class AccountTransformer extends TransformerAbstract $type = $account->accountType->type; $role = $this->repository->getMetaValue($account, 'accountRole'); - if ($type !== AccountType::ASSET || (string)$role === '') { + if ($type !== AccountType::ASSET || '' === (string)$role) { $role = null; } $currencyId = (int)$this->repository->getMetaValue($account, 'currency_id'); @@ -167,13 +167,13 @@ class AccountTransformer extends TransformerAbstract $date = $this->parameters->get('date'); } - if ($currencyId === 0) { + if (0 === $currencyId) { $currencyId = null; } $monthlyPaymentDate = null; $creditCardType = null; - if ($role === 'ccAsset' && $type === AccountType::ASSET) { + if ('ccAsset' === $role && $type === AccountType::ASSET) { $creditCardType = $this->repository->getMetaValue($account, 'ccType'); $monthlyPaymentDate = $this->repository->getMetaValue($account, 'ccMonthlyPaymentDate'); } @@ -194,7 +194,7 @@ class AccountTransformer extends TransformerAbstract 'updated_at' => $account->updated_at->toAtomString(), 'created_at' => $account->created_at->toAtomString(), 'name' => $account->name, - 'active' => (int)$account->active === 1, + 'active' => 1 === (int)$account->active, 'type' => $type, 'currency_id' => $currencyId, 'currency_code' => $currencyCode, diff --git a/app/Transformers/BudgetTransformer.php b/app/Transformers/BudgetTransformer.php index 4b9562292a..e09170a54a 100644 --- a/app/Transformers/BudgetTransformer.php +++ b/app/Transformers/BudgetTransformer.php @@ -118,7 +118,7 @@ class BudgetTransformer extends TransformerAbstract 'id' => (int)$budget->id, 'updated_at' => $budget->updated_at->toAtomString(), 'created_at' => $budget->created_at->toAtomString(), - 'active' => (int)$budget->active === 1, + 'active' => 1 === (int)$budget->active, 'name' => $budget->name, 'links' => [ [ diff --git a/app/Transformers/CurrencyExchangeRateTransformer.php b/app/Transformers/CurrencyExchangeRateTransformer.php index e1c8ebc0e6..e9dbd007dc 100644 --- a/app/Transformers/CurrencyExchangeRateTransformer.php +++ b/app/Transformers/CurrencyExchangeRateTransformer.php @@ -29,6 +29,9 @@ use League\Fractal\Resource\Item; use League\Fractal\TransformerAbstract; use Symfony\Component\HttpFoundation\ParameterBag; +/** + * Class CurrencyExchangeRateTransformer + */ class CurrencyExchangeRateTransformer extends TransformerAbstract { /** @@ -79,6 +82,11 @@ class CurrencyExchangeRateTransformer extends TransformerAbstract return $this->item($rate->toCurrency, new CurrencyTransformer($this->parameters), 'transaction_currencies'); } + /** + * @param CurrencyExchangeRate $rate + * + * @return array + */ public function transform(CurrencyExchangeRate $rate): array { $data = [ diff --git a/app/Transformers/PiggyBankEventTransformer.php b/app/Transformers/PiggyBankEventTransformer.php index 44b60aad55..420a761899 100644 --- a/app/Transformers/PiggyBankEventTransformer.php +++ b/app/Transformers/PiggyBankEventTransformer.php @@ -95,6 +95,7 @@ class PiggyBankEventTransformer extends TransformerAbstract $pageSize = (int)app('preferences')->getForUser($journal->user, 'listPageSize', 50)->data; // journals always use collector and limited using URL parameters. + /** @var JournalCollectorInterface $collector */ $collector = app(JournalCollectorInterface::class); $collector->setUser($journal->user); $collector->withOpposingAccount()->withCategoryInformation()->withCategoryInformation(); @@ -129,7 +130,8 @@ class PiggyBankEventTransformer extends TransformerAbstract /** @var CurrencyRepositoryInterface $repository */ $repository = app(CurrencyRepositoryInterface::class); $repository->setUser($account->user); - $currency = $repository->findNull($currencyId); + $currency = $repository->findNull($currencyId); + /** @noinspection NullPointerExceptionInspection */ $decimalPlaces = $currency->decimal_places; } diff --git a/app/Transformers/PiggyBankTransformer.php b/app/Transformers/PiggyBankTransformer.php index 897e969b7e..b3bd7f91da 100644 --- a/app/Transformers/PiggyBankTransformer.php +++ b/app/Transformers/PiggyBankTransformer.php @@ -170,7 +170,7 @@ class PiggyBankTransformer extends TransformerAbstract 'start_date' => $startDate, 'target_date' => $targetDate, 'order' => (int)$piggyBank->order, - 'active' => (int)$piggyBank->active === 1, + 'active' => 1 === (int)$piggyBank->active, 'notes' => null, 'links' => [ [ diff --git a/app/Transformers/PreferenceTransformer.php b/app/Transformers/PreferenceTransformer.php index 033b682050..254c11bf3c 100644 --- a/app/Transformers/PreferenceTransformer.php +++ b/app/Transformers/PreferenceTransformer.php @@ -28,6 +28,9 @@ use FireflyIII\Models\Preference; use League\Fractal\TransformerAbstract; use Symfony\Component\HttpFoundation\ParameterBag; +/** + * Class PreferenceTransformer + */ class PreferenceTransformer extends TransformerAbstract { /** @@ -45,6 +48,11 @@ class PreferenceTransformer extends TransformerAbstract /** @var ParameterBag */ protected $parameters; + /** + * PreferenceTransformer constructor. + * + * @param ParameterBag $parameters + */ public function __construct(ParameterBag $parameters) { $this->parameters = $parameters; diff --git a/app/Transformers/TagTransformer.php b/app/Transformers/TagTransformer.php index 19ce472453..3b926de80a 100644 --- a/app/Transformers/TagTransformer.php +++ b/app/Transformers/TagTransformer.php @@ -121,7 +121,7 @@ class TagTransformer extends TransformerAbstract 'tag' => $tag->tag, 'tag_mode' => $tag->tagMode, 'date' => $date, - 'description' => $tag->description === '' ? null : $tag->description, + 'description' => '' === $tag->description ? null : $tag->description, 'latitude' => (float)$tag->latitude, 'longitude' => (float)$tag->longitude, 'zoom_level' => (int)$tag->zoomLevel, diff --git a/app/Transformers/UserTransformer.php b/app/Transformers/UserTransformer.php index dadb23fb94..cca96ecedd 100644 --- a/app/Transformers/UserTransformer.php +++ b/app/Transformers/UserTransformer.php @@ -193,7 +193,7 @@ class UserTransformer extends TransformerAbstract 'updated_at' => $user->updated_at->toAtomString(), 'created_at' => $user->created_at->toAtomString(), 'email' => $user->email, - 'blocked' => (int)$user->blocked === 1, + 'blocked' => 1 === (int)$user->blocked, 'blocked_code' => $user->blocked_code, 'role' => $role, 'links' => [ diff --git a/app/User.php b/app/User.php index 442c9fb290..17a64c29c9 100644 --- a/app/User.php +++ b/app/User.php @@ -61,7 +61,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; * @property bool $isAdmin used in admin user controller. * @property bool $has2FA used in admin user controller. * @property array $prefs used in admin user controller. - * @property string password + * @property string password * @property Collection roles * @property string blocked_code * @property bool blocked @@ -216,7 +216,7 @@ class User extends Authenticatable { $bytes = random_bytes(16); - return (string)bin2hex($bytes); + return bin2hex($bytes); } /** diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php index 5125bb6a90..c16c7430ba 100644 --- a/app/Validation/FireflyValidator.php +++ b/app/Validation/FireflyValidator.php @@ -243,7 +243,9 @@ class FireflyValidator extends Validator } /** - * @param $attribute + * @param string $attribute + * + * @param string $value * * @return bool */ @@ -338,7 +340,7 @@ class FireflyValidator extends Validator $classes = app('config')->get('firefly.rule-triggers'); /** @var TriggerInterface $class */ $class = $classes[$triggerType] ?? false; - if(false === $class) { + if (false === $class) { return false; } @@ -412,7 +414,7 @@ class FireflyValidator extends Validator public function validateUniqueAccountNumberForUser($attribute, $value, $parameters): bool { $accountId = (int)($this->data['id'] ?? 0.0); - if ($accountId === 0) { + if (0 === $accountId) { $accountId = (int)($parameters[0] ?? 0.0); } @@ -421,7 +423,7 @@ class FireflyValidator extends Validator ->where('accounts.user_id', auth()->user()->id) ->where('account_meta.name', 'accountNumber'); - if ((int)$accountId > 0) { + if ($accountId > 0) { // exclude current account from check. $query->where('account_meta.account_id', '!=', $accountId); } @@ -513,66 +515,6 @@ class FireflyValidator extends Validator return true; } - /** - * @param int $index - * - * @return string - */ - private function getRuleActionName(int $index): string - { - $name = $this->data['rule-action'][$index] ?? 'invalid'; - if (!isset($this->data['rule-action'][$index])) { - $name = $this->data['rule-actions'][$index]['name'] ?? 'invalid'; - } - - return $name; - } - - /** - * @param int $index - * - * @return string - */ - private function getRuleActionValue(int $index): string - { - $value = $this->data['rule-action-value'][$index] ?? ''; - if (!isset($this->data['rule-action-value'][$index])) { - $value = $this->data['rule-actions'][$index]['value'] ?? ''; - } - - return $value; - } - - /** - * @param int $index - * - * @return string - */ - private function getRuleTriggerName(int $index): string - { - $name = $this->data['rule-trigger'][$index] ?? 'invalid'; - if (!isset($this->data['rule-trigger'][$index])) { - $name = $this->data['rule-triggers'][$index]['name'] ?? 'invalid'; - } - - return $name; - } - - /** - * @param int $index - * - * @return string - */ - private function getRuleTriggerValue(int $index): string - { - $value = $this->data['rule-trigger-value'][$index] ?? ''; - if (!isset($this->data['rule-trigger-value'][$index])) { - $value = $this->data['rule-triggers'][$index]['value'] ?? ''; - } - - return $value; - } - /** * @param $value * @@ -627,6 +569,7 @@ class FireflyValidator extends Validator $ignore = $existingAccount->id; $value = $this->tryDecrypt($value); + /** @var Collection $set */ $set = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get(); /** @var Account $entry */ foreach ($set as $entry) { @@ -650,6 +593,7 @@ class FireflyValidator extends Validator $ignore = (int)($parameters[0] ?? 0.0); $value = $this->tryDecrypt($value); + /** @var Collection $set */ $set = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)->get(); /** @var Account $entry */ foreach ($set as $entry) { diff --git a/app/Validation/RecurrenceValidation.php b/app/Validation/RecurrenceValidation.php index ad6614a0db..91e4cc47de 100644 --- a/app/Validation/RecurrenceValidation.php +++ b/app/Validation/RecurrenceValidation.php @@ -37,6 +37,39 @@ use Log; */ trait RecurrenceValidation { + /** + * Adds an error to the validator when there are no repetitions in the array of data. + * + * @param Validator $validator + */ + public function validateOneRepetition(Validator $validator): void + { + $data = $validator->getData(); + $repetitions = $data['repetitions'] ?? []; + // need at least one transaction + if (0 === \count($repetitions)) { + $validator->errors()->add('description', (string)trans('validation.at_least_one_repetition')); + } + } + + /** + * Validates that the recurrence has valid repetition information. It either doesn't stop, + * or stops after X times or at X date. Not both of them., + * + * @param Validator $validator + */ + public function validateRecurrenceRepetition(Validator $validator): void + { + $data = $validator->getData(); + $repetitions = $data['nr_of_repetitions'] ?? null; + $repeatUntil = $data['repeat_until'] ?? null; + if (null !== $repetitions && null !== $repeatUntil) { + // expect a date OR count: + $validator->errors()->add('repeat_until', (string)trans('validation.require_repeat_until')); + $validator->errors()->add('nr_of_repetitions', (string)trans('validation.require_repeat_until')); + } + } + /** * @param Validator $validator */ @@ -73,39 +106,6 @@ trait RecurrenceValidation } } - /** - * Adds an error to the validator when there are no repetitions in the array of data. - * - * @param Validator $validator - */ - public function validateOneRepetition(Validator $validator): void - { - $data = $validator->getData(); - $repetitions = $data['repetitions'] ?? []; - // need at least one transaction - if (\count($repetitions) === 0) { - $validator->errors()->add('description', (string)trans('validation.at_least_one_repetition')); - } - } - - /** - * Validates that the recurrence has valid repetition information. It either doesn't stop, - * or stops after X times or at X date. Not both of them., - * - * @param Validator $validator - */ - public function validateRecurrenceRepetition(Validator $validator): void - { - $data = $validator->getData(); - $repetitions = $data['nr_of_repetitions'] ?? null; - $repeatUntil = $data['repeat_until'] ?? null; - if (null !== $repetitions && null !== $repeatUntil) { - // expect a date OR count: - $validator->errors()->add('repeat_until', (string)trans('validation.require_repeat_until')); - $validator->errors()->add('nr_of_repetitions', (string)trans('validation.require_repeat_until')); - } - } - /** * If the repetition type is daily, the moment should be empty. * @@ -145,7 +145,7 @@ trait RecurrenceValidation protected function validateNdom(Validator $validator, int $index, string $moment): void { $parameters = explode(',', $moment); - if (\count($parameters) !== 2) { + if (2 !== \count($parameters)) { $validator->errors()->add(sprintf('repetitions.%d.moment', $index), (string)trans('validation.valid_recurrence_rep_moment')); return; diff --git a/app/Validation/TransactionValidation.php b/app/Validation/TransactionValidation.php index 1d42ead1bf..cac645acdd 100644 --- a/app/Validation/TransactionValidation.php +++ b/app/Validation/TransactionValidation.php @@ -338,13 +338,13 @@ trait TransactionValidation if ($accountId < 1 && '' === $accountName) { return null; } - if ($accountId !== 0) { + if (0 !== $accountId) { // ID belongs to user and is $type account: /** @var AccountRepositoryInterface $repository */ $repository = app(AccountRepositoryInterface::class); $repository->setUser($admin); $set = $repository->getAccountsById([$accountId]); - if ($set->count() === 1) { + if (1 === $set->count()) { /** @var Account $first */ $first = $set->first(); if ($first->accountType->type !== $type) { diff --git a/routes/web.php b/routes/web.php index d68ca517c6..4627af911e 100755 --- a/routes/web.php +++ b/routes/web.php @@ -806,7 +806,6 @@ Route::group( Route::post('update/{rule}', ['uses' => 'Rule\EditController@update', 'as' => 'update']); - } ); diff --git a/tests/Api/V1/Controllers/AvailableBudgetControllerTest.php b/tests/Api/V1/Controllers/AvailableBudgetControllerTest.php index 2e2f3dd750..cf1d849e7e 100644 --- a/tests/Api/V1/Controllers/AvailableBudgetControllerTest.php +++ b/tests/Api/V1/Controllers/AvailableBudgetControllerTest.php @@ -174,7 +174,7 @@ class AvailableBudgetControllerTest extends TestCase // test API - $response = $this->post('/api/v1/available_budgets', $data,['Accept' => 'application/json']); + $response = $this->post('/api/v1/available_budgets', $data, ['Accept' => 'application/json']); $response->assertStatus(500); $response->assertSee('Could not find the indicated currency.'); $response->assertHeader('Content-Type', 'application/json'); diff --git a/tests/Api/V1/Controllers/BillControllerTest.php b/tests/Api/V1/Controllers/BillControllerTest.php index 8621d3779b..774037d255 100644 --- a/tests/Api/V1/Controllers/BillControllerTest.php +++ b/tests/Api/V1/Controllers/BillControllerTest.php @@ -127,6 +127,7 @@ class BillControllerTest extends TestCase /** * Store with minimum amount more than maximum amount + * * @covers \FireflyIII\Api\V1\Controllers\BillController * @covers \FireflyIII\Api\V1\Requests\BillRequest */ diff --git a/tests/Api/V1/Controllers/BudgetLimitControllerTest.php b/tests/Api/V1/Controllers/BudgetLimitControllerTest.php index 5935f47301..d20d9296c5 100644 --- a/tests/Api/V1/Controllers/BudgetLimitControllerTest.php +++ b/tests/Api/V1/Controllers/BudgetLimitControllerTest.php @@ -124,7 +124,7 @@ class BudgetLimitControllerTest extends TestCase 'start' => '2018-01-01', 'end' => '2018-01-31', ]; - $uri = '/api/v1/budget_limits?' . http_build_query($params); + $uri = '/api/v1/budget_limits?' . http_build_query($params); $response = $this->get($uri); $response->assertStatus(200); $response->assertHeader('Content-Type', 'application/vnd.api+json'); @@ -149,9 +149,9 @@ class BudgetLimitControllerTest extends TestCase // call API $params = [ - 'budget_id' => $budget->id, - 'start' => '2018-01-01', - 'end' => '2018-01-31', + 'budget_id' => $budget->id, + 'start' => '2018-01-01', + 'end' => '2018-01-31', ]; $response = $this->get('/api/v1/budget_limits?' . http_build_query($params)); $response->assertStatus(200); diff --git a/tests/Api/V1/Controllers/CurrencyControllerTest.php b/tests/Api/V1/Controllers/CurrencyControllerTest.php index b9f0f64fb6..a72d2d3aa1 100644 --- a/tests/Api/V1/Controllers/CurrencyControllerTest.php +++ b/tests/Api/V1/Controllers/CurrencyControllerTest.php @@ -97,7 +97,8 @@ class CurrencyControllerTest extends TestCase $response = $this->get('/api/v1/currencies'); $response->assertStatus(200); $response->assertJson(['data' => [],]); - $response->assertJson([ + $response->assertJson( + [ 'meta' => [ 'pagination' => [ 'total' => $collection->count(), diff --git a/tests/Api/V1/Controllers/CurrencyExchangeRateControllerTest.php b/tests/Api/V1/Controllers/CurrencyExchangeRateControllerTest.php index d246883ef1..09da194a12 100644 --- a/tests/Api/V1/Controllers/CurrencyExchangeRateControllerTest.php +++ b/tests/Api/V1/Controllers/CurrencyExchangeRateControllerTest.php @@ -103,40 +103,6 @@ class CurrencyExchangeRateControllerTest extends TestCase $response->assertHeader('Content-Type', 'application/vnd.api+json'); } - /** - * @covers \FireflyIII\Api\V1\Controllers\CurrencyExchangeRateController - */ - public function testIndexBadSource(): void - { - // mock repository - $repository = $this->mock(CurrencyRepositoryInterface::class); - $service = $this->mock(ExchangeRateInterface::class); - - $rate = new CurrencyExchangeRate(); - $rate->date = new Carbon(); - $rate->updated_at = new Carbon(); - $rate->created_at = new Carbon(); - $rate->rate = '0.5'; - $rate->to_currency_id = 1; - $rate->from_currency_id = 2; - - // mock calls: - $repository->shouldReceive('setUser')->once(); - $repository->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(null)->once(); - $repository->shouldReceive('findByCodeNull')->withArgs(['USD'])->andReturn(TransactionCurrency::whereCode('USD')->first())->once(); - - // test API - $params = [ - 'from' => 'EUR', - 'to' => 'USD', - 'date' => '2018-01-01', - ]; - $response = $this->get('/api/v1/cer?' . http_build_query($params), ['Accept' => 'application/json']); - $response->assertStatus(500); - $response->assertSee('Unknown source currency.'); - $response->assertHeader('Content-Type', 'application/json'); - } - /** * @covers \FireflyIII\Api\V1\Controllers\CurrencyExchangeRateController */ @@ -170,4 +136,38 @@ class CurrencyExchangeRateControllerTest extends TestCase $response->assertSee('Unknown destination currency.'); $response->assertHeader('Content-Type', 'application/json'); } + + /** + * @covers \FireflyIII\Api\V1\Controllers\CurrencyExchangeRateController + */ + public function testIndexBadSource(): void + { + // mock repository + $repository = $this->mock(CurrencyRepositoryInterface::class); + $service = $this->mock(ExchangeRateInterface::class); + + $rate = new CurrencyExchangeRate(); + $rate->date = new Carbon(); + $rate->updated_at = new Carbon(); + $rate->created_at = new Carbon(); + $rate->rate = '0.5'; + $rate->to_currency_id = 1; + $rate->from_currency_id = 2; + + // mock calls: + $repository->shouldReceive('setUser')->once(); + $repository->shouldReceive('findByCodeNull')->withArgs(['EUR'])->andReturn(null)->once(); + $repository->shouldReceive('findByCodeNull')->withArgs(['USD'])->andReturn(TransactionCurrency::whereCode('USD')->first())->once(); + + // test API + $params = [ + 'from' => 'EUR', + 'to' => 'USD', + 'date' => '2018-01-01', + ]; + $response = $this->get('/api/v1/cer?' . http_build_query($params), ['Accept' => 'application/json']); + $response->assertStatus(500); + $response->assertSee('Unknown source currency.'); + $response->assertHeader('Content-Type', 'application/json'); + } } diff --git a/tests/Api/V1/Controllers/RecurrenceControllerTest.php b/tests/Api/V1/Controllers/RecurrenceControllerTest.php index 83ab310195..ac41bf1309 100644 --- a/tests/Api/V1/Controllers/RecurrenceControllerTest.php +++ b/tests/Api/V1/Controllers/RecurrenceControllerTest.php @@ -749,12 +749,12 @@ class RecurrenceControllerTest extends TestCase } /** - * Submit the minimum amount to store a recurring transaction (using source ID field). + * Add a recurring but refer to an asset as destination. * * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController * @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest */ - public function testStoreFailInvalidWeekly(): void + public function testStoreFailInvalidDestinationId(): void { /** @var Recurrence $recurrence */ $recurrence = $this->user()->recurrences()->first(); @@ -776,6 +776,19 @@ class RecurrenceControllerTest extends TestCase // used by the validator to find the source_id: $accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once() ->andReturn(new Collection([$assetAccount])); + $accountRepos->shouldReceive('getAccountsById')->withArgs([[$assetAccount->id]])->once() + ->andReturn(new Collection([$assetAccount])); + + + // entries used by the transformer + $repository->shouldReceive('getNoteText')->andReturn('Note text'); + $repository->shouldReceive('repetitionDescription')->andReturn('Some description.'); + $repository->shouldReceive('getXOccurrences')->andReturn([]); + + // entries used by the transformer (the fake entry has a category + a budget): + $factory->shouldReceive('findOrCreate')->andReturn(null); + $budgetRepos->shouldReceive('findNull')->andReturn(null); + // data to submit $firstDate = new Carbon; @@ -788,16 +801,17 @@ class RecurrenceControllerTest extends TestCase 'active' => 1, 'transactions' => [ [ - 'amount' => '100', - 'currency_id' => '1', - 'description' => 'Test description', - 'source_id' => '1', + 'amount' => '100', + 'currency_id' => '1', + 'description' => 'Test description', + 'source_id' => '1', + 'destination_id' => $assetAccount->id, ], ], 'repetitions' => [ [ - 'type' => 'weekly', - 'moment' => '8', + 'type' => 'daily', + 'moment' => '', 'skip' => '0', 'weekend' => '1', @@ -811,8 +825,8 @@ class RecurrenceControllerTest extends TestCase [ 'message' => 'The given data was invalid.', 'errors' => [ - 'repetitions.0.moment' => [ - 'Invalid repetition moment for this type of repetition.', + 'transactions.0.destination_id' => [ + 'This value is invalid for this field.', ], ], ] @@ -967,6 +981,79 @@ class RecurrenceControllerTest extends TestCase $response->assertHeader('Content-Type', 'application/json'); } + /** + * Submit the minimum amount to store a recurring transaction (using source ID field). + * + * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController + * @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest + */ + public function testStoreFailInvalidNdomCount(): void + { + /** @var Recurrence $recurrence */ + $recurrence = $this->user()->recurrences()->first(); + + // mock stuff: + $repository = $this->mock(RecurringRepositoryInterface::class); + $factory = $this->mock(CategoryFactory::class); + $budgetRepos = $this->mock(BudgetRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first(); + + // mock calls: + $repository->shouldReceive('setUser'); + $factory->shouldReceive('setUser'); + $budgetRepos->shouldReceive('setUser'); + $accountRepos->shouldReceive('setUser'); + + // used by the validator to find the source_id: + $accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once() + ->andReturn(new Collection([$assetAccount])); + + // data to submit + $firstDate = new Carbon; + $firstDate->addDays(2); + $data = [ + 'type' => 'withdrawal', + 'title' => 'Hello', + 'first_date' => $firstDate->format('Y-m-d'), + 'apply_rules' => 1, + 'active' => 1, + 'transactions' => [ + [ + 'amount' => '100', + 'currency_id' => '1', + 'description' => 'Test description', + 'source_id' => '1', + ], + ], + 'repetitions' => [ + [ + 'type' => 'ndom', + 'moment' => '9', + 'skip' => '0', + 'weekend' => '1', + + ], + ], + ]; + + // test API + $response = $this->post('/api/v1/recurrences', $data, ['Accept' => 'application/json']); + $response->assertExactJson( + [ + 'message' => 'The given data was invalid.', + 'errors' => [ + 'repetitions.0.moment' => [ + 'Invalid repetition moment for this type of repetition.', + ], + ], + ] + ); + $response->assertStatus(422); + $response->assertHeader('Content-Type', 'application/json'); + } + /** * Submit the minimum amount to store a recurring transaction (using source ID field). * @@ -1046,7 +1133,7 @@ class RecurrenceControllerTest extends TestCase * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController * @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest */ - public function testStoreFailInvalidNdomCount(): void + public function testStoreFailInvalidWeekly(): void { /** @var Recurrence $recurrence */ $recurrence = $this->user()->recurrences()->first(); @@ -1088,8 +1175,8 @@ class RecurrenceControllerTest extends TestCase ], 'repetitions' => [ [ - 'type' => 'ndom', - 'moment' => '9', + 'type' => 'weekly', + 'moment' => '8', 'skip' => '0', 'weekend' => '1', @@ -1113,93 +1200,6 @@ class RecurrenceControllerTest extends TestCase $response->assertHeader('Content-Type', 'application/json'); } - /** - * Add a recurring but refer to an asset as destination. - * - * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController - * @covers \FireflyIII\Api\V1\Requests\RecurrenceRequest - */ - public function testStoreFailInvalidDestinationId(): void - { - /** @var Recurrence $recurrence */ - $recurrence = $this->user()->recurrences()->first(); - - // mock stuff: - $repository = $this->mock(RecurringRepositoryInterface::class); - $factory = $this->mock(CategoryFactory::class); - $budgetRepos = $this->mock(BudgetRepositoryInterface::class); - $accountRepos = $this->mock(AccountRepositoryInterface::class); - - $assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first(); - - // mock calls: - $repository->shouldReceive('setUser'); - $factory->shouldReceive('setUser'); - $budgetRepos->shouldReceive('setUser'); - $accountRepos->shouldReceive('setUser'); - - // used by the validator to find the source_id: - $accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once() - ->andReturn(new Collection([$assetAccount])); - $accountRepos->shouldReceive('getAccountsById')->withArgs([[$assetAccount->id]])->once() - ->andReturn(new Collection([$assetAccount])); - - - // entries used by the transformer - $repository->shouldReceive('getNoteText')->andReturn('Note text'); - $repository->shouldReceive('repetitionDescription')->andReturn('Some description.'); - $repository->shouldReceive('getXOccurrences')->andReturn([]); - - // entries used by the transformer (the fake entry has a category + a budget): - $factory->shouldReceive('findOrCreate')->andReturn(null); - $budgetRepos->shouldReceive('findNull')->andReturn(null); - - - // data to submit - $firstDate = new Carbon; - $firstDate->addDays(2); - $data = [ - 'type' => 'withdrawal', - 'title' => 'Hello', - 'first_date' => $firstDate->format('Y-m-d'), - 'apply_rules' => 1, - 'active' => 1, - 'transactions' => [ - [ - 'amount' => '100', - 'currency_id' => '1', - 'description' => 'Test description', - 'source_id' => '1', - 'destination_id' => $assetAccount->id, - ], - ], - 'repetitions' => [ - [ - 'type' => 'daily', - 'moment' => '', - 'skip' => '0', - 'weekend' => '1', - - ], - ], - ]; - - // test API - $response = $this->post('/api/v1/recurrences', $data, ['Accept' => 'application/json']); - $response->assertExactJson( - [ - 'message' => 'The given data was invalid.', - 'errors' => [ - 'transactions.0.destination_id' => [ - 'This value is invalid for this field.', - ], - ], - ] - ); - $response->assertStatus(422); - $response->assertHeader('Content-Type', 'application/json'); - } - /** * Submit without a source account. * diff --git a/tests/Feature/Controllers/Account/CreateControllerTest.php b/tests/Feature/Controllers/Account/CreateControllerTest.php index 8746bbba6e..a378f1bf6a 100644 --- a/tests/Feature/Controllers/Account/CreateControllerTest.php +++ b/tests/Feature/Controllers/Account/CreateControllerTest.php @@ -27,7 +27,6 @@ namespace Tests\Feature\Controllers\Account; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; use FireflyIII\Models\TransactionJournal; -use FireflyIII\Models\TransactionType; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; diff --git a/tests/Feature/Controllers/Account/DeleteControllerTest.php b/tests/Feature/Controllers/Account/DeleteControllerTest.php index 572b4872f1..482df158d7 100644 --- a/tests/Feature/Controllers/Account/DeleteControllerTest.php +++ b/tests/Feature/Controllers/Account/DeleteControllerTest.php @@ -30,8 +30,9 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Support\Collection; -use Tests\TestCase; use Log; +use Tests\TestCase; + /** * * Class DeleteControllerTest @@ -46,6 +47,7 @@ class DeleteControllerTest extends TestCase parent::setUp(); Log::debug(sprintf('Now in %s.', \get_class($this))); } + /** * @covers \FireflyIII\Http\Controllers\Account\DeleteController * @covers \FireflyIII\Http\Controllers\Controller diff --git a/tests/Feature/Controllers/Account/EditControllerTest.php b/tests/Feature/Controllers/Account/EditControllerTest.php index 2dd3cbcde3..ef9951d705 100644 --- a/tests/Feature/Controllers/Account/EditControllerTest.php +++ b/tests/Feature/Controllers/Account/EditControllerTest.php @@ -26,16 +26,16 @@ namespace Tests\Feature\Controllers\Account; use Amount; use FireflyIII\Models\AccountType; -use FireflyIII\Models\Note; use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Support\Collection; +use Log; use Mockery; use Tests\TestCase; -use Log; + /** * * Class EditControllerTest @@ -50,6 +50,7 @@ class EditControllerTest extends TestCase parent::setUp(); Log::debug(sprintf('Now in %s.', \get_class($this))); } + /** * @covers \FireflyIII\Http\Controllers\Account\EditController */ diff --git a/tests/Feature/Controllers/Account/ReconcileControllerTest.php b/tests/Feature/Controllers/Account/ReconcileControllerTest.php index 93fded7b6e..16e6883de9 100644 --- a/tests/Feature/Controllers/Account/ReconcileControllerTest.php +++ b/tests/Feature/Controllers/Account/ReconcileControllerTest.php @@ -32,8 +32,8 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Support\Collection; use Log; -use Tests\TestCase; use Mockery; +use Tests\TestCase; /** * Class ConfigurationControllerTest @@ -217,7 +217,7 @@ class ReconcileControllerTest extends TestCase $journalRepos->shouldReceive('store')->andReturn(new TransactionJournal); $repository->shouldReceive('getReconciliation')->andReturn(new Account); $repository->shouldReceive('findNull')->andReturn(new Account); - $repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(),'currency_id'])->andReturn('1'); + $repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1'); $data = [ 'transactions' => [1, 2, 3], diff --git a/tests/Feature/Controllers/Account/ShowControllerTest.php b/tests/Feature/Controllers/Account/ShowControllerTest.php index 3268405a40..355e3973b4 100644 --- a/tests/Feature/Controllers/Account/ShowControllerTest.php +++ b/tests/Feature/Controllers/Account/ShowControllerTest.php @@ -147,7 +147,7 @@ class ShowControllerTest extends TestCase } /** - * @covers \FireflyIII\Http\Controllers\Account\ShowController + * @covers \FireflyIII\Http\Controllers\Account\ShowController * @expectedExceptionMessage End is after start! */ public function testShowBrokenBadDates(): void @@ -165,7 +165,7 @@ class ShowControllerTest extends TestCase } /** - * @covers \FireflyIII\Http\Controllers\Account\ShowController + * @covers \FireflyIII\Http\Controllers\Account\ShowController * @expectedExceptionMessage Expected a transaction */ public function testShowBrokenInitial(): void diff --git a/tests/Feature/Controllers/Admin/UpdateControllerTest.php b/tests/Feature/Controllers/Admin/UpdateControllerTest.php index 0d9212bb35..8b9b0a2d33 100644 --- a/tests/Feature/Controllers/Admin/UpdateControllerTest.php +++ b/tests/Feature/Controllers/Admin/UpdateControllerTest.php @@ -97,8 +97,8 @@ class UpdateControllerTest extends TestCase FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig); FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration); - $version = config('firefly.version'); - $date = new Carbon; + $version = config('firefly.version'); + $date = new Carbon; $date->subDays(5); $releases = [ new Release(['id' => 'x', 'title' => $version . '.1', 'content' => '', 'updated' => $date]), diff --git a/tests/Feature/Controllers/Admin/UserControllerTest.php b/tests/Feature/Controllers/Admin/UserControllerTest.php index 70d559ff56..298061386e 100644 --- a/tests/Feature/Controllers/Admin/UserControllerTest.php +++ b/tests/Feature/Controllers/Admin/UserControllerTest.php @@ -96,7 +96,7 @@ class UserControllerTest extends TestCase $repository = $this->mock(UserRepositoryInterface::class); //$repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false); $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->times(3)->andReturn(true); - $user = $this->user(); + $user = $this->user(); $repository->shouldReceive('all')->andReturn(new Collection([$user])); $this->be($user); diff --git a/tests/Feature/Controllers/AttachmentControllerTest.php b/tests/Feature/Controllers/AttachmentControllerTest.php index 8b96a9ab78..d7d1d9ef32 100644 --- a/tests/Feature/Controllers/AttachmentControllerTest.php +++ b/tests/Feature/Controllers/AttachmentControllerTest.php @@ -139,7 +139,7 @@ class AttachmentControllerTest extends TestCase */ public function testIndex() { - $repository = $this->mock(AttachmentRepositoryInterface::class); + $repository = $this->mock(AttachmentRepositoryInterface::class); $repository->shouldReceive('get')->andReturn(new Collection([Attachment::first()]))->once(); $repository->shouldReceive('exists')->andReturn(true)->once(); diff --git a/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php b/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php index a7bd6e1f9f..ab9be7b766 100644 --- a/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php +++ b/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php @@ -74,8 +74,8 @@ class TwoFactorControllerTest extends TestCase $falsePreference = new Preference; $falsePreference->data = false; - $langPreference = new Preference; - $langPreference->data = 'en_US'; + $langPreference = new Preference; + $langPreference->data = 'en_US'; Preferences::shouldReceive('get')->withArgs(['twoFactorAuthEnabled', false])->andReturn($falsePreference)->twice(); Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret', null])->andReturn(null)->once(); diff --git a/tests/Feature/Controllers/BillControllerTest.php b/tests/Feature/Controllers/BillControllerTest.php index 8a29efb42a..5f7d22cb33 100644 --- a/tests/Feature/Controllers/BillControllerTest.php +++ b/tests/Feature/Controllers/BillControllerTest.php @@ -27,7 +27,6 @@ use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Models\Bill; use FireflyIII\Models\Rule; -use FireflyIII\Models\RuleGroup; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; @@ -65,9 +64,9 @@ class BillControllerTest extends TestCase public function testCreate(): void { // mock stuff - $attachHelper = $this->mock(AttachmentHelperInterface::class); - $journalRepos = $this->mock(JournalRepositoryInterface::class); - $ruleGroupRepos =$this->mock(RuleGroupRepositoryInterface::class); + $attachHelper = $this->mock(AttachmentHelperInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); $this->be($this->user()); @@ -83,9 +82,9 @@ class BillControllerTest extends TestCase public function testDelete(): void { // mock stuff - $attachHelper = $this->mock(AttachmentHelperInterface::class); - $journalRepos = $this->mock(JournalRepositoryInterface::class); - $ruleGroupRepos =$this->mock(RuleGroupRepositoryInterface::class); + $attachHelper = $this->mock(AttachmentHelperInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); $this->be($this->user()); @@ -101,10 +100,10 @@ class BillControllerTest extends TestCase public function testDestroy(): void { // mock stuff - $attachHelper = $this->mock(AttachmentHelperInterface::class); - $journalRepos = $this->mock(JournalRepositoryInterface::class); - $repository = $this->mock(BillRepositoryInterface::class); - $ruleGroupRepos =$this->mock(RuleGroupRepositoryInterface::class); + $attachHelper = $this->mock(AttachmentHelperInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $repository = $this->mock(BillRepositoryInterface::class); + $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); $repository->shouldReceive('destroy')->andReturn(true); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); @@ -121,9 +120,9 @@ class BillControllerTest extends TestCase public function testEdit(): void { // mock stuff - $attachHelper = $this->mock(AttachmentHelperInterface::class); - $journalRepos = $this->mock(JournalRepositoryInterface::class); - $ruleGroupRepos =$this->mock(RuleGroupRepositoryInterface::class); + $attachHelper = $this->mock(AttachmentHelperInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); $this->be($this->user()); @@ -140,11 +139,11 @@ class BillControllerTest extends TestCase public function testIndex(): void { // mock stuff - $attachHelper = $this->mock(AttachmentHelperInterface::class); - $bill = factory(Bill::class)->make(); - $journalRepos = $this->mock(JournalRepositoryInterface::class); - $repository = $this->mock(BillRepositoryInterface::class); - $ruleGroupRepos =$this->mock(RuleGroupRepositoryInterface::class); + $attachHelper = $this->mock(AttachmentHelperInterface::class); + $bill = factory(Bill::class)->make(); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $repository = $this->mock(BillRepositoryInterface::class); + $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); $collection = new Collection([$bill]); $repository->shouldReceive('getPaginator')->andReturn(new LengthAwarePaginator($collection, 1, 50))->once(); @@ -166,12 +165,12 @@ class BillControllerTest extends TestCase public function testRescan(): void { // mock stuff - $rule = Rule::first(); - $attachHelper = $this->mock(AttachmentHelperInterface::class); - $journal = factory(TransactionJournal::class)->make(); - $journalRepos = $this->mock(JournalRepositoryInterface::class); - $repository = $this->mock(BillRepositoryInterface::class); - $ruleGroupRepos =$this->mock(RuleGroupRepositoryInterface::class); + $rule = Rule::first(); + $attachHelper = $this->mock(AttachmentHelperInterface::class); + $journal = factory(TransactionJournal::class)->make(); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $repository = $this->mock(BillRepositoryInterface::class); + $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); $repository->shouldReceive('getRulesForBill')->andReturn(new Collection([$rule])); @@ -196,10 +195,10 @@ class BillControllerTest extends TestCase public function testRescanInactive(): void { // mock stuff - $attachHelper = $this->mock(AttachmentHelperInterface::class); - $journalRepos = $this->mock(JournalRepositoryInterface::class); - $repository = $this->mock(BillRepositoryInterface::class); - $ruleGroupRepos =$this->mock(RuleGroupRepositoryInterface::class); + $attachHelper = $this->mock(AttachmentHelperInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $repository = $this->mock(BillRepositoryInterface::class); + $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); $this->be($this->user()); @@ -214,11 +213,11 @@ class BillControllerTest extends TestCase public function testShow(): void { // mock stuff - $attachHelper = $this->mock(AttachmentHelperInterface::class); - $journalRepos = $this->mock(JournalRepositoryInterface::class); - $collector = $this->mock(JournalCollectorInterface::class); - $repository = $this->mock(BillRepositoryInterface::class); - $ruleGroupRepos =$this->mock(RuleGroupRepositoryInterface::class); + $attachHelper = $this->mock(AttachmentHelperInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $collector = $this->mock(JournalCollectorInterface::class); + $repository = $this->mock(BillRepositoryInterface::class); + $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); $repository->shouldReceive('getYearAverage')->andReturn('0'); $repository->shouldReceive('getOverallAverage')->andReturn('0'); $repository->shouldReceive('nextExpectedMatch')->andReturn(new Carbon); @@ -252,10 +251,10 @@ class BillControllerTest extends TestCase $this->be($this->user()); $bill = $this->user()->bills()->first(); // mock stuff - $attachHelper = $this->mock(AttachmentHelperInterface::class); - $journalRepos = $this->mock(JournalRepositoryInterface::class); - $repository = $this->mock(BillRepositoryInterface::class); - $ruleGroupRepos =$this->mock(RuleGroupRepositoryInterface::class); + $attachHelper = $this->mock(AttachmentHelperInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $repository = $this->mock(BillRepositoryInterface::class); + $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); $repository->shouldReceive('store')->andReturn($bill); $attachHelper->shouldReceive('saveAttachmentsForModel'); @@ -286,11 +285,11 @@ class BillControllerTest extends TestCase public function testStoreCreateAnother(): void { // mock stuff - $attachHelper = $this->mock(AttachmentHelperInterface::class); - $journalRepos = $this->mock(JournalRepositoryInterface::class); - $repository = $this->mock(BillRepositoryInterface::class); - $ruleGroupRepos =$this->mock(RuleGroupRepositoryInterface::class); - $bill = $this->user()->bills()->first(); + $attachHelper = $this->mock(AttachmentHelperInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $repository = $this->mock(BillRepositoryInterface::class); + $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); + $bill = $this->user()->bills()->first(); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); $repository->shouldReceive('store')->andReturn($bill); $attachHelper->shouldReceive('saveAttachmentsForModel'); @@ -314,41 +313,6 @@ class BillControllerTest extends TestCase $response->assertSessionHas('success'); } - /** - * @covers \FireflyIII\Http\Controllers\BillController::store - * @covers \FireflyIII\Http\Requests\BillFormRequest - * @covers \FireflyIII\Http\Requests\Request - */ - public function testStoreNoGroup(): void - { - // mock stuff - $attachHelper = $this->mock(AttachmentHelperInterface::class); - $journalRepos = $this->mock(JournalRepositoryInterface::class); - $repository = $this->mock(BillRepositoryInterface::class); - $ruleGroupRepos =$this->mock(RuleGroupRepositoryInterface::class); - $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); - $repository->shouldReceive('store')->andReturn(new Bill); - $attachHelper->shouldReceive('saveAttachmentsForModel'); - $attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag); - - $data = [ - 'name' => 'New Bill ' . random_int(1000, 9999), - 'amount_min' => '100', - 'transaction_currency_id' => 1, - 'skip' => 0, - 'create_another' => '1', - 'strict' => 1, - 'amount_max' => '100', - 'date' => '2016-01-01', - 'repeat_freq' => 'monthly', - ]; - $this->session(['bills.create.uri' => 'http://localhost']); - $this->be($this->user()); - $response = $this->post(route('bills.store'), $data); - $response->assertStatus(302); - $response->assertSessionHas('success'); - } - /** * @covers \FireflyIII\Http\Controllers\BillController::store * @covers \FireflyIII\Http\Requests\BillFormRequest @@ -357,10 +321,10 @@ class BillControllerTest extends TestCase public function testStoreError(): void { // mock stuff - $attachHelper = $this->mock(AttachmentHelperInterface::class); - $journalRepos = $this->mock(JournalRepositoryInterface::class); - $repository = $this->mock(BillRepositoryInterface::class); - $ruleGroupRepos =$this->mock(RuleGroupRepositoryInterface::class); + $attachHelper = $this->mock(AttachmentHelperInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $repository = $this->mock(BillRepositoryInterface::class); + $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); $repository->shouldReceive('store')->andReturn(null); @@ -381,6 +345,41 @@ class BillControllerTest extends TestCase $response->assertRedirect(route('bills.create')); } + /** + * @covers \FireflyIII\Http\Controllers\BillController::store + * @covers \FireflyIII\Http\Requests\BillFormRequest + * @covers \FireflyIII\Http\Requests\Request + */ + public function testStoreNoGroup(): void + { + // mock stuff + $attachHelper = $this->mock(AttachmentHelperInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $repository = $this->mock(BillRepositoryInterface::class); + $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); + $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); + $repository->shouldReceive('store')->andReturn(new Bill); + $attachHelper->shouldReceive('saveAttachmentsForModel'); + $attachHelper->shouldReceive('getMessages')->andReturn(new MessageBag); + + $data = [ + 'name' => 'New Bill ' . random_int(1000, 9999), + 'amount_min' => '100', + 'transaction_currency_id' => 1, + 'skip' => 0, + 'create_another' => '1', + 'strict' => 1, + 'amount_max' => '100', + 'date' => '2016-01-01', + 'repeat_freq' => 'monthly', + ]; + $this->session(['bills.create.uri' => 'http://localhost']); + $this->be($this->user()); + $response = $this->post(route('bills.store'), $data); + $response->assertStatus(302); + $response->assertSessionHas('success'); + } + /** * @covers \FireflyIII\Http\Controllers\BillController::update * @covers \FireflyIII\Http\Requests\BillFormRequest @@ -389,10 +388,10 @@ class BillControllerTest extends TestCase public function testUpdate(): void { // mock stuff - $attachHelper = $this->mock(AttachmentHelperInterface::class); - $journalRepos = $this->mock(JournalRepositoryInterface::class); - $repository = $this->mock(BillRepositoryInterface::class); - $ruleGroupRepos =$this->mock(RuleGroupRepositoryInterface::class); + $attachHelper = $this->mock(AttachmentHelperInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $repository = $this->mock(BillRepositoryInterface::class); + $ruleGroupRepos = $this->mock(RuleGroupRepositoryInterface::class); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); $repository->shouldReceive('update')->andReturn(new Bill); $attachHelper->shouldReceive('saveAttachmentsForModel'); diff --git a/tests/Feature/Controllers/Category/ShowControllerTest.php b/tests/Feature/Controllers/Category/ShowControllerTest.php index f6a4eacf11..6e6e1551d2 100644 --- a/tests/Feature/Controllers/Category/ShowControllerTest.php +++ b/tests/Feature/Controllers/Category/ShowControllerTest.php @@ -24,13 +24,9 @@ declare(strict_types=1); namespace Tests\Feature\Controllers\Category; -use Tests\TestCase; -use Log; - use Carbon\Carbon; use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Helpers\Filter\InternalTransferFilter; -use FireflyIII\Models\Category; use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Account\AccountRepositoryInterface; @@ -38,7 +34,10 @@ use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Collection; +use Log; use Navigation; +use Tests\TestCase; + /** * * Class ShowControllerTest @@ -200,7 +199,7 @@ class ShowControllerTest extends TestCase public function testShowEmpty(string $range): void { $latestJournal = $this->user()->transactionJournals() - ->orderBy('date','DESC')->first(); + ->orderBy('date', 'DESC')->first(); Log::debug(sprintf('Test testShowEmpty(%s)', $range)); $journalRepos = $this->mock(JournalRepositoryInterface::class); diff --git a/tests/Feature/Controllers/CurrencyControllerTest.php b/tests/Feature/Controllers/CurrencyControllerTest.php index e39225964d..c2f2dd9a54 100644 --- a/tests/Feature/Controllers/CurrencyControllerTest.php +++ b/tests/Feature/Controllers/CurrencyControllerTest.php @@ -29,8 +29,9 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface; use Illuminate\Support\Collection; use Log; -use Tests\TestCase; use Mockery; +use Tests\TestCase; + /** * Class CurrencyControllerTest * diff --git a/tests/Feature/Controllers/HomeControllerTest.php b/tests/Feature/Controllers/HomeControllerTest.php index a2b68c59b8..73705a6df3 100644 --- a/tests/Feature/Controllers/HomeControllerTest.php +++ b/tests/Feature/Controllers/HomeControllerTest.php @@ -22,11 +22,10 @@ declare(strict_types=1); namespace Tests\Feature\Controllers; -use FireflyIII\Models\TransactionCurrency; -use Mockery; use FireflyIII\Helpers\Collector\JournalCollectorInterface; use FireflyIII\Models\Account; use FireflyIII\Models\AccountType; +use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Bill\BillRepositoryInterface; @@ -34,6 +33,7 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use Illuminate\Support\Collection; use Log; +use Mockery; use Tests\TestCase; /** @@ -111,11 +111,11 @@ class HomeControllerTest extends TestCase public function testIndex(string $range): void { // mock stuff - $account = factory(Account::class)->make(); - $collector = $this->mock(JournalCollectorInterface::class); - $accountRepos = $this->mock(AccountRepositoryInterface::class); - $billRepos = $this->mock(BillRepositoryInterface::class); - $journalRepos = $this->mock(JournalRepositoryInterface::class); + $account = factory(Account::class)->make(); + $collector = $this->mock(JournalCollectorInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $billRepos = $this->mock(BillRepositoryInterface::class); + $journalRepos = $this->mock(JournalRepositoryInterface::class); $currencyRepos = $this->mock(CurrencyRepositoryInterface::class); $journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal); $accountRepos->shouldReceive('count')->andReturn(1); diff --git a/tests/Feature/Controllers/Import/IndexControllerTest.php b/tests/Feature/Controllers/Import/IndexControllerTest.php index 5a9e2931a0..4e9a0852c1 100644 --- a/tests/Feature/Controllers/Import/IndexControllerTest.php +++ b/tests/Feature/Controllers/Import/IndexControllerTest.php @@ -167,7 +167,6 @@ class IndexControllerTest extends TestCase $ynabPrerequisites->shouldReceive('setUser')->times(2); - $repository->shouldReceive('create')->withArgs(['fake'])->andReturn($importJob); $repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'has_prereq'])->andReturn($importJob)->once(); diff --git a/tests/Feature/Controllers/JavascriptControllerTest.php b/tests/Feature/Controllers/JavascriptControllerTest.php index b4f0b30905..b44738fbc3 100644 --- a/tests/Feature/Controllers/JavascriptControllerTest.php +++ b/tests/Feature/Controllers/JavascriptControllerTest.php @@ -107,6 +107,28 @@ class JavascriptControllerTest extends TestCase $response->assertStatus(200); } + /** + * @covers \FireflyIII\Http\Controllers\JavascriptController::variables + * @covers \FireflyIII\Http\Controllers\JavascriptController::getDateRangeConfig + * + * @param string $range + * + * @dataProvider dateRangeProvider + */ + public function testVariablesCustom(string $range): void + { + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $currencyRepos = $this->mock(CurrencyRepositoryInterface::class); + $accountRepos->shouldReceive('findNull')->andReturn(new Account); + $currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1)); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1'); + + $this->be($this->user()); + $this->changeDateRange($this->user(), $range); + $this->session(['is_custom_range' => true]); + $response = $this->get(route('javascript.variables')); + $response->assertStatus(200); + } /** * @covers \FireflyIII\Http\Controllers\JavascriptController::variables @@ -132,27 +154,4 @@ class JavascriptControllerTest extends TestCase $response = $this->get(route('javascript.variables')); $response->assertStatus(200); } - - /** - * @covers \FireflyIII\Http\Controllers\JavascriptController::variables - * @covers \FireflyIII\Http\Controllers\JavascriptController::getDateRangeConfig - * - * @param string $range - * - * @dataProvider dateRangeProvider - */ - public function testVariablesCustom(string $range): void - { - $accountRepos = $this->mock(AccountRepositoryInterface::class); - $currencyRepos = $this->mock(CurrencyRepositoryInterface::class); - $accountRepos->shouldReceive('findNull')->andReturn(new Account); - $currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1)); - $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1'); - - $this->be($this->user()); - $this->changeDateRange($this->user(), $range); - $this->session(['is_custom_range' => true]); - $response = $this->get(route('javascript.variables')); - $response->assertStatus(200); - } } diff --git a/tests/Feature/Controllers/Json/AutoCompleteControllerTest.php b/tests/Feature/Controllers/Json/AutoCompleteControllerTest.php index d35cbe837c..6013a992f2 100644 --- a/tests/Feature/Controllers/Json/AutoCompleteControllerTest.php +++ b/tests/Feature/Controllers/Json/AutoCompleteControllerTest.php @@ -108,23 +108,6 @@ class AutoCompleteControllerTest extends TestCase $response->assertStatus(200); } - - /** - * @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController - */ - public function testCurrencyNames(): void - { - $repository = $this->mock(CurrencyRepositoryInterface::class); - - $currency = TransactionCurrency::find(1); - $repository->shouldReceive('get')->andReturn(new Collection([$currency]))->once(); - - $this->be($this->user()); - $response = $this->get(route('json.currency-names')); - $response->assertStatus(200); - $response->assertExactJson(['Euro']); - } - /** * @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController */ @@ -159,6 +142,22 @@ class AutoCompleteControllerTest extends TestCase $response->assertExactJson([$category->name]); } + /** + * @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController + */ + public function testCurrencyNames(): void + { + $repository = $this->mock(CurrencyRepositoryInterface::class); + + $currency = TransactionCurrency::find(1); + $repository->shouldReceive('get')->andReturn(new Collection([$currency]))->once(); + + $this->be($this->user()); + $response = $this->get(route('json.currency-names')); + $response->assertStatus(200); + $response->assertExactJson(['Euro']); + } + /** * @covers \FireflyIII\Http\Controllers\Json\AutoCompleteController */ diff --git a/tests/Feature/Controllers/Json/BoxControllerTest.php b/tests/Feature/Controllers/Json/BoxControllerTest.php index 377d139d50..23031ea22d 100644 --- a/tests/Feature/Controllers/Json/BoxControllerTest.php +++ b/tests/Feature/Controllers/Json/BoxControllerTest.php @@ -117,9 +117,9 @@ class BoxControllerTest extends TestCase */ public function testBalanceTransactions(): void { - $transaction = new Transaction; + $transaction = new Transaction; $transaction->transaction_currency_id = 1; - $transaction->transaction_amount ='5'; + $transaction->transaction_amount = '5'; $accountRepos = $this->mock(AccountRepositoryInterface::class); $collector = $this->mock(JournalCollectorInterface::class); @@ -171,17 +171,20 @@ class BoxControllerTest extends TestCase /** * @covers \FireflyIII\Http\Controllers\Json\BoxController::netWorth() */ - public function testNetWorthVirtual(): void + public function testNetWorthFuture(): void { - $account = $this->user()->accounts()->first(); - $account->virtual_balance = '1000'; $accountRepos = $this->mock(AccountRepositoryInterface::class); $currencyRepos = $this->mock(CurrencyRepositoryInterface::class); - $accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$account])); + $accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()])); $currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1)); $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1'); $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset'); + $start = new Carbon; + $start->addMonths(6)->startOfMonth(); + $end = clone $start; + $end->endOfMonth(); + $this->session(['start' => $start, 'end' => $end]); $this->be($this->user()); $response = $this->get(route('json.box.net-worth')); $response->assertStatus(200); @@ -207,20 +210,17 @@ class BoxControllerTest extends TestCase /** * @covers \FireflyIII\Http\Controllers\Json\BoxController::netWorth() */ - public function testNetWorthFuture(): void + public function testNetWorthVirtual(): void { - $accountRepos = $this->mock(AccountRepositoryInterface::class); - $currencyRepos = $this->mock(CurrencyRepositoryInterface::class); - $accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$this->user()->accounts()->first()])); + $account = $this->user()->accounts()->first(); + $account->virtual_balance = '1000'; + $accountRepos = $this->mock(AccountRepositoryInterface::class); + $currencyRepos = $this->mock(CurrencyRepositoryInterface::class); + $accountRepos->shouldReceive('getActiveAccountsByType')->andReturn(new Collection([$account])); $currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1)); $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1'); $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('ccAsset'); - $start = new Carbon; - $start->addMonths(6)->startOfMonth(); - $end = clone $start; - $end->endOfMonth(); - $this->session(['start' => $start, 'end' => $end]); $this->be($this->user()); $response = $this->get(route('json.box.net-worth')); $response->assertStatus(200); diff --git a/tests/Feature/Controllers/ProfileControllerTest.php b/tests/Feature/Controllers/ProfileControllerTest.php index 6f157eb889..376e59fa44 100644 --- a/tests/Feature/Controllers/ProfileControllerTest.php +++ b/tests/Feature/Controllers/ProfileControllerTest.php @@ -228,9 +228,9 @@ class ProfileControllerTest extends TestCase $listPref->data = '50'; Preferences::shouldReceive('get')->withArgs(['list-length', '10'])->andReturn($listPref)->once(); - $secretPref= new Preference; + $secretPref = new Preference; $secretPref->data = 'X'; - Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->twice()->andReturn(null,$secretPref); + Preferences::shouldReceive('get')->withArgs(['twoFactorAuthSecret'])->twice()->andReturn(null, $secretPref); // set pref Preferences::shouldReceive('set')->once()->withArgs(['twoFactorAuthEnabled', 1]); @@ -313,7 +313,7 @@ class ProfileControllerTest extends TestCase { $repository = $this->mock(UserRepositoryInterface::class); $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false); - $data = [ + $data = [ 'email' => $this->user()->email, ]; $this->be($this->user()); @@ -467,7 +467,7 @@ class ProfileControllerTest extends TestCase */ public function testRegenerate(): void { - $repository = $this->mock(UserRepositoryInterface::class); + $repository = $this->mock(UserRepositoryInterface::class); $repository->shouldReceive('hasRole')->withArgs([Mockery::any(), 'demo'])->once()->andReturn(false); $token = ''; $currentToken = Preference::where('user_id', $this->user()->id)->where('name', 'access_token')->first(); diff --git a/tests/Feature/Controllers/Rule/CreateControllerTest.php b/tests/Feature/Controllers/Rule/CreateControllerTest.php index 87f54a9436..6d29c4db2e 100644 --- a/tests/Feature/Controllers/Rule/CreateControllerTest.php +++ b/tests/Feature/Controllers/Rule/CreateControllerTest.php @@ -24,7 +24,6 @@ declare(strict_types=1); namespace tests\Feature\Controllers\Rule; -use FireflyIII\Models\Bill; use FireflyIII\Models\Rule; use FireflyIII\Models\TransactionJournal; use FireflyIII\Repositories\Bill\BillRepositoryInterface; diff --git a/tests/Feature/Controllers/Transaction/BulkControllerTest.php b/tests/Feature/Controllers/Transaction/BulkControllerTest.php index d8133c1b41..fa6dfaa31a 100644 --- a/tests/Feature/Controllers/Transaction/BulkControllerTest.php +++ b/tests/Feature/Controllers/Transaction/BulkControllerTest.php @@ -75,32 +75,6 @@ class BulkControllerTest extends TestCase $response->assertSee('