Skip to content

Firefly III: a personal finances manager

Various code cleanup.

James Cole5ceef2e9c343
diff --git a/app/Api/V1/Controllers/Models/Transaction/StoreController.php b/app/Api/V1/Controllers/Models/Transaction/StoreController.php
index c46fcac390..dcec81a1ca 100644
--- a/app/Api/V1/Controllers/Models/Transaction/StoreController.php
+++ b/app/Api/V1/Controllers/Models/Transaction/StoreController.php
@@ -94,13 +94,13 @@ class StoreController extends Controller
$validator = Validator::make(
['transactions' => [['description' => $e->getMessage()]]], ['transactions.0.description' => new IsDuplicateTransaction]
);
- throw new ValidationException($validator);
+ throw new ValidationException($validator,0, $e);
} catch (FireflyException $e) {
Log::warning('Caught an exception. Return error message.');
Log::error($e->getMessage());
$message = sprintf('Internal exception: %s', $e->getMessage());
$validator = Validator::make(['transactions' => [['description' => $message]]], ['transactions.0.description' => new IsDuplicateTransaction]);
- throw new ValidationException($validator);
+ throw new ValidationException($validator,0, $e);
}
app('preferences')->mark();
event(new StoredTransactionGroup($transactionGroup, $data['apply_rules'] ?? true));
diff --git a/app/Api/V1/Controllers/Models/TransactionCurrency/DestroyController.php b/app/Api/V1/Controllers/Models/TransactionCurrency/DestroyController.php
index da72def335..c3f377f4ce 100644
--- a/app/Api/V1/Controllers/Models/TransactionCurrency/DestroyController.php
+++ b/app/Api/V1/Controllers/Models/TransactionCurrency/DestroyController.php
@@ -50,13 +50,9 @@ class DestroyController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
- /** @var User $admin */
- $admin = auth()->user();
-
- /** @var CurrencyRepositoryInterface repository */
$this->repository = app(CurrencyRepositoryInterface::class);
$this->userRepository = app(UserRepositoryInterface::class);
- $this->repository->setUser($admin);
+ $this->repository->setUser(auth()->user());
return $next($request);
}
diff --git a/app/Api/V1/Controllers/Models/TransactionCurrency/ListController.php b/app/Api/V1/Controllers/Models/TransactionCurrency/ListController.php
index 36a9bd080c..bfca5cad4a 100644
--- a/app/Api/V1/Controllers/Models/TransactionCurrency/ListController.php
+++ b/app/Api/V1/Controllers/Models/TransactionCurrency/ListController.php
@@ -77,13 +77,9 @@ class ListController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
- /** @var User $admin */
- $admin = auth()->user();
-
- /** @var CurrencyRepositoryInterface repository */
$this->repository = app(CurrencyRepositoryInterface::class);
$this->userRepository = app(UserRepositoryInterface::class);
- $this->repository->setUser($admin);
+ $this->repository->setUser(auth()->user());
return $next($request);
}
diff --git a/app/Api/V1/Controllers/Models/TransactionCurrency/ShowController.php b/app/Api/V1/Controllers/Models/TransactionCurrency/ShowController.php
index efb7605fa3..4bd4fc290c 100644
--- a/app/Api/V1/Controllers/Models/TransactionCurrency/ShowController.php
+++ b/app/Api/V1/Controllers/Models/TransactionCurrency/ShowController.php
@@ -56,12 +56,8 @@ class ShowController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
- /** @var User $admin */
- $admin = auth()->user();
-
- /** @var CurrencyRepositoryInterface repository */
$this->repository = app(CurrencyRepositoryInterface::class);
- $this->repository->setUser($admin);
+ $this->repository->setUser(auth()->user());
return $next($request);
}
diff --git a/app/Api/V1/Controllers/Models/TransactionCurrency/StoreController.php b/app/Api/V1/Controllers/Models/TransactionCurrency/StoreController.php
index e26e2b1fda..16ef964dfc 100644
--- a/app/Api/V1/Controllers/Models/TransactionCurrency/StoreController.php
+++ b/app/Api/V1/Controllers/Models/TransactionCurrency/StoreController.php
@@ -56,13 +56,9 @@ class StoreController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
- /** @var User $admin */
- $admin = auth()->user();
-
- /** @var CurrencyRepositoryInterface repository */
$this->repository = app(CurrencyRepositoryInterface::class);
$this->userRepository = app(UserRepositoryInterface::class);
- $this->repository->setUser($admin);
+ $this->repository->setUser(auth()->user());
return $next($request);
}
diff --git a/app/Api/V1/Controllers/Models/TransactionCurrency/UpdateController.php b/app/Api/V1/Controllers/Models/TransactionCurrency/UpdateController.php
index 8e8641dd46..219620621f 100644
--- a/app/Api/V1/Controllers/Models/TransactionCurrency/UpdateController.php
+++ b/app/Api/V1/Controllers/Models/TransactionCurrency/UpdateController.php
@@ -56,13 +56,9 @@ class UpdateController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
- /** @var User $admin */
- $admin = auth()->user();
-
- /** @var CurrencyRepositoryInterface repository */
$this->repository = app(CurrencyRepositoryInterface::class);
$this->userRepository = app(UserRepositoryInterface::class);
- $this->repository->setUser($admin);
+ $this->repository->setUser(auth()->user());
return $next($request);
}
diff --git a/app/Api/V1/Controllers/System/ConfigurationController.php b/app/Api/V1/Controllers/System/ConfigurationController.php
index da86e0369c..0b84a57933 100644
--- a/app/Api/V1/Controllers/System/ConfigurationController.php
+++ b/app/Api/V1/Controllers/System/ConfigurationController.php
@@ -64,7 +64,7 @@ class ConfigurationController extends Controller
} catch (FireflyException $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
- throw new FireflyException('200030: Could not load config variables.');
+ throw new FireflyException('200030: Could not load config variables.', 0, $e);
}
$staticData = $this->getStaticConfiguration();
$return = [];
diff --git a/app/Api/V1/Controllers/System/UserController.php b/app/Api/V1/Controllers/System/UserController.php
index 2a83429055..5941af752e 100644
--- a/app/Api/V1/Controllers/System/UserController.php
+++ b/app/Api/V1/Controllers/System/UserController.php
@@ -54,7 +54,6 @@ class UserController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
- /** @var UserRepositoryInterface repository */
$this->repository = app(UserRepositoryInterface::class);
return $next($request);
diff --git a/app/Api/V1/Controllers/Webhook/AttemptController.php b/app/Api/V1/Controllers/Webhook/AttemptController.php
index 2f938ebbcc..118480a407 100644
--- a/app/Api/V1/Controllers/Webhook/AttemptController.php
+++ b/app/Api/V1/Controllers/Webhook/AttemptController.php
@@ -53,12 +53,8 @@ class AttemptController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
- /** @var User $admin */
- $admin = auth()->user();
-
- /** @var WebhookRepositoryInterface repository */
$this->repository = app(WebhookRepositoryInterface::class);
- $this->repository->setUser($admin);
+ $this->repository->setUser(auth()->user());
return $next($request);
}
diff --git a/app/Api/V1/Controllers/Webhook/DestroyController.php b/app/Api/V1/Controllers/Webhook/DestroyController.php
index 5c3e2799f7..bb41507ede 100644
--- a/app/Api/V1/Controllers/Webhook/DestroyController.php
+++ b/app/Api/V1/Controllers/Webhook/DestroyController.php
@@ -48,12 +48,8 @@ class DestroyController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
- /** @var User $admin */
- $admin = auth()->user();
-
- /** @var WebhookRepositoryInterface repository */
$this->repository = app(WebhookRepositoryInterface::class);
- $this->repository->setUser($admin);
+ $this->repository->setUser(auth()->user());
return $next($request);
}
diff --git a/app/Api/V1/Controllers/Webhook/MessageController.php b/app/Api/V1/Controllers/Webhook/MessageController.php
index 08005210bb..a863ad1778 100644
--- a/app/Api/V1/Controllers/Webhook/MessageController.php
+++ b/app/Api/V1/Controllers/Webhook/MessageController.php
@@ -49,12 +49,8 @@ class MessageController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
- /** @var User $admin */
- $admin = auth()->user();
-
- /** @var WebhookRepositoryInterface repository */
$this->repository = app(WebhookRepositoryInterface::class);
- $this->repository->setUser($admin);
+ $this->repository->setUser(auth()->user());
return $next($request);
}
diff --git a/app/Api/V1/Controllers/Webhook/ShowController.php b/app/Api/V1/Controllers/Webhook/ShowController.php
index 424f10990e..5fbdf20e37 100644
--- a/app/Api/V1/Controllers/Webhook/ShowController.php
+++ b/app/Api/V1/Controllers/Webhook/ShowController.php
@@ -50,12 +50,8 @@ class ShowController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
- /** @var User $admin */
- $admin = auth()->user();
-
- /** @var WebhookRepositoryInterface repository */
$this->repository = app(WebhookRepositoryInterface::class);
- $this->repository->setUser($admin);
+ $this->repository->setUser(auth()->user());
return $next($request);
}
diff --git a/app/Api/V1/Controllers/Webhook/StoreController.php b/app/Api/V1/Controllers/Webhook/StoreController.php
index 28bfb00b28..f61620e769 100644
--- a/app/Api/V1/Controllers/Webhook/StoreController.php
+++ b/app/Api/V1/Controllers/Webhook/StoreController.php
@@ -47,12 +47,8 @@ class StoreController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
- /** @var User $admin */
- $admin = auth()->user();
-
- /** @var WebhookRepositoryInterface repository */
$this->repository = app(WebhookRepositoryInterface::class);
- $this->repository->setUser($admin);
+ $this->repository->setUser(auth()->user());
return $next($request);
}
diff --git a/app/Api/V1/Controllers/Webhook/SubmitController.php b/app/Api/V1/Controllers/Webhook/SubmitController.php
index c2227b04e5..f81e7efebf 100644
--- a/app/Api/V1/Controllers/Webhook/SubmitController.php
+++ b/app/Api/V1/Controllers/Webhook/SubmitController.php
@@ -27,7 +27,6 @@ use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Jobs\SendWebhookMessage;
use FireflyIII\Models\Webhook;
use FireflyIII\Repositories\Webhook\WebhookRepositoryInterface;
-use FireflyIII\User;
use Illuminate\Http\JsonResponse;
/**
@@ -45,12 +44,8 @@ class SubmitController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
- /** @var User $admin */
- $admin = auth()->user();
-
- /** @var WebhookRepositoryInterface repository */
$this->repository = app(WebhookRepositoryInterface::class);
- $this->repository->setUser($admin);
+ $this->repository->setUser(auth()->user());
return $next($request);
}
diff --git a/app/Api/V1/Controllers/Webhook/UpdateController.php b/app/Api/V1/Controllers/Webhook/UpdateController.php
index e7db643085..d69dccf7b7 100644
--- a/app/Api/V1/Controllers/Webhook/UpdateController.php
+++ b/app/Api/V1/Controllers/Webhook/UpdateController.php
@@ -47,12 +47,8 @@ class UpdateController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
- /** @var User $admin */
- $admin = auth()->user();
-
- /** @var WebhookRepositoryInterface repository */
$this->repository = app(WebhookRepositoryInterface::class);
- $this->repository->setUser($admin);
+ $this->repository->setUser(auth()->user());
return $next($request);
}
diff --git a/app/Api/V1/Middleware/ApiDemoUser.php b/app/Api/V1/Middleware/ApiDemoUser.php
index fd3b1e35b6..46cecc1966 100644
--- a/app/Api/V1/Middleware/ApiDemoUser.php
+++ b/app/Api/V1/Middleware/ApiDemoUser.php
@@ -41,7 +41,7 @@ class ApiDemoUser
*/
public function handle(Request $request, Closure $next)
{
- /** @var User $user */
+ /** @var User|null $user */
$user = $request->user();
if (null === $user) {
diff --git a/app/Api/V1/Requests/Insight/GenericRequest.php b/app/Api/V1/Requests/Insight/GenericRequest.php
index 1f05c08a28..54f71b05a4 100644
--- a/app/Api/V1/Requests/Insight/GenericRequest.php
+++ b/app/Api/V1/Requests/Insight/GenericRequest.php
@@ -86,9 +86,6 @@ class GenericRequest extends FormRequest
*/
private function parseAccounts(): void
{
- if (null === $this->accounts) {
- $this->accounts = new Collection;
- }
if (0 !== $this->accounts->count()) {
return;
}
@@ -121,9 +118,6 @@ class GenericRequest extends FormRequest
*/
private function parseBills(): void
{
- if (null === $this->bills) {
- $this->bills = new Collection;
- }
if (0 !== $this->bills->count()) {
return;
}
@@ -156,9 +150,6 @@ class GenericRequest extends FormRequest
*/
private function parseBudgets(): void
{
- if (null === $this->budgets) {
- $this->budgets = new Collection;
- }
if (0 !== $this->budgets->count()) {
return;
}
@@ -191,9 +182,6 @@ class GenericRequest extends FormRequest
*/
private function parseCategories(): void
{
- if (null === $this->categories) {
- $this->categories = new Collection;
- }
if (0 !== $this->categories->count()) {
return;
}
@@ -284,9 +272,6 @@ class GenericRequest extends FormRequest
*/
private function parseTags(): void
{
- if (null === $this->tags) {
- $this->tags = new Collection;
- }
if (0 !== $this->tags->count()) {
return;
}
@@ -311,7 +296,7 @@ class GenericRequest extends FormRequest
*/
public function rules(): array
{
- // this is cheating but it works:
+ // this is cheating but it works to initialize the collections.
$this->accounts = new Collection;
$this->budgets = new Collection;
$this->categories = new Collection;
diff --git a/app/Api/V1/Requests/Models/Recurrence/StoreRequest.php b/app/Api/V1/Requests/Models/Recurrence/StoreRequest.php
index 99a9d378e5..044b26106d 100644
--- a/app/Api/V1/Requests/Models/Recurrence/StoreRequest.php
+++ b/app/Api/V1/Requests/Models/Recurrence/StoreRequest.php
@@ -79,7 +79,7 @@ class StoreRequest extends FormRequest
{
$return = [];
// transaction data:
- /** @var array $transactions */
+ /** @var array|null $transactions */
$transactions = $this->get('transactions');
if (null === $transactions) {
return [];
@@ -101,7 +101,7 @@ class StoreRequest extends FormRequest
{
$return = [];
// repetition data:
- /** @var array $repetitions */
+ /** @var array|null $repetitions */
$repetitions = $this->get('repetitions');
if (null === $repetitions) {
return [];
diff --git a/app/Api/V1/Requests/Models/Recurrence/UpdateRequest.php b/app/Api/V1/Requests/Models/Recurrence/UpdateRequest.php
index 2c76b46ad1..cab0cc29e7 100644
--- a/app/Api/V1/Requests/Models/Recurrence/UpdateRequest.php
+++ b/app/Api/V1/Requests/Models/Recurrence/UpdateRequest.php
@@ -84,7 +84,7 @@ class UpdateRequest extends FormRequest
{
$return = [];
// repetition data:
- /** @var array $repetitions */
+ /** @var array|null $repetitions */
$repetitions = $this->get('repetitions');
if (null === $repetitions) {
return null;
@@ -126,7 +126,7 @@ class UpdateRequest extends FormRequest
{
$return = [];
// transaction data:
- /** @var array $transactions */
+ /** @var array|null $transactions */
$transactions = $this->get('transactions');
if (null === $transactions) {
return null;
diff --git a/app/Api/V1/Requests/Models/Transaction/UpdateRequest.php b/app/Api/V1/Requests/Models/Transaction/UpdateRequest.php
index 21ae0d8f92..68cefec00b 100644
--- a/app/Api/V1/Requests/Models/Transaction/UpdateRequest.php
+++ b/app/Api/V1/Requests/Models/Transaction/UpdateRequest.php
@@ -150,10 +150,7 @@ class UpdateRequest extends FormRequest
return $return;
}
- /**
- * @var int $index
- * @var array $transaction
- */
+ /** @var array $transaction */
foreach ($this->get('transactions') as $transaction) {
// default response is to update nothing in the transaction:
$current = [];
diff --git a/app/Api/V1/Requests/Models/TransactionLink/UpdateRequest.php b/app/Api/V1/Requests/Models/TransactionLink/UpdateRequest.php
index 143c284056..491782b2de 100644
--- a/app/Api/V1/Requests/Models/TransactionLink/UpdateRequest.php
+++ b/app/Api/V1/Requests/Models/TransactionLink/UpdateRequest.php
@@ -117,12 +117,6 @@ class UpdateRequest extends FormRequest
$validator->errors()->add('outward_id', 'Inward ID must be different from outward ID.');
}
- if (null === $inward) {
- $validator->errors()->add('inward_id', 'This is not a valid inward journal.');
- }
- if (null === $outward) {
- $validator->errors()->add('inward_id', 'This is not a valid outward journal.');
- }
$inDB = $repository->findSpecificLink($existing->linkType, $inward, $outward);
if (null === $inDB) {
return;
diff --git a/app/Console/Commands/Tools/ApplyRules.php b/app/Console/Commands/Tools/ApplyRules.php
index d01e63fba3..dba8126ab7 100644
--- a/app/Console/Commands/Tools/ApplyRules.php
+++ b/app/Console/Commands/Tools/ApplyRules.php
@@ -214,14 +214,6 @@ class ApplyRules extends Command
$finalList = new Collection;
$accountList = explode(',', $accountString);
- // @codeCoverageIgnoreStart
- if (0 === count($accountList)) {
- $this->error('Please use the --accounts option to indicate the accounts to apply rules to.');
-
- return false;
- }
- // @codeCoverageIgnoreEnd
-
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$accountRepository->setUser($this->getUser());
@@ -255,12 +247,7 @@ class ApplyRules extends Command
return true;
}
$ruleGroupList = explode(',', $ruleGroupString);
- // @codeCoverageIgnoreStart
- if (0 === count($ruleGroupList)) {
- // can be empty.
- return true;
- }
- // @codeCoverageIgnoreEnd
+
foreach ($ruleGroupList as $ruleGroupId) {
$ruleGroup = $this->ruleGroupRepository->find((int)$ruleGroupId);
if ($ruleGroup->active) {
@@ -286,14 +273,6 @@ class ApplyRules extends Command
}
$ruleList = explode(',', $ruleString);
- // @codeCoverageIgnoreStart
- if (0 === count($ruleList)) {
- // can be empty.
-
- return true;
- }
- // @codeCoverageIgnoreEnd
-
foreach ($ruleList as $ruleId) {
$rule = $this->ruleRepository->find((int)$ruleId);
if (null !== $rule && $rule->active) {
diff --git a/app/Console/Commands/Tools/Cron.php b/app/Console/Commands/Tools/Cron.php
index d65dc729fc..a1746a2ffa 100644
--- a/app/Console/Commands/Tools/Cron.php
+++ b/app/Console/Commands/Tools/Cron.php
@@ -65,9 +65,8 @@ class Cron extends Command
$date = null;
try {
$date = new Carbon($this->option('date'));
- } catch (InvalidArgumentException | Exception $e) {
+ } catch (InvalidArgumentException $e) {
$this->error(sprintf('"%s" is not a valid date', $this->option('date')));
- $e->getMessage();
}
$force = (bool)$this->option('force');
@@ -127,13 +126,15 @@ class Cron extends Command
$recurring->setDate($date);
}
- $result = $recurring->fire();
-
- if (false === $result) {
- $this->line('The recurring transaction cron job did not fire.');
+ $recurring->fire();
+ if($recurring->jobErrored) {
+ $this->error(sprintf('Error in "create recurring transactions" cron: %s', $recurring->message));
+ }
+ if($recurring->jobFired) {
+ $this->error(sprintf('"Create recurring transactions" cron fired: %s', $recurring->message));
}
- if (true === $result) {
- $this->line('The recurring transaction cron job fired successfully.');
+ if($recurring->jobSucceeded) {
+ $this->error(sprintf('"Create recurring transactions" cron ran with success: %s', $recurring->message));
}
}
@@ -142,7 +143,6 @@ class Cron extends Command
* @param Carbon|null $date
*
* @throws FireflyException
- * @throws Exception
*/
private function autoBudgetCronJob(bool $force, ?Carbon $date): void
{
@@ -153,13 +153,16 @@ class Cron extends Command
$autoBudget->setDate($date);
}
- $result = $autoBudget->fire();
+ $autoBudget->fire();
- if (false === $result) {
- $this->line('The auto budget cron job did not fire.');
+ if($autoBudget->jobErrored) {
+ $this->error(sprintf('Error in "create auto budgets" cron: %s', $autoBudget->message));
+ }
+ if($autoBudget->jobFired) {
+ $this->error(sprintf('"Create auto budgets" cron fired: %s', $autoBudget->message));
}
- if (true === $result) {
- $this->line('The auto budget cron job fired successfully.');
+ if($autoBudget->jobSucceeded) {
+ $this->error(sprintf('"Create auto budgets" cron ran with success: %s', $autoBudget->message));
}
}
@@ -167,6 +170,8 @@ class Cron extends Command
/**
* @param bool $force
* @param Carbon|null $date
+ *
+ * @throws FireflyException
*/
private function telemetryCronJob(bool $force, ?Carbon $date): void
{
@@ -182,13 +187,16 @@ class Cron extends Command
$telemetry->setDate($date);
}
- $result = $telemetry->fire();
+ $telemetry->fire();
- if (false === $result) {
- $this->line('The telemetry cron job did not fire.');
+ if($telemetry->jobErrored) {
+ $this->error(sprintf('Error in "send telemetry" cron: %s', $telemetry->message));
+ }
+ if($telemetry->jobFired) {
+ $this->error(sprintf('"Send telemetry" cron fired: %s', $telemetry->message));
}
- if (true === $result) {
- $this->line('The telemetry cron job fired successfully.');
+ if($telemetry->jobSucceeded) {
+ $this->error(sprintf('"Send telemetry" cron ran with success: %s', $telemetry->message));
}
}
diff --git a/app/Console/Commands/Upgrade/AccountCurrencies.php b/app/Console/Commands/Upgrade/AccountCurrencies.php
index 3c9a11bad7..e56a628672 100644
--- a/app/Console/Commands/Upgrade/AccountCurrencies.php
+++ b/app/Console/Commands/Upgrade/AccountCurrencies.php
@@ -148,7 +148,7 @@ class AccountCurrencies extends Command
}
Log::debug(sprintf('Users currency pref is %s', $defaultCurrencyCode));
- /** @var TransactionCurrency $defaultCurrency */
+ /** @var TransactionCurrency|null $defaultCurrency */
$defaultCurrency = TransactionCurrency::where('code', $defaultCurrencyCode)->first();
if (null === $defaultCurrency) {
diff --git a/app/Console/Commands/Upgrade/AppendBudgetLimitPeriods.php b/app/Console/Commands/Upgrade/AppendBudgetLimitPeriods.php
index b3fb1a3bc2..3f495c2c74 100644
--- a/app/Console/Commands/Upgrade/AppendBudgetLimitPeriods.php
+++ b/app/Console/Commands/Upgrade/AppendBudgetLimitPeriods.php
@@ -73,11 +73,8 @@ class AppendBudgetLimitPeriods extends Command
private function isExecuted(): bool
{
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
- if (null !== $configVar) {
- return (bool)$configVar->data;
- }
- return false; // @codeCoverageIgnore
+ return (bool)$configVar->data;
}
/**
diff --git a/app/Console/Commands/Upgrade/BackToJournals.php b/app/Console/Commands/Upgrade/BackToJournals.php
index a499a83009..832a03f0c2 100644
--- a/app/Console/Commands/Upgrade/BackToJournals.php
+++ b/app/Console/Commands/Upgrade/BackToJournals.php
@@ -87,11 +87,7 @@ class BackToJournals extends Command
private function isMigrated(): bool
{
$configVar = app('fireflyconfig')->get(MigrateToGroups::CONFIG_NAME, false);
- if (null !== $configVar) {
return (bool)$configVar->data;
- }
-
- return false; // @codeCoverageIgnore
}
/**
@@ -100,11 +96,7 @@ class BackToJournals extends Command
private function isExecuted(): bool
{
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
- if (null !== $configVar) {
return (bool)$configVar->data;
- }
-
- return false; // @codeCoverageIgnore
}
/**
diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php
index 7c25441e3b..1d1317511a 100644
--- a/app/Http/Controllers/HomeController.php
+++ b/app/Http/Controllers/HomeController.php
@@ -39,6 +39,7 @@ use Illuminate\Routing\Redirector;
use Illuminate\Support\Collection;
use Illuminate\View\View;
use Log;
+use DB;
/**
* Class HomeController.
diff --git a/app/Models/Account.php b/app/Models/Account.php
index 5714a23d50..44b73d10bf 100644
--- a/app/Models/Account.php
+++ b/app/Models/Account.php
@@ -22,7 +22,6 @@ declare(strict_types=1);
namespace FireflyIII\Models;
-use Carbon\Carbon;
use Eloquent;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
@@ -33,7 +32,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Query\Builder;
-use Illuminate\Support\Collection;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
@@ -53,7 +51,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property int $order
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\AccountMeta[] $accountMeta
* @property-read int|null $account_meta_count
- * @property-read \FireflyIII\Models\AccountType $accountType
+ * @property \FireflyIII\Models\AccountType $accountType
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\Attachment[] $attachments
* @property-read int|null $attachments_count
* @property-read string $account_number
diff --git a/app/Support/Cronjobs/AbstractCronjob.php b/app/Support/Cronjobs/AbstractCronjob.php
index a43005de6c..d1fc16d0e7 100644
--- a/app/Support/Cronjobs/AbstractCronjob.php
+++ b/app/Support/Cronjobs/AbstractCronjob.php
@@ -25,6 +25,7 @@ namespace FireflyIII\Support\Cronjobs;
use Carbon\Carbon;
use Exception;
+use FireflyIII\Exceptions\FireflyException;
/**
* Class AbstractCronjob
@@ -45,8 +46,6 @@ abstract class AbstractCronjob
/**
* AbstractCronjob constructor.
- *
- * @throws Exception
*/
public function __construct()
{
diff --git a/app/Support/FireflyConfig.php b/app/Support/FireflyConfig.php
index de5e3cd02f..6440b655ad 100644
--- a/app/Support/FireflyConfig.php
+++ b/app/Support/FireflyConfig.php
@@ -66,7 +66,7 @@ class FireflyConfig
/**
* @param string $name
- * @param null $default
+ * @param bool|string|int|null $default
*
* @return Configuration|null
* @throws FireflyException
diff --git a/app/Validation/Account/OBValidation.php b/app/Validation/Account/OBValidation.php
index 3efabe83cc..c2bcf617da 100644
--- a/app/Validation/Account/OBValidation.php
+++ b/app/Validation/Account/OBValidation.php
@@ -35,7 +35,7 @@ trait OBValidation
{
/**
* @param int|null $accountId
- * @param $accountName
+ * @param mixed $accountName
*
* @return bool
*/
diff --git a/app/Validation/Account/TransferValidation.php b/app/Validation/Account/TransferValidation.php
index 44459963aa..70554a6f1c 100644
--- a/app/Validation/Account/TransferValidation.php
+++ b/app/Validation/Account/TransferValidation.php
@@ -33,7 +33,7 @@ trait TransferValidation
{
/**
* @param int|null $accountId
- * @param $accountName
+ * @param mixed $accountName
*
* @return bool
*/
diff --git a/app/Validation/AccountValidator.php b/app/Validation/AccountValidator.php
index f70d860706..d98e4d5247 100644
--- a/app/Validation/AccountValidator.php
+++ b/app/Validation/AccountValidator.php
@@ -58,14 +58,12 @@ class AccountValidator
*/
public function __construct()
{
- $this->createMode = false;
- $this->destError = 'No error yet.';
- $this->sourceError = 'No error yet.';
- $this->combinations = config('firefly.source_dests');
- $this->source = null;
- $this->destination = null;
-
- /** @var AccountRepositoryInterface accountRepository */
+ $this->createMode = false;
+ $this->destError = 'No error yet.';
+ $this->sourceError = 'No error yet.';
+ $this->combinations = config('firefly.source_dests');
+ $this->source = null;
+ $this->destination = null;
$this->accountRepository = app(AccountRepositoryInterface::class);
}
diff --git a/app/Validation/AutoBudget/ValidatesAutoBudgetRequest.php b/app/Validation/AutoBudget/ValidatesAutoBudgetRequest.php
index a9c844a115..606bd9bacf 100644
--- a/app/Validation/AutoBudget/ValidatesAutoBudgetRequest.php
+++ b/app/Validation/AutoBudget/ValidatesAutoBudgetRequest.php
@@ -57,7 +57,7 @@ trait ValidatesAutoBudgetRequest
if ('' === $period) {
$validator->errors()->add('auto_budget_period', (string)trans('validation.auto_budget_period_mandatory'));
}
- if (null !== $amount && null !== $currencyId && null !== $currencyCode && '' === $currencyCode && '' === $currencyId) {
+ if (null !== $amount && null !== $currencyId && null !== $currencyCode && '' === $currencyCode && 0 === $currencyId) {
$validator->errors()->add('auto_budget_amount', (string)trans('validation.require_currency_info'));
}
}
diff --git a/app/Validation/CurrencyValidation.php b/app/Validation/CurrencyValidation.php
index b92d9cb3f6..0c48b2a5a2 100644
--- a/app/Validation/CurrencyValidation.php
+++ b/app/Validation/CurrencyValidation.php
@@ -23,6 +23,7 @@
declare(strict_types=1);
namespace FireflyIII\Validation;
+
use Illuminate\Validation\Validator;
use Log;
@@ -45,7 +46,11 @@ trait CurrencyValidation
foreach ($transactions as $index => $transaction) {
// if foreign amount is present, then the currency must be as well.
- if (isset($transaction['foreign_amount']) && !(isset($transaction['foreign_currency_id']) || isset($transaction['foreign_currency_code']))
+ if (array_key_exists('foreign_amount', $transaction)
+ && !(array_key_exists('foreign_currency_id', $transaction)
+ || array_key_exists(
+ 'foreign_currency_code', $transaction
+ ))
&& 0 !== bccomp('0', $transaction['foreign_amount'])
) {
$validator->errors()->add(
@@ -54,7 +59,10 @@ trait CurrencyValidation
);
}
// if the currency is present, then the amount must be present as well.
- if ((isset($transaction['foreign_currency_id']) || isset($transaction['foreign_currency_code'])) && !isset($transaction['foreign_amount'])) {
+ if ((array_key_exists('foreign_currency_id', $transaction) || array_key_exists('foreign_currency_code', $transaction))
+ && !array_key_exists(
+ 'foreign_amount', $transaction
+ )) {
$validator->errors()->add(
'transactions.' . $index . '.foreign_amount',
(string)trans('validation.require_currency_amount')
diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php
index 8aef97bcec..db4523952a 100644
--- a/app/Validation/FireflyValidator.php
+++ b/app/Validation/FireflyValidator.php
@@ -52,14 +52,14 @@ use function is_string;
class FireflyValidator extends Validator
{
/**
- * @param $attribute
- * @param $value
+ * @param mixed $attribute
+ * @param mixed $value
*
* @return bool
*/
public function validate2faCode($attribute, $value): bool
{
- if (!is_string($value) || null === $value || 6 !== strlen($value)) {
+ if (null === $value || !is_string($value) || 6 !== strlen($value)) {
return false;
}
@@ -69,9 +69,9 @@ class FireflyValidator extends Validator
}
/**
- * @param $attribute
- * @param $value
- * @param $parameters
+ * @param mixed $attribute
+ * @param mixed $value
+ * @param mixed $parameters
*
* @return bool
*/
@@ -88,8 +88,8 @@ class FireflyValidator extends Validator
}
/**
- * @param $attribute
- * @param $value
+ * @param mixed $attribute
+ * @param mixed $value
*
* @return bool
*/
@@ -108,14 +108,14 @@ class FireflyValidator extends Validator
}
/**
- * @param $attribute
- * @param $value
+ * @param mixed $attribute
+ * @param mixed $value
*
* @return bool
*/
public function validateIban($attribute, $value): bool
{
- if (!is_string($value) || null === $value || strlen($value) < 6) {
+ if (null === $value || !is_string($value) || strlen($value) < 6) {
return false;
}
// strip spaces
@@ -186,9 +186,9 @@ class FireflyValidator extends Validator
}
/**
- * @param $attribute
- * @param $value
- * @param $parameters
+ * @param mixed $attribute
+ * @param mixed $value
+ * @param mixed $parameters
*
* @return bool
*/
@@ -201,9 +201,9 @@ class FireflyValidator extends Validator
}
/**
- * @param $attribute
- * @param $value
- * @param $parameters
+ * @param mixed $attribute
+ * @param mixed $value
+ * @param mixed $parameters
*
* @return bool
*/
@@ -216,9 +216,9 @@ class FireflyValidator extends Validator
}
/**
- * @param $attribute
- * @param $value
- * @param $parameters
+ * @param mixed $attribute
+ * @param mixed $value
+ * @param mixed $parameters
*
* @return bool
*/
@@ -235,9 +235,9 @@ class FireflyValidator extends Validator
}
/**
- * @param string $attribute
+ * @param string $attribute
*
- * @param string $value
+ * @param string|null $value
*
* @return bool
*/
@@ -309,8 +309,8 @@ class FireflyValidator extends Validator
/**
* $attribute has the format triggers.%d.value.
*
- * @param string $attribute
- * @param string $value
+ * @param string $attribute
+ * @param string|null $value
*
* @return bool
*/
@@ -375,15 +375,15 @@ class FireflyValidator extends Validator
}
/**
- * @param $attribute
- * @param $value
+ * @param mixed $attribute
+ * @param mixed $value
*
* @return bool
*/
public function validateSecurePassword($attribute, $value): bool
{
$verify = false;
- if (isset($this->data['verify_password'])) {
+ if (array_key_exists('verify_password', $this->data)) {
$verify = 1 === (int)$this->data['verify_password'];
}
if ($verify) {
@@ -397,9 +397,9 @@ class FireflyValidator extends Validator
}
/**
- * @param $attribute
- * @param $value
- * @param $parameters
+ * @param mixed $attribute
+ * @param mixed $value
+ * @param mixed $parameters
*
* @return bool
*/
@@ -410,21 +410,20 @@ class FireflyValidator extends Validator
if (!auth()->check()) {
return $this->validateAccountAnonymously();
}
- if (isset($this->data['objectType'])) {
-
+ if (array_key_exists('objectType', $this->data)) {
return $this->validateByAccountTypeString($value, $parameters, $this->data['objectType']);
}
- if (isset($this->data['type'])) {
+ if (array_key_exists('type', $this->data)) {
return $this->validateByAccountTypeString($value, $parameters, $this->data['type']);
}
- if (isset($this->data['account_type_id'])) {
+ if (array_key_exists('account_type_id', $this->data)) {
return $this->validateByAccountTypeId($value, $parameters);
}
$parameterId = $parameters[0] ?? null;
if (null !== $parameterId) {
return $this->validateByParameterId((int)$parameterId, $value);
}
- if (isset($this->data['id'])) {
+ if (array_key_exists('id', $this->data)) {
return $this->validateByAccountId($value);
}
@@ -437,7 +436,7 @@ class FireflyValidator extends Validator
*/
private function validateAccountAnonymously(): bool
{
- if (!isset($this->data['user_id'])) {
+ if (!array_key_exists('user_id',$this->data)) {
return false;
}
@@ -466,7 +465,7 @@ class FireflyValidator extends Validator
*/
private function validateByAccountTypeString(string $value, array $parameters, string $type): bool
{
- /** @var array $search */
+ /** @var array|null $search */
$search = Config::get('firefly.accountTypeByIdentifier.' . $type);
if (null === $search) {
@@ -491,8 +490,8 @@ class FireflyValidator extends Validator
}
/**
- * @param $value
- * @param $parameters
+ * @param mixed $value
+ * @param mixed $parameters
*
* @return bool
*/
@@ -516,7 +515,8 @@ class FireflyValidator extends Validator
}
/**
- * @param $value
+ * @param int $accountId
+ * @param mixed $value
*
* @return bool
*/
@@ -528,7 +528,6 @@ class FireflyValidator extends Validator
$type = $existingAccount->accountType;
$ignore = $existingAccount->id;
- /** @var Collection $set */
$entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
->where('name', $value)
->first();
@@ -537,7 +536,7 @@ class FireflyValidator extends Validator
}
/**
- * @param $value
+ * @param mixed $value
*
* @return bool
*/
@@ -549,7 +548,6 @@ class FireflyValidator extends Validator
$type = $existingAccount->accountType;
$ignore = $existingAccount->id;
- /** @var Collection $set */
$entry = auth()->user()->accounts()->where('account_type_id', $type->id)->where('id', '!=', $ignore)
->where('name', $value)
->first();
@@ -568,9 +566,9 @@ class FireflyValidator extends Validator
}
/**
- * @param $attribute
- * @param $value
- * @param $parameters
+ * @param mixed $attribute
+ * @param mixed $value
+ * @param mixed $parameters
*
* @return bool
*/
@@ -602,6 +600,13 @@ class FireflyValidator extends Validator
return true;
}
+ /**
+ * @param mixed $value
+ * @param mixed $parameters
+ * @param mixed $something
+ *
+ * @return bool
+ */
public function validateUniqueExistingWebhook($value, $parameters, $something): bool
{
$existingId = (int)($something[0] ?? 0);
@@ -614,7 +619,7 @@ class FireflyValidator extends Validator
if (auth()->check()) {
// get existing webhook value:
if (0 !== $existingId) {
- /** @var Webhook $webhook */
+ /** @var Webhook|null $webhook */
$webhook = auth()->user()->webhooks()->find($existingId);
if (null === $webhook) {
return false;
@@ -645,15 +650,15 @@ class FireflyValidator extends Validator
/**
*
- * Validate an object and its unicity. Checks for encryption / encrypted values as well.
+ * Validate an object and its uniqueness. Checks for encryption / encrypted values as well.
*
* parameter 0: the table
* parameter 1: the field
* parameter 2: an id to ignore (when editing)
*
- * @param $attribute
- * @param $value
- * @param $parameters
+ * @param mixed $attribute
+ * @param mixed $value
+ * @param mixed $parameters
*
* @return bool
*/
@@ -667,7 +672,7 @@ class FireflyValidator extends Validator
* ID field, set that field to be the $exclude.
*/
$data = $this->getData();
- if (!isset($parameters[2]) && isset($data['id']) && (int)$data['id'] > 0) {
+ if (!array_key_exists(2, $parameters) && array_key_exists('id', $data) && (int)$data['id'] > 0) {
$exclude = (int)$data['id'];
}
// get entries from table
@@ -686,9 +691,9 @@ class FireflyValidator extends Validator
}
/**
- * @param $attribute
- * @param $value
- * @param $parameters
+ * @param mixed $attribute
+ * @param mixed $value
+ * @param mixed $parameters
*
* @return bool
*/
@@ -707,11 +712,11 @@ class FireflyValidator extends Validator
}
/**
- * @param $attribute
- * @param $value
- * @param $parameters
+ * @param mixed $attribute
+ * @param mixed $value
+ * @param mixed $parameters
*
- * TODO this method does not need a for loop
+ * TODO this method does not need a for loop
*
* @return bool
*/
@@ -738,8 +743,8 @@ class FireflyValidator extends Validator
}
/**
- * @param $value
- * @param $parameters
+ * @param mixed $value
+ * @param mixed $parameters
*
* @return bool
*/
diff --git a/app/Validation/RecurrenceValidation.php b/app/Validation/RecurrenceValidation.php
index 3fa05d77cd..dd4f1d6dbc 100644
--- a/app/Validation/RecurrenceValidation.php
+++ b/app/Validation/RecurrenceValidation.php
@@ -59,7 +59,7 @@ trait RecurrenceValidation
if (null !== $recurrence) {
Log::debug('There is a recurrence in the route.');
// ok so we have a recurrence should be able to extract type somehow.
- /** @var RecurrenceTransaction $first */
+ /** @var RecurrenceTransaction|null $first */
$first = $recurrence->recurrenceTransactions()->first();
if (null !== $first) {
$transactionType = $first->transactionType ? $first->transactionType->type : 'withdrawal';
@@ -91,7 +91,7 @@ trait RecurrenceValidation
continue;
}
// validate source account.
- $sourceId = isset($transaction['source_id']) ? (int)$transaction['source_id'] : null;
+ $sourceId = array_key_exists('source_id', $transaction) ? (int)$transaction['source_id'] : null;
$sourceName = $transaction['source_name'] ?? null;
$validSource = $accountValidator->validateSource($sourceId, $sourceName, null);
@@ -103,7 +103,7 @@ trait RecurrenceValidation
return;
}
// validate destination account
- $destinationId = isset($transaction['destination_id']) ? (int)$transaction['destination_id'] : null;
+ $destinationId = array_key_exists('destination_id', $transaction) ? (int)$transaction['destination_id'] : null;
$destinationName = $transaction['destination_name'] ?? null;
$validDestination = $accountValidator->validateDestination($destinationId, $destinationName, null);
// do something with result:
diff --git a/app/Validation/TransactionValidation.php b/app/Validation/TransactionValidation.php
index 2ea32dae7b..6dd17d06ed 100644
--- a/app/Validation/TransactionValidation.php
+++ b/app/Validation/TransactionValidation.php
@@ -100,9 +100,9 @@ trait TransactionValidation
$accountValidator->setTransactionType($transactionType);
// validate source account.
- $sourceId = isset($transaction['source_id']) ? (int)$transaction['source_id'] : null;
- $sourceName = isset($transaction['source_name']) ? (string)$transaction['source_name'] : null;
- $sourceIban = isset($transaction['source_iban']) ? (string)$transaction['source_iban'] : null;
+ $sourceId = array_key_exists('source_id', $transaction) ? (int)$transaction['source_id'] : null;
+ $sourceName = array_key_exists('source_name', $transaction) ? (string)$transaction['source_name'] : null;
+ $sourceIban = array_key_exists('source_iban', $transaction) ? (string)$transaction['source_iban'] : null;
$validSource = $accountValidator->validateSource($sourceId, $sourceName, $sourceIban);
// do something with result:
@@ -113,9 +113,9 @@ trait TransactionValidation
return;
}
// validate destination account
- $destinationId = isset($transaction['destination_id']) ? (int)$transaction['destination_id'] : null;
- $destinationName = isset($transaction['destination_name']) ? (string)$transaction['destination_name'] : null;
- $destinationIban = isset($transaction['destination_iban']) ? (string)$transaction['destination_iban'] : null;
+ $destinationId = array_key_exists('destination_id', $transaction) ? (int)$transaction['destination_id'] : null;
+ $destinationName = array_key_exists('destination_name', $transaction) ? (string)$transaction['destination_name'] : null;
+ $destinationIban = array_key_exists('destination_iban', $transaction) ? (string)$transaction['destination_iban'] : null;
$validDestination = $accountValidator->validateDestination($destinationId, $destinationName, $destinationIban);
// do something with result:
if (false === $validDestination) {
@@ -155,10 +155,11 @@ trait TransactionValidation
Log::debug('Now validating single account update in validateSingleUpdate()');
// if no account types are given, just skip the check.
- if (!isset($transaction['source_id'])
- && !isset($transaction['source_name'])
- && !isset($transaction['destination_id'])
- && !isset($transaction['destination_name'])) {
+ if (
+ !array_key_exists('source_id', $transaction)
+ && !array_key_exists('source_name', $transaction)
+ && !array_key_exists('destination_id', $transaction)
+ && !array_key_exists('destination_name', $transaction)) {
Log::debug('No account data has been submitted so will not validating account info.');
return;
@@ -362,7 +363,7 @@ trait TransactionValidation
if (0 === $journalId) {
return 'invalid';
}
- /** @var TransactionJournal $journal */
+ /** @var TransactionJournal|null $journal */
$journal = TransactionJournal::with(['transactionType'])->find($journalId);
if (null !== $journal) {
return strtolower($journal->transactionType->type);
diff --git a/database/factories/EmptyFactory.php b/database/factories/EmptyFactory.php
deleted file mode 100644
index 115ac4cd9e..0000000000
--- a/database/factories/EmptyFactory.php
+++ /dev/null
@@ -1,33 +0,0 @@
-<?php
-
-/*
- * EmptyFactory.php
- * Copyright (c) 2021 [email protected]
- *
- * This file is part of Firefly III (https://github.com/firefly-iii).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-declare(strict_types=1);
-/** @var \Illuminate\Database\Eloquent\Factory $factory */
-
-use Faker\Generator as Faker;
-use FireflyIII\User;
-
-$factory->define(User::class, function (Faker $faker) {
- return [
- //
- ];
-});
diff --git a/database/factories/FireflyIII/Models/AccountFactory.php b/database/factories/FireflyIII/Models/AccountFactory.php
deleted file mode 100644
index dc7c13b670..0000000000
--- a/database/factories/FireflyIII/Models/AccountFactory.php
+++ /dev/null
@@ -1,99 +0,0 @@
-<?php
-/*
- * AccountFactory.php
- * Copyright (c) 2020 [email protected]
- *
- * This file is part of Firefly III (https://github.com/firefly-iii).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-declare(strict_types=1);
-
-namespace Database\Factories\FireflyIII\Models;
-
-use FireflyIII\Models\Account;
-use Illuminate\Database\Eloquent\Factories\Factory;
-
-/**
- * Class AccountFactory
- */
-class AccountFactory extends Factory
-{
-
- /**
- * The name of the factory's corresponding model.
- *
- * @var string
- */
- protected $model = Account::class;
-
- /**
- * @return AccountFactory
- */
- public function asset()
- {
- return $this->state(
- function () {
- return [
- 'account_type_id' => 3,
- ];
- }
- );
- }
-
- /**
- * @inheritDoc
- */
- public function definition()
- {
- return [
- 'user_id' => 1,
- 'account_type_id' => 1,
- 'name' => $this->faker->words(3, true),
- 'virtual_balance' => '0',
- 'active' => 1,
- 'encrypted' => 0,
- 'order' => 1,
- ];
- }
-
- /**
- * @return AccountFactory
- */
- public function expense()
- {
- return $this->state(
- function () {
- return [
- 'account_type_id' => 4,
- ];
- }
- );
- }
-
- /**
- * @return AccountFactory
- */
- public function initialBalance()
- {
- return $this->state(
- function () {
- return [
- 'account_type_id' => 6,
- ];
- }
- );
- }
-}
diff --git a/database/factories/FireflyIII/Models/TransactionFactory.php b/database/factories/FireflyIII/Models/TransactionFactory.php
deleted file mode 100644
index 24b706342f..0000000000
--- a/database/factories/FireflyIII/Models/TransactionFactory.php
+++ /dev/null
@@ -1,53 +0,0 @@
-<?php
-/*
- * TransactionFactory.php
- * Copyright (c) 2020 [email protected]
- *
- * This file is part of Firefly III (https://github.com/firefly-iii).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-declare(strict_types=1);
-
-namespace Database\Factories\FireflyIII\Models;
-use FireflyIII\Models\Transaction;
-use Illuminate\Database\Eloquent\Factories\Factory;
-
-/**
- * Class TransactionFactory
- */
-class TransactionFactory extends Factory
-{
- /**
- * The name of the factory's corresponding model.
- *
- * @var string
- */
- protected $model = Transaction::class;
-
- /**
- * Define the model's default state.
- *
- * @return array
- */
- public function definition()
- {
- return [
- 'transaction_journal_id' => 0,
- 'account_id' => 0,
- 'amount' => 5,
- ];
- }
-}
diff --git a/database/factories/FireflyIII/Models/TransactionJournalFactory.php b/database/factories/FireflyIII/Models/TransactionJournalFactory.php
deleted file mode 100644
index 20cb16769b..0000000000
--- a/database/factories/FireflyIII/Models/TransactionJournalFactory.php
+++ /dev/null
@@ -1,123 +0,0 @@
-<?php
-/*
- * TransactionJournalFactory.php
- * Copyright (c) 2020 [email protected]
- *
- * This file is part of Firefly III (https://github.com/firefly-iii).
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
-
-declare(strict_types=1);
-
-namespace Database\Factories\FireflyIII\Models;
-
-use FireflyIII\Models\Account;
-use FireflyIII\Models\Transaction;
-use FireflyIII\Models\TransactionJournal;
-use Illuminate\Database\Eloquent\Factories\Factory;
-
-/**
- * Class TransactionJournalFactory
- */
-class TransactionJournalFactory extends Factory
-{
- /**
- * The name of the factory's corresponding model.
- *
- * @var string
- */
- protected $model = TransactionJournal::class;
-
- /**
- * @return Factory
- */
- public function brokenOpeningBalance()
- {
- return $this->state(
- function () {
- return [
- 'transaction_type_id' => 4,
- ];
- }
- )->afterCreating(
- function (TransactionJournal $journal) {
- $ob1 = Account::factory(Account::class)->initialBalance()->create();
- $ob2 = Account::factory(Account::class)->initialBalance()->create();
-
- Transaction::factory()->create(
- [
- 'account_id' => $ob1->id,
- 'transaction_journal_id' => $journal->id,
- 'amount' => '5',
- ]
- );
- Transaction::factory()->create(
- [
- 'account_id' => $ob2->id,
- 'transaction_journal_id' => $journal->id,
- 'amount' => '5',
- ]
- );
-
- }
- );
- }
-
- /**
- * Define the model's default state.
- *
- * @return array
- */
- public function definition()
- {
- return [
- 'user_id' => 1,
- 'transaction_type_id' => 1,
- 'description' => $this->faker->words(3, true),
- 'tag_count' => 0,
- 'date' => $this->faker->date('Y-m-d'),
- ];
- }
-
- /**
- * @return Factory
- */
- public function openingBalance()
- {
- return $this
- ->state(fn() => ['transaction_type_id' => 4])
- ->afterCreating(
- function (TransactionJournal $journal) {
- // fix factory
- $obAccount = Account::factory(Account::class)->initialBalance()->create();
- $assetAccount = Account::factory(Account::class)->asset()->create();
- Transaction::factory()->create(
- [
- 'account_id' => $obAccount->id,
- 'transaction_journal_id' => $journal->id,
- 'amount' => '5',
- ]
- );
- Transaction::factory()->create(
- [
- 'account_id' => $assetAccount->id,
- 'transaction_journal_id' => $journal->id,
- 'amount' => '-5',
- ]
- );
- }
- );
- }
-}
diff --git a/database/seeders/AccountTypeSeeder.php b/database/seeders/AccountTypeSeeder.php
index c34fb4f663..f22d029426 100644
--- a/database/seeders/AccountTypeSeeder.php
+++ b/database/seeders/AccountTypeSeeder.php
@@ -51,7 +51,7 @@ class AccountTypeSeeder extends Seeder
try {
AccountType::create(['type' => $type]);
} catch (PDOException $e) {
- // dont care.
+ // @ignoreException
}
}
}
diff --git a/database/seeders/LinkTypeSeeder.php b/database/seeders/LinkTypeSeeder.php
index 702abb3f61..00ee9fee54 100644
--- a/database/seeders/LinkTypeSeeder.php
+++ b/database/seeders/LinkTypeSeeder.php
@@ -63,7 +63,7 @@ class LinkTypeSeeder extends Seeder
try {
LinkType::create($type);
} catch (PDOException $e) {
- // dont care
+ // @ignoreException
}
}
}
diff --git a/database/seeders/PermissionSeeder.php b/database/seeders/PermissionSeeder.php
index ab965073b5..7db4e44406 100644
--- a/database/seeders/PermissionSeeder.php
+++ b/database/seeders/PermissionSeeder.php
@@ -49,7 +49,7 @@ class PermissionSeeder extends Seeder
try {
Role::create($role);
} catch (PDOException $e) {
- // dont care
+ // @ignoreException
}
}
}
diff --git a/database/seeders/TransactionCurrencySeeder.php b/database/seeders/TransactionCurrencySeeder.php
index 2e83a1f129..0b68c6588f 100644
--- a/database/seeders/TransactionCurrencySeeder.php
+++ b/database/seeders/TransactionCurrencySeeder.php
@@ -81,7 +81,7 @@ class TransactionCurrencySeeder extends Seeder
try {
TransactionCurrency::create($currency);
} catch (PDOException $e) {
- // dont care
+ // @ignoreException
}
}
}
diff --git a/database/seeders/TransactionTypeSeeder.php b/database/seeders/TransactionTypeSeeder.php
index adab1d38c8..dc0bf3ea06 100644
--- a/database/seeders/TransactionTypeSeeder.php
+++ b/database/seeders/TransactionTypeSeeder.php
@@ -46,7 +46,7 @@ class TransactionTypeSeeder extends Seeder
try {
TransactionType::create(['type' => $type]);
} catch (PDOException $e) {
- // dont care
+ // @ignoreException
}
}
}