Skip to content

Firefly III: a personal finances manager

Do some code cleanup.

James Cole6967bb003e6c
diff --git a/app/Api/V1/Controllers/AccountController.php b/app/Api/V1/Controllers/AccountController.php
index 9fa6170065..1a962df72f 100644
--- a/app/Api/V1/Controllers/AccountController.php
+++ b/app/Api/V1/Controllers/AccountController.php
@@ -227,10 +227,8 @@ class AccountController extends Controller
if (null !== $limit && $limit > 0) {
$pageSize = $limit;
}
-
$types = $this->mapTransactionTypes($this->parameters->get('type'));
$manager = $this->getManager();
-
/** @var User $admin */
$admin = auth()->user();
@@ -240,7 +238,6 @@ class AccountController extends Controller
$collector->setUser($admin)->setAccounts(new Collection([$account]))
->withAPIInformation()->setLimit($pageSize)->setPage($this->parameters->get('page'))->setTypes($types);
- // set range if necessary:
if (null !== $this->parameters->get('start') && null !== $this->parameters->get('end')) {
$collector->setRange($this->parameters->get('start'), $this->parameters->get('end'));
}
diff --git a/app/Api/V1/Controllers/ConfigurationController.php b/app/Api/V1/Controllers/ConfigurationController.php
index 23b78898a3..cf7423a30c 100644
--- a/app/Api/V1/Controllers/ConfigurationController.php
+++ b/app/Api/V1/Controllers/ConfigurationController.php
@@ -51,7 +51,6 @@ class ConfigurationController extends Controller
parent::__construct();
$this->middleware(
function ($request, $next) {
- /** @noinspection UnusedConstructorDependenciesInspection */
$this->repository = app(UserRepositoryInterface::class);
/** @var User $admin */
$admin = auth()->user();
@@ -109,13 +108,12 @@ class ConfigurationController extends Controller
$lastCheck = app('fireflyconfig')->get('last_update_check');
/** @var Configuration $singleUser */
$singleUser = app('fireflyconfig')->get('single_user_mode');
- $data = [
+
+ return [
'is_demo_site' => null === $isDemoSite ? null : $isDemoSite->data,
'permission_update_check' => null === $updateCheck ? null : (int)$updateCheck->data,
'last_update_check' => null === $lastCheck ? null : (int)$lastCheck->data,
'single_user_mode' => null === $singleUser ? null : $singleUser->data,
];
-
- return $data;
}
}
diff --git a/app/Api/V1/Controllers/Search/AccountController.php b/app/Api/V1/Controllers/Search/AccountController.php
index 72b44ce2ea..43ff8ffa5f 100644
--- a/app/Api/V1/Controllers/Search/AccountController.php
+++ b/app/Api/V1/Controllers/Search/AccountController.php
@@ -22,7 +22,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Search;
-
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Support\Http\Api\AccountFilter;
use FireflyIII\Support\Search\AccountSearch;
@@ -98,5 +97,4 @@ class AccountController extends Controller
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
}
-
-}
\ No newline at end of file
+}
diff --git a/app/Api/V1/Controllers/Search/TransactionController.php b/app/Api/V1/Controllers/Search/TransactionController.php
index 78839e5e23..7febe475e8 100644
--- a/app/Api/V1/Controllers/Search/TransactionController.php
+++ b/app/Api/V1/Controllers/Search/TransactionController.php
@@ -22,11 +22,8 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Search;
-
use FireflyIII\Api\V1\Controllers\Controller;
-use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
-use Illuminate\Http\Response;
/**
* Class TransactionController
@@ -60,9 +57,8 @@ class TransactionController extends Controller
*
* @return void
*/
- public function search(Request $request)
+ public function search(Request $request): void
{
die('the route is present but nobody\'s home.');
}
-
-}
\ No newline at end of file
+}
diff --git a/app/Api/V1/Controllers/Search/TransferController.php b/app/Api/V1/Controllers/Search/TransferController.php
index 587b8649ae..1fac6ba6f6 100644
--- a/app/Api/V1/Controllers/Search/TransferController.php
+++ b/app/Api/V1/Controllers/Search/TransferController.php
@@ -22,16 +22,13 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers\Search;
-
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Api\V1\Requests\Search\TransferRequest;
-use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Support\Search\TransferSearch;
use FireflyIII\Transformers\TransactionGroupTransformer;
use FireflyIII\User;
use Illuminate\Http\JsonResponse;
-use Illuminate\Http\Request;
use Illuminate\Http\Response;
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
use League\Fractal\Resource\Collection as FractalCollection;
@@ -113,4 +110,4 @@ class TransferController extends Controller
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
}
-}
\ No newline at end of file
+}
diff --git a/app/Api/V1/Controllers/SummaryController.php b/app/Api/V1/Controllers/SummaryController.php
index 15cd9c2f13..ca148ffab4 100644
--- a/app/Api/V1/Controllers/SummaryController.php
+++ b/app/Api/V1/Controllers/SummaryController.php
@@ -24,7 +24,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Controllers;
-
use Carbon\Carbon;
use Exception;
use FireflyIII\Api\V1\Requests\DateRequest;
@@ -124,7 +123,6 @@ class SummaryController extends Controller
}
return response()->json($return);
-
}
/**
@@ -151,25 +149,6 @@ class SummaryController extends Controller
return $result;
}
- /**
- * This method will scroll through the results of the spentInPeriodMc() array and return the correct info.
- *
- * @param array $spentInfo
- * @param TransactionCurrency $currency
- *
- * @return string
- */
- private function findInSpentArray(array $spentInfo, TransactionCurrency $currency): string
- {
- foreach ($spentInfo as $array) {
- if ($array['currency_id'] === $currency->id) {
- return (string)$array['amount'];
- }
- }
-
- return '0'; // @codeCoverageIgnore
- }
-
/**
* @param Carbon $start
* @param Carbon $end
@@ -197,7 +176,6 @@ class SummaryController extends Controller
$set = $collector->getExtractedJournals();
/** @var array $transactionJournal */
foreach ($set as $transactionJournal) {
-
$currencyId = (int)$transactionJournal['currency_id'];
$incomes[$currencyId] = $incomes[$currencyId] ?? '0';
$incomes[$currencyId] = bcadd($incomes[$currencyId], bcmul($transactionJournal['amount'], '-1'));
@@ -373,12 +351,15 @@ class SummaryController extends Controller
'value_parsed' => app('amount')->formatFlat($row['currency_symbol'], $row['currency_decimal_places'], $leftToSpend, false),
'local_icon' => 'money',
'sub_title' => (string)trans(
- 'firefly.box_spend_per_day', ['amount' => app('amount')->formatFlat(
- $row['currency_symbol'], $row['currency_decimal_places'], $perDay, false
- )]
+ 'firefly.box_spend_per_day',
+ ['amount' => app('amount')->formatFlat(
+ $row['currency_symbol'],
+ $row['currency_decimal_places'],
+ $perDay,
+ false
+ )]
),
];
-
}
return $return;
}
@@ -442,5 +423,4 @@ class SummaryController extends Controller
return $return;
}
-
}
diff --git a/app/Api/V1/Controllers/TransactionController.php b/app/Api/V1/Controllers/TransactionController.php
index 9e25876dcb..1cb04d03bf 100644
--- a/app/Api/V1/Controllers/TransactionController.php
+++ b/app/Api/V1/Controllers/TransactionController.php
@@ -110,7 +110,6 @@ class TransactionController extends Controller
$resource = new FractalCollection($attachments, $transformer, 'attachments');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
-
}
/**
@@ -215,7 +214,6 @@ class TransactionController extends Controller
$resource = new FractalCollection($events, $transformer, 'piggy_bank_events');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
-
}
/**
@@ -296,7 +294,7 @@ class TransactionController extends Controller
];
return response()->json($response, 422);
- } catch(FireflyException $e) {
+ } catch (FireflyException $e) {
Log::warning('Caught an exception. Return error message.');
Log::error($e->getMessage());
// return bad validation message.
@@ -304,7 +302,7 @@ class TransactionController extends Controller
$response = [
'message' => 'The given data was invalid.',
'errors' => [
- 'transactions.0.description' => [sprintf('Internal exception: %s',$e->getMessage())],
+ 'transactions.0.description' => [sprintf('Internal exception: %s', $e->getMessage())]
],
];
@@ -379,6 +377,5 @@ class TransactionController extends Controller
$resource = new Item($selectedGroup, $transformer, 'transactions');
return response()->json($manager->createData($resource)->toArray())->header('Content-Type', 'application/vnd.api+json');
-
}
}
diff --git a/app/Api/V1/Requests/AvailableBudgetRequest.php b/app/Api/V1/Requests/AvailableBudgetRequest.php
index 8f66dcdcd4..077d077a44 100644
--- a/app/Api/V1/Requests/AvailableBudgetRequest.php
+++ b/app/Api/V1/Requests/AvailableBudgetRequest.php
@@ -64,15 +64,13 @@ class AvailableBudgetRequest extends Request
*/
public function rules(): array
{
- $rules = [
+ return [
'currency_id' => 'numeric|exists:transaction_currencies,id',
'currency_code' => 'min:3|max:3|exists:transaction_currencies,code',
'amount' => 'required|numeric|more:0',
'start' => 'required|date|before:end',
'end' => 'required|date|after:start',
];
-
- return $rules;
}
diff --git a/app/Api/V1/Requests/BillRequest.php b/app/Api/V1/Requests/BillRequest.php
index 31f5967d30..16bdefd292 100644
--- a/app/Api/V1/Requests/BillRequest.php
+++ b/app/Api/V1/Requests/BillRequest.php
@@ -60,7 +60,7 @@ class BillRequest extends Request
$active = $this->boolean('active');
}
- $data = [
+ return [
'name' => $this->string('name'),
'amount_min' => $this->string('amount_min'),
'amount_max' => $this->string('amount_max'),
@@ -72,8 +72,6 @@ class BillRequest extends Request
'active' => $active,
'notes' => $this->nlString('notes'),
];
-
- return $data;
}
/**
diff --git a/app/Api/V1/Requests/RecurrenceStoreRequest.php b/app/Api/V1/Requests/RecurrenceStoreRequest.php
index be57cb06c0..f5a399f76f 100644
--- a/app/Api/V1/Requests/RecurrenceStoreRequest.php
+++ b/app/Api/V1/Requests/RecurrenceStoreRequest.php
@@ -63,7 +63,8 @@ class RecurrenceStoreRequest extends Request
if (null !== $this->get('apply_rules')) {
$applyRules = $this->boolean('apply_rules');
}
- $return = [
+
+ return [
'recurrence' => [
'type' => $this->string('type'),
'title' => $this->string('title'),
@@ -77,8 +78,6 @@ class RecurrenceStoreRequest extends Request
'transactions' => $this->getTransactionData(),
'repetitions' => $this->getRepetitionData(),
];
-
- return $return;
}
/**
diff --git a/app/Api/V1/Requests/RecurrenceUpdateRequest.php b/app/Api/V1/Requests/RecurrenceUpdateRequest.php
index 7397db39ef..6485a1b107 100644
--- a/app/Api/V1/Requests/RecurrenceUpdateRequest.php
+++ b/app/Api/V1/Requests/RecurrenceUpdateRequest.php
@@ -63,7 +63,8 @@ class RecurrenceUpdateRequest extends Request
if (null !== $this->get('apply_rules')) {
$applyRules = $this->boolean('apply_rules');
}
- $return = [
+
+ return [
'recurrence' => [
'type' => $this->nullableString('type'),
'title' => $this->nullableString('title'),
@@ -78,8 +79,6 @@ class RecurrenceUpdateRequest extends Request
'transactions' => $this->getTransactionData(),
'repetitions' => $this->getRepetitionData(),
];
-
- return $return;
}
/**
diff --git a/app/Api/V1/Requests/RuleGroupTestRequest.php b/app/Api/V1/Requests/RuleGroupTestRequest.php
index 4f990d8b00..34f975217b 100644
--- a/app/Api/V1/Requests/RuleGroupTestRequest.php
+++ b/app/Api/V1/Requests/RuleGroupTestRequest.php
@@ -54,7 +54,7 @@ class RuleGroupTestRequest extends Request
*/
public function getTestParameters(): array
{
- $return = [
+ return [
'page' => $this->getPage(),
'start_date' => $this->getDate('start_date'),
'end_date' => $this->getDate('end_date'),
@@ -62,9 +62,6 @@ class RuleGroupTestRequest extends Request
'trigger_limit' => $this->getTriggerLimit(),
'accounts' => $this->getAccounts(),
];
-
-
- return $return;
}
/**
diff --git a/app/Api/V1/Requests/RuleGroupTriggerRequest.php b/app/Api/V1/Requests/RuleGroupTriggerRequest.php
index 476009b79c..059eede3be 100644
--- a/app/Api/V1/Requests/RuleGroupTriggerRequest.php
+++ b/app/Api/V1/Requests/RuleGroupTriggerRequest.php
@@ -54,14 +54,11 @@ class RuleGroupTriggerRequest extends Request
*/
public function getTriggerParameters(): array
{
- $return = [
+ return [
'start_date' => $this->getDate('start_date'),
'end_date' => $this->getDate('end_date'),
'accounts' => $this->getAccounts(),
];
-
-
- return $return;
}
/**
diff --git a/app/Api/V1/Requests/RuleStoreRequest.php b/app/Api/V1/Requests/RuleStoreRequest.php
index dc7fb256f9..5c275c60d7 100644
--- a/app/Api/V1/Requests/RuleStoreRequest.php
+++ b/app/Api/V1/Requests/RuleStoreRequest.php
@@ -65,7 +65,7 @@ class RuleStoreRequest extends Request
$stopProcessing = $this->boolean('stop_processing');
}
- $data = [
+ return [
'title' => $this->string('title'),
'description' => $this->string('description'),
'rule_group_id' => $this->integer('rule_group_id'),
@@ -77,8 +77,6 @@ class RuleStoreRequest extends Request
'triggers' => $this->getRuleTriggers(),
'actions' => $this->getRuleActions(),
];
-
- return $data;
}
/**
@@ -94,7 +92,8 @@ class RuleStoreRequest extends Request
// some triggers and actions require text:
$contextTriggers = implode(',', config('firefly.context-rule-triggers'));
$contextActions = implode(',', config('firefly.context-rule-actions'));
- $rules = [
+
+ return [
'title' => 'required|between:1,100|uniqueObjectForUser:rules,title',
'description' => 'between:1,5000|nullable',
'rule_group_id' => 'required|belongsToUser:rule_groups|required_without:rule_group_title',
@@ -112,8 +111,6 @@ class RuleStoreRequest extends Request
'stop_processing' => [new IsBoolean],
'active' => [new IsBoolean],
];
-
- return $rules;
}
/**
diff --git a/app/Api/V1/Requests/RuleTestRequest.php b/app/Api/V1/Requests/RuleTestRequest.php
index 3aa41ac848..ff481c33d0 100644
--- a/app/Api/V1/Requests/RuleTestRequest.php
+++ b/app/Api/V1/Requests/RuleTestRequest.php
@@ -54,7 +54,7 @@ class RuleTestRequest extends Request
*/
public function getTestParameters(): array
{
- $return = [
+ return [
'page' => $this->getPage(),
'start_date' => $this->getDate('start_date'),
'end_date' => $this->getDate('end_date'),
@@ -62,9 +62,6 @@ class RuleTestRequest extends Request
'trigger_limit' => $this->getTriggerLimit(),
'accounts' => $this->getAccounts(),
];
-
-
- return $return;
}
/**
diff --git a/app/Api/V1/Requests/RuleTriggerRequest.php b/app/Api/V1/Requests/RuleTriggerRequest.php
index 8d4042b0b8..28a2cd9c04 100644
--- a/app/Api/V1/Requests/RuleTriggerRequest.php
+++ b/app/Api/V1/Requests/RuleTriggerRequest.php
@@ -53,14 +53,11 @@ class RuleTriggerRequest extends Request
*/
public function getTriggerParameters(): array
{
- $return = [
+ return [
'start_date' => $this->getDate('start_date'),
'end_date' => $this->getDate('end_date'),
'accounts' => $this->getAccounts(),
];
-
-
- return $return;
}
/**
diff --git a/app/Api/V1/Requests/RuleUpdateRequest.php b/app/Api/V1/Requests/RuleUpdateRequest.php
index 15d05c0032..d8c73d915d 100644
--- a/app/Api/V1/Requests/RuleUpdateRequest.php
+++ b/app/Api/V1/Requests/RuleUpdateRequest.php
@@ -65,7 +65,7 @@ class RuleUpdateRequest extends Request
$stopProcessing = $this->boolean('stop_processing');
}
- $data = [
+ return [
'title' => $this->nullableString('title'),
'description' => $this->nullableString('description'),
'rule_group_id' => $this->nullableInteger('rule_group_id'),
@@ -77,8 +77,6 @@ class RuleUpdateRequest extends Request
'triggers' => $this->getRuleTriggers(),
'actions' => $this->getRuleActions(),
];
-
- return $data;
}
/**
@@ -95,7 +93,8 @@ class RuleUpdateRequest extends Request
// some triggers and actions require text:
$contextTriggers = implode(',', config('firefly.context-rule-triggers'));
$contextActions = implode(',', config('firefly.context-rule-actions'));
- $rules = [
+
+ return [
'title' => sprintf('between:1,100|uniqueObjectForUser:rules,title,%d', $rule->id),
'description' => 'between:1,5000|nullable',
'rule_group_id' => 'belongsToUser:rule_groups',
@@ -113,8 +112,6 @@ class RuleUpdateRequest extends Request
'stop_processing' => [new IsBoolean],
'active' => [new IsBoolean],
];
-
- return $rules;
}
/**
diff --git a/app/Api/V1/Requests/Search/TransferRequest.php b/app/Api/V1/Requests/Search/TransferRequest.php
index 52a046170c..5cfb4d3ead 100644
--- a/app/Api/V1/Requests/Search/TransferRequest.php
+++ b/app/Api/V1/Requests/Search/TransferRequest.php
@@ -22,7 +22,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V1\Requests\Search;
-
use FireflyIII\Api\V1\Requests\Request;
use FireflyIII\Rules\IsTransferAccount;
@@ -55,5 +54,4 @@ class TransferRequest extends Request
'date' => 'required|date',
];
}
-
-}
\ No newline at end of file
+}
diff --git a/app/Api/V1/Requests/TransactionStoreRequest.php b/app/Api/V1/Requests/TransactionStoreRequest.php
index 3b9319dd51..9d34e8ac0c 100644
--- a/app/Api/V1/Requests/TransactionStoreRequest.php
+++ b/app/Api/V1/Requests/TransactionStoreRequest.php
@@ -60,14 +60,13 @@ class TransactionStoreRequest extends Request
public function getAll(): array
{
Log::debug('get all data in TransactionStoreRequest');
- $data = [
+
+ return [
'group_title' => $this->string('group_title'),
'error_if_duplicate_hash' => $this->boolean('error_if_duplicate_hash'),
'apply_rules' => $this->boolean('apply_rules', true),
'transactions' => $this->getTransactionData(),
];
-
- return $data;
}
/**
@@ -78,7 +77,8 @@ class TransactionStoreRequest extends Request
public function rules(): array
{
Log::debug('Collect rules of TransactionStoreRequest');
- $rules = [
+
+ return [
// basic fields for group:
'group_title' => 'between:1,1000|nullable',
'error_if_duplicate_hash' => [new IsBoolean],
@@ -156,8 +156,6 @@ class TransactionStoreRequest extends Request
'transactions.*.invoice_date' => 'date|nullable',
];
- return $rules;
-
}
diff --git a/app/Api/V1/Requests/TransactionUpdateRequest.php b/app/Api/V1/Requests/TransactionUpdateRequest.php
index 422032ba3e..11ccc8598a 100644
--- a/app/Api/V1/Requests/TransactionUpdateRequest.php
+++ b/app/Api/V1/Requests/TransactionUpdateRequest.php
@@ -154,7 +154,7 @@ class TransactionUpdateRequest extends Request
*/
public function rules(): array
{
- $rules = [
+ return [
// basic fields for group:
'group_title' => 'between:1,1000',
'apply_rules' => [new IsBoolean],
@@ -222,8 +222,6 @@ class TransactionUpdateRequest extends Request
'transactions.*.payment_date' => 'date|nullable',
'transactions.*.invoice_date' => 'date|nullable',
];
-
- return $rules;
}
/**
diff --git a/app/Api/V1/Requests/UserStoreRequest.php b/app/Api/V1/Requests/UserStoreRequest.php
index 89680806d0..e9b55980fe 100644
--- a/app/Api/V1/Requests/UserStoreRequest.php
+++ b/app/Api/V1/Requests/UserStoreRequest.php
@@ -69,14 +69,13 @@ class UserStoreRequest extends Request
if (null !== $this->get('blocked')) {
$blocked = $this->boolean('blocked');
}
- $data = [
+
+ return [
'email' => $this->string('email'),
'blocked' => $blocked,
'blocked_code' => $this->string('blocked_code'),
'role' => $this->string('role'),
];
-
- return $data;
}
/**
diff --git a/app/Api/V1/Requests/UserUpdateRequest.php b/app/Api/V1/Requests/UserUpdateRequest.php
index bc3fe9d3bb..ce85ead64f 100644
--- a/app/Api/V1/Requests/UserUpdateRequest.php
+++ b/app/Api/V1/Requests/UserUpdateRequest.php
@@ -69,14 +69,13 @@ class UserUpdateRequest extends Request
if (null !== $this->get('blocked')) {
$blocked = $this->boolean('blocked');
}
- $data = [
+
+ return [
'email' => $this->string('email'),
'blocked' => $blocked,
'blocked_code' => $this->string('blocked_code'),
'role' => $this->string('role'),
];
-
- return $data;
}
/**
@@ -87,14 +86,13 @@ class UserUpdateRequest extends Request
public function rules(): array
{
$user = $this->route()->parameter('user');
- $rules = [
+
+ return [
'email' => sprintf('email|unique:users,email,%d', $user->id),
'blocked' => [new IsBoolean],
'blocked_code' => 'in:email_changed',
'role' => 'in:owner,demo,',
];
-
- return $rules;
}
}
diff --git a/app/Console/Commands/Correction/CorrectOpeningBalanceCurrencies.php b/app/Console/Commands/Correction/CorrectOpeningBalanceCurrencies.php
index fda42940a7..6b1fc6a04f 100644
--- a/app/Console/Commands/Correction/CorrectOpeningBalanceCurrencies.php
+++ b/app/Console/Commands/Correction/CorrectOpeningBalanceCurrencies.php
@@ -111,15 +111,12 @@ class CorrectOpeningBalanceCurrencies extends Command
*/
private function getAccount(TransactionJournal $journal): ?Account
{
- $excluded = [];
$transactions = $journal->transactions()->with(['account', 'account.accountType'])->get();
/** @var Transaction $transaction */
foreach ($transactions as $transaction) {
$account = $transaction->account;
- if (null !== $account) {
- if (AccountType::INITIAL_BALANCE !== $account->accountType->type) {
- return $account;
- }
+ if ((null !== $account) && AccountType::INITIAL_BALANCE !== $account->accountType->type) {
+ return $account;
}
}
diff --git a/app/Console/Commands/Correction/DeleteEmptyGroups.php b/app/Console/Commands/Correction/DeleteEmptyGroups.php
index a9a640de36..f03796d3ce 100644
--- a/app/Console/Commands/Correction/DeleteEmptyGroups.php
+++ b/app/Console/Commands/Correction/DeleteEmptyGroups.php
@@ -25,7 +25,6 @@ namespace FireflyIII\Console\Commands\Correction;
use Exception;
use FireflyIII\Models\TransactionGroup;
-use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command;
use Log;
@@ -59,7 +58,7 @@ class DeleteEmptyGroups extends Command
$start = microtime(true);
$groupIds =
TransactionGroup
- ::leftJoin('transaction_journals','transaction_groups.id','=','transaction_journals.transaction_group_id')
+ ::leftJoin('transaction_journals', 'transaction_groups.id', '=', 'transaction_journals.transaction_group_id')
->whereNull('transaction_journals.id')->get(['transaction_groups.id'])->pluck('id')->toArray();
$total = count($groupIds);
diff --git a/app/Console/Commands/Correction/DeleteOrphanedTransactions.php b/app/Console/Commands/Correction/DeleteOrphanedTransactions.php
index b9611e599c..f741da152e 100644
--- a/app/Console/Commands/Correction/DeleteOrphanedTransactions.php
+++ b/app/Console/Commands/Correction/DeleteOrphanedTransactions.php
@@ -91,8 +91,11 @@ class DeleteOrphanedTransactions extends Command
}
Transaction::where('transaction_journal_id', (int)$transaction->transaction_journal_id)->delete();
$this->line(
- sprintf('Deleted transaction journal #%d because account #%d was already deleted.',
- $transaction->transaction_journal_id, $transaction->account_id)
+ sprintf(
+ 'Deleted transaction journal #%d because account #%d was already deleted.',
+ $transaction->transaction_journal_id,
+ $transaction->account_id
+ )
);
$count++;
}
@@ -134,6 +137,5 @@ class DeleteOrphanedTransactions extends Command
if (0 === $count) {
$this->info('No orphaned transactions.');
}
-
}
}
diff --git a/app/Console/Commands/Correction/FixAccountTypes.php b/app/Console/Commands/Correction/FixAccountTypes.php
index 277d72a0df..6f1e8adb4d 100644
--- a/app/Console/Commands/Correction/FixAccountTypes.php
+++ b/app/Console/Commands/Correction/FixAccountTypes.php
@@ -167,9 +167,12 @@ class FixAccountTypes extends Command
$dest->save();
$this->info(
sprintf(
- 'Transaction journal #%d, destination account changed from #%d ("%s") to #%d ("%s").', $journal->id,
- $oldDest->id, $oldDest->name,
- $result->id, $result->name
+ 'Transaction journal #%d, destination account changed from #%d ("%s") to #%d ("%s").',
+ $journal->id,
+ $oldDest->id,
+ $oldDest->name,
+ $result->id,
+ $result->name
)
);
$this->inspectJournal($journal);
@@ -184,9 +187,12 @@ class FixAccountTypes extends Command
$source->save();
$this->info(
sprintf(
- 'Transaction journal #%d, source account changed from #%d ("%s") to #%d ("%s").', $journal->id,
- $oldSource->id, $oldSource->name,
- $result->id, $result->name
+ 'Transaction journal #%d, source account changed from #%d ("%s") to #%d ("%s").',
+ $journal->id,
+ $oldSource->id,
+ $oldSource->name,
+ $result->id,
+ $result->name
)
);
$this->inspectJournal($journal);
@@ -198,7 +204,6 @@ class FixAccountTypes extends Command
break;
}
-
}
/**
@@ -273,5 +278,4 @@ class FixAccountTypes extends Command
$this->fixJournal($journal, $type, $sourceTransaction, $destTransaction);
}
}
-
}
diff --git a/app/Console/Commands/Correction/FixRecurringTransactions.php b/app/Console/Commands/Correction/FixRecurringTransactions.php
index f9e99f6de1..c64039a6f8 100644
--- a/app/Console/Commands/Correction/FixRecurringTransactions.php
+++ b/app/Console/Commands/Correction/FixRecurringTransactions.php
@@ -51,16 +51,6 @@ class FixRecurringTransactions extends Command
/** @var UserRepositoryInterface */
private $userRepos;
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
diff --git a/app/Console/Commands/Correction/FixUnevenAmount.php b/app/Console/Commands/Correction/FixUnevenAmount.php
index 2001cf0848..6e7ead58a5 100644
--- a/app/Console/Commands/Correction/FixUnevenAmount.php
+++ b/app/Console/Commands/Correction/FixUnevenAmount.php
@@ -94,7 +94,8 @@ class FixUnevenAmount extends Command
if (null === $source) {
$this->error(
sprintf(
- 'Journal #%d ("%s") has no source transaction. It will be deleted to maintain database consistency.', $journal->id ?? 0,
+ 'Journal #%d ("%s") has no source transaction. It will be deleted to maintain database consistency.',
+ $journal->id ?? 0,
$journal->description ?? ''
)
);
@@ -113,7 +114,8 @@ class FixUnevenAmount extends Command
if (null === $destination) {
$this->error(
sprintf(
- 'Journal #%d ("%s") has no destination transaction. It will be deleted to maintain database consistency.', $journal->id ?? 0,
+ 'Journal #%d ("%s") has no destination transaction. It will be deleted to maintain database consistency.',
+ $journal->id ?? 0,
$journal->description ?? ''
)
);
diff --git a/app/Console/Commands/DecryptDatabase.php b/app/Console/Commands/DecryptDatabase.php
index 24885712c2..a3733fd1bf 100644
--- a/app/Console/Commands/DecryptDatabase.php
+++ b/app/Console/Commands/DecryptDatabase.php
@@ -92,7 +92,7 @@ class DecryptDatabase extends Command
// A separate routine for preferences:
if ('preferences' === $table) {
// try to json_decrypt the value.
- $value = json_decode($value, true) ?? $value;
+ $value = json_decode($value, true, 512, JSON_THROW_ON_ERROR) ?? $value;
Log::debug(sprintf('Decrypted field "%s" "%s" to "%s" in table "%s" (row #%d)', $field, $original, print_r($value, true), $table, $id));
/** @var Preference $object */
diff --git a/app/Console/Commands/Export/ExportData.php b/app/Console/Commands/Export/ExportData.php
index b2df8e08b4..017c30a505 100644
--- a/app/Console/Commands/Export/ExportData.php
+++ b/app/Console/Commands/Export/ExportData.php
@@ -76,21 +76,12 @@ class ExportData extends Command
/** @var User */
private $user;
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
* @return int
* @throws FireflyException
+ * @throws \League\Csv\CannotInsertRecord
*/
public function handle(): int
{
@@ -206,6 +197,7 @@ class ExportData extends Command
*
* @return Carbon
* @throws FireflyException
+ * @throws \Exception
*/
private function getDateParameter(string $field): Carbon
{
diff --git a/app/Console/Commands/Import/CreateCSVImport.php b/app/Console/Commands/Import/CreateCSVImport.php
index 5583a71c77..d402271c27 100644
--- a/app/Console/Commands/Import/CreateCSVImport.php
+++ b/app/Console/Commands/Import/CreateCSVImport.php
@@ -93,7 +93,7 @@ class CreateCSVImport extends Command
$this->importRepository->setUser($user);
- $configurationData = json_decode(file_get_contents($configuration), true);
+ $configurationData = json_decode(file_get_contents($configuration), true, 512, JSON_THROW_ON_ERROR);
$this->importJob = $this->importRepository->create('file');
@@ -214,7 +214,7 @@ class CreateCSVImport extends Command
return false;
}
- $configurationData = json_decode(file_get_contents($configuration), true);
+ $configurationData = json_decode(file_get_contents($configuration), true, 512, JSON_THROW_ON_ERROR);
if (null === $configurationData) {
$this->errorLine(sprintf('Firefly III cannot read the contents of configuration file "%s" (working directory: "%s").', $configuration, $cwd));
diff --git a/app/Console/Commands/Integrity/RestoreOAuthKeys.php b/app/Console/Commands/Integrity/RestoreOAuthKeys.php
index 67950d8798..ec5f0d9d67 100644
--- a/app/Console/Commands/Integrity/RestoreOAuthKeys.php
+++ b/app/Console/Commands/Integrity/RestoreOAuthKeys.php
@@ -21,8 +21,6 @@
namespace FireflyIII\Console\Commands\Integrity;
-use Artisan;
-use Crypt;
use FireflyIII\Support\System\OAuthKeys;
use Illuminate\Console\Command;
@@ -122,4 +120,4 @@ class RestoreOAuthKeys extends Command
{
OAuthKeys::storeKeysInDB();
}
-}
\ No newline at end of file
+}
diff --git a/app/Console/Commands/ScanAttachments.php b/app/Console/Commands/ScanAttachments.php
index 4546c8c646..60077a1573 100644
--- a/app/Console/Commands/ScanAttachments.php
+++ b/app/Console/Commands/ScanAttachments.php
@@ -64,7 +64,6 @@ class ScanAttachments extends Command
/** @var Attachment $attachment */
foreach ($attachments as $attachment) {
$fileName = $attachment->fileName();
- $decryptedContent = '';
try {
$encryptedContent = $disk->get($fileName);
} catch (FileNotFoundException $e) {
diff --git a/app/Console/Commands/SetLatestVersion.php b/app/Console/Commands/SetLatestVersion.php
index 4eb0ce6285..f18441793a 100644
--- a/app/Console/Commands/SetLatestVersion.php
+++ b/app/Console/Commands/SetLatestVersion.php
@@ -43,16 +43,6 @@ class SetLatestVersion extends Command
*/
protected $signature = 'firefly-iii:set-latest-version {--james-is-cool}';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
/**
* Execute the console command.
*
diff --git a/app/Console/Commands/Tools/Cron.php b/app/Console/Commands/Tools/Cron.php
index b3e9974ff5..1f2b77ce78 100644
--- a/app/Console/Commands/Tools/Cron.php
+++ b/app/Console/Commands/Tools/Cron.php
@@ -100,9 +100,11 @@ class Cron extends Command
/**
* @param bool $force
* @param Carbon|null $date
+ *
* @throws FireflyException
+ * @throws Exception
*/
- private function autoBudgetCronJob(bool $force, ?Carbon $date)
+ private function autoBudgetCronJob(bool $force, ?Carbon $date): void
{
$autoBudget = new AutoBudgetCronjob;
$autoBudget->setForce($force);
diff --git a/app/Console/Commands/Upgrade/AccountCurrencies.php b/app/Console/Commands/Upgrade/AccountCurrencies.php
index 4ac42aaaa6..cbb6d77b1b 100644
--- a/app/Console/Commands/Upgrade/AccountCurrencies.php
+++ b/app/Console/Commands/Upgrade/AccountCurrencies.php
@@ -178,7 +178,8 @@ class AccountCurrencies extends Command
static function (Transaction $transaction) use ($accountCurrency) {
$transaction->transaction_currency_id = $accountCurrency;
$transaction->save();
- });
+ }
+ );
$this->line(sprintf('Account #%d ("%s") now has a correct currency for opening balance.', $account->id, $account->name));
$this->count++;
diff --git a/app/Console/Commands/Upgrade/MigrateRecurrenceMeta.php b/app/Console/Commands/Upgrade/MigrateRecurrenceMeta.php
index 317a9dd157..396a2a27b7 100644
--- a/app/Console/Commands/Upgrade/MigrateRecurrenceMeta.php
+++ b/app/Console/Commands/Upgrade/MigrateRecurrenceMeta.php
@@ -115,7 +115,7 @@ class MigrateRecurrenceMeta extends Command
if ('tags' === $meta->name) {
$array = explode(',', $meta->value);
- $value = json_encode($array);
+ $value = json_encode($array, JSON_THROW_ON_ERROR, 512);
}
RecurrenceTransactionMeta::create(
diff --git a/app/Console/Commands/Upgrade/MigrateToGroups.php b/app/Console/Commands/Upgrade/MigrateToGroups.php
index 4645a4e404..c0f1c68f94 100644
--- a/app/Console/Commands/Upgrade/MigrateToGroups.php
+++ b/app/Console/Commands/Upgrade/MigrateToGroups.php
@@ -302,7 +302,8 @@ class MigrateToGroups extends Command
$this->error(
sprintf(
'Journal #%d has no opposing transaction for transaction #%d. Cannot upgrade this entry.',
- $journal->id, $transaction->id
+ $journal->id,
+ $transaction->id
)
);
continue;
@@ -365,12 +366,20 @@ class MigrateToGroups extends Command
// report on result:
Log::debug(
- sprintf('Migrated journal #%d into group #%d with these journals: #%s',
- $journal->id, $group->id, implode(', #', $group->transactionJournals->pluck('id')->toArray()))
+ sprintf(
+ 'Migrated journal #%d into group #%d with these journals: #%s',
+ $journal->id,
+ $group->id,
+ implode(', #', $group->transactionJournals->pluck('id')->toArray())
+ )
);
$this->line(
- sprintf('Migrated journal #%d into group #%d with these journals: #%s',
- $journal->id, $group->id, implode(', #', $group->transactionJournals->pluck('id')->toArray()))
+ sprintf(
+ 'Migrated journal #%d into group #%d with these journals: #%s',
+ $journal->id,
+ $group->id,
+ implode(', #', $group->transactionJournals->pluck('id')->toArray())
+ )
);
}
@@ -447,5 +456,4 @@ class MigrateToGroups extends Command
{
app('fireflyconfig')->set(self::CONFIG_NAME, true);
}
-
}
diff --git a/app/Console/Commands/Upgrade/MigrateToRules.php b/app/Console/Commands/Upgrade/MigrateToRules.php
index 0286d4b70f..f1ecbd56ec 100644
--- a/app/Console/Commands/Upgrade/MigrateToRules.php
+++ b/app/Console/Commands/Upgrade/MigrateToRules.php
@@ -177,9 +177,9 @@ class MigrateToRules extends Command
}
/**
- * @param RuleGroup $ruleGroup
- * @param Bill $bill
- * @throws FireflyException
+ * @param RuleGroup $ruleGroup
+ * @param Bill $bill
+ * @param Preference $language
*/
private function migrateBill(RuleGroup $ruleGroup, Bill $bill, Preference $language): void
{
diff --git a/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php b/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php
index daa00621bd..7a6a37e5b9 100644
--- a/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php
+++ b/app/Console/Commands/Upgrade/OtherCurrenciesCorrections.php
@@ -40,7 +40,6 @@ use Illuminate\Console\Command;
*/
class OtherCurrenciesCorrections extends Command
{
-
public const CONFIG_NAME = '480_other_currencies';
/**
* The console command description.
@@ -136,8 +135,6 @@ class OtherCurrenciesCorrections extends Command
$this->accountCurrencies[$accountId] = $currency;
return $currency;
-
-
}
/**
@@ -186,8 +183,12 @@ class OtherCurrenciesCorrections extends Command
$currency = $this->getCurrency($account);
if (null === $currency) {
// @codeCoverageIgnoreStart
- $this->error(sprintf('Account #%d ("%s") has no currency preference, so transaction journal #%d can\'t be corrected',
- $account->id, $account->name, $journal->id));
+ $this->error(sprintf(
+ 'Account #%d ("%s") has no currency preference, so transaction journal #%d can\'t be corrected',
+ $account->id,
+ $account->name,
+ $journal->id
+ ));
$this->count++;
return;
diff --git a/app/Console/Commands/Upgrade/RenameAccountMeta.php b/app/Console/Commands/Upgrade/RenameAccountMeta.php
index 493fbd2f97..fef408cc3a 100644
--- a/app/Console/Commands/Upgrade/RenameAccountMeta.php
+++ b/app/Console/Commands/Upgrade/RenameAccountMeta.php
@@ -76,7 +76,7 @@ class RenameAccountMeta extends Command
$count += AccountMeta::where('name', $old)->update(['name' => $new]);
// delete empty entries while we're at it.
- AccountMeta::where('name', $new)->where('data','""')->delete();
+ AccountMeta::where('name', $new)->where('data', '""')->delete();
}
$this->markAsExecuted();
diff --git a/app/Console/Commands/Upgrade/TransferCurrenciesCorrections.php b/app/Console/Commands/Upgrade/TransferCurrenciesCorrections.php
index af19d78ad2..13a674112a 100644
--- a/app/Console/Commands/Upgrade/TransferCurrenciesCorrections.php
+++ b/app/Console/Commands/Upgrade/TransferCurrenciesCorrections.php
@@ -23,7 +23,6 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade;
-
use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
@@ -41,7 +40,6 @@ use Log;
*/
class TransferCurrenciesCorrections extends Command
{
-
public const CONFIG_NAME = '480_transfer_currencies';
/**
* The console command description.
@@ -162,8 +160,6 @@ class TransferCurrenciesCorrections extends Command
$this->accountCurrencies[$accountId] = $result;
return $result;
-
-
}
/**
@@ -297,7 +293,6 @@ class TransferCurrenciesCorrections extends Command
*/
private function updateTransferCurrency(TransactionJournal $transfer): void
{
-
$this->resetInformation();
// @codeCoverageIgnoreStart
@@ -325,7 +320,8 @@ class TransferCurrenciesCorrections extends Command
// @codeCoverageIgnoreStart
if ($this->isNoCurrencyPresent()) {
$this->error(
- sprintf('Source or destination accounts for transaction journal #%d have no currency information. Cannot fix this one.', $transfer->id));
+ sprintf('Source or destination accounts for transaction journal #%d have no currency information. Cannot fix this one.', $transfer->id)
+ );
return;
}
@@ -355,7 +351,6 @@ class TransferCurrenciesCorrections extends Command
// fix journal itself:
$this->fixTransactionJournalCurrency($transfer);
-
}
/**
@@ -367,8 +362,11 @@ class TransferCurrenciesCorrections extends Command
if (null === $this->sourceTransaction->transaction_currency_id && null !== $this->sourceCurrency) {
$this->sourceTransaction
->transaction_currency_id = (int)$this->sourceCurrency->id;
- $message = sprintf('Transaction #%d has no currency setting, now set to %s.',
- $this->sourceTransaction->id, $this->sourceCurrency->code);
+ $message = sprintf(
+ 'Transaction #%d has no currency setting, now set to %s.',
+ $this->sourceTransaction->id,
+ $this->sourceCurrency->code
+ );
Log::debug($message);
$this->line($message);
$this->count++;
@@ -385,8 +383,11 @@ class TransferCurrenciesCorrections extends Command
if (null === $this->destinationTransaction->transaction_currency_id && null !== $this->destinationCurrency) {
$this->destinationTransaction
->transaction_currency_id = (int)$this->destinationCurrency->id;
- $message = sprintf('Transaction #%d has no currency setting, now set to %s.',
- $this->destinationTransaction->id, $this->destinationCurrency->code);
+ $message = sprintf(
+ 'Transaction #%d has no currency setting, now set to %s.',
+ $this->destinationTransaction->id,
+ $this->destinationCurrency->code
+ );
Log::debug($message);
$this->line($message);
$this->count++;
@@ -490,9 +491,13 @@ class TransferCurrenciesCorrections extends Command
sprintf(
'Currency for account "%s" is %s, and currency for account "%s" is also
%s, so transactions #%d and #%d has been verified to be to %s exclusively.',
- $this->destinationAccount->name, $this->destinationCurrency->code,
- $this->sourceAccount->name, $this->sourceCurrency->code,
- $this->sourceTransaction->id, $this->destinationTransaction->id, $this->sourceCurrency->code
+ $this->destinationAccount->name,
+ $this->destinationCurrency->code,
+ $this->sourceAccount->name,
+ $this->sourceCurrency->code,
+ $this->sourceTransaction->id,
+ $this->destinationTransaction->id,
+ $this->sourceCurrency->code
)
);
}
@@ -528,8 +533,11 @@ class TransferCurrenciesCorrections extends Command
$this->sourceTransaction->foreign_amount = bcmul((string)$this->destinationTransaction->foreign_amount, '-1');
$this->sourceTransaction->save();
$this->count++;
- Log::debug(sprintf('Restored foreign amount of source transaction #%d to %s',
- $this->sourceTransaction->id, $this->sourceTransaction->foreign_amount));
+ Log::debug(sprintf(
+ 'Restored foreign amount of source transaction #%d to %s',
+ $this->sourceTransaction->id,
+ $this->sourceTransaction->foreign_amount
+ ));
}
}
@@ -543,8 +551,11 @@ class TransferCurrenciesCorrections extends Command
$this->destinationTransaction->foreign_amount = bcmul((string)$this->sourceTransaction->foreign_amount, '-1');
$this->destinationTransaction->save();
$this->count++;
- Log::debug(sprintf('Restored foreign amount of destination transaction #%d to %s',
- $this->destinationTransaction->id, $this->destinationTransaction->foreign_amount));
+ Log::debug(sprintf(
+ 'Restored foreign amount of destination transaction #%d to %s',
+ $this->destinationTransaction->id,
+ $this->destinationTransaction->foreign_amount
+ ));
}
}
@@ -565,8 +576,11 @@ class TransferCurrenciesCorrections extends Command
// destination account must have a currency preference.
if (null === $this->destinationCurrency) {
- $message = sprintf('Account #%d ("%s") must have currency preference but has none.',
- $this->destinationAccount->id, $this->destinationAccount->name);
+ $message = sprintf(
+ 'Account #%d ("%s") must have currency preference but has none.',
+ $this->destinationAccount->id,
+ $this->destinationAccount->name
+ );
Log::error($message);
$this->error($message);
@@ -575,5 +589,4 @@ class TransferCurrenciesCorrections extends Command
return false;
}
-
}
diff --git a/app/Repositories/TransactionGroup/TransactionGroupRepositoryInterface.php b/app/Repositories/TransactionGroup/TransactionGroupRepositoryInterface.php
index ce0a7e0be1..014f49e7d8 100644
--- a/app/Repositories/TransactionGroup/TransactionGroupRepositoryInterface.php
+++ b/app/Repositories/TransactionGroup/TransactionGroupRepositoryInterface.php
@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\TransactionGroup;
use FireflyIII\Exceptions\DuplicateTransactionException;
+use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Support\NullArrayObject;
use FireflyIII\User;
@@ -135,6 +136,7 @@ interface TransactionGroupRepositoryInterface
*
* @return TransactionGroup
* @throws DuplicateTransactionException
+ * @throws FireflyException
*/
public function store(array $data): TransactionGroup;