Merge pull request #7595 from firefly-iii/qodana-fix

chore: fix various qodana issues
This commit is contained in:
James Cole 2023-06-04 06:30:45 +02:00 committed by GitHub
commit d07705c329
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 56 additions and 106 deletions

View File

@ -81,8 +81,9 @@ class AccountController extends Controller
$query = $data['query']; $query = $data['query'];
$date = $data['date'] ?? today(config('app.timezone')); $date = $data['date'] ?? today(config('app.timezone'));
$return = []; $return = [];
$result = $this->repository->searchAccount((string)$query, $types, $data['limit']); $result = $this->repository->searchAccount((string)$query, $types, $data['limit']);
// TODO this code is duplicated in the V2 Autocomplete controller, which means this code is due to be deprecated.
$defaultCurrency = app('amount')->getDefaultCurrency(); $defaultCurrency = app('amount')->getDefaultCurrency();
/** @var Account $account */ /** @var Account $account */
@ -113,12 +114,12 @@ class AccountController extends Controller
} }
// custom order. // custom order.
$order = [AccountType::ASSET, AccountType::REVENUE, AccountType::EXPENSE];
usort( usort(
$return, $return,
function ($a, $b) use ($order) { function ($a, $b) {
$posA = array_search($a['type'], $order, true); $order = [AccountType::ASSET, AccountType::REVENUE, AccountType::EXPENSE];
$posB = array_search($b['type'], $order, true); $posA = array_search($a['type'], $order, true);
$posB = array_search($b['type'], $order, true);
return $posA - $posB; return $posA - $posB;
} }

View File

@ -113,7 +113,7 @@ class AccountController extends Controller
if (null === $currency) { if (null === $currency) {
$currency = $default; $currency = $default;
} }
$currentSet = [ $currentSet = [
'label' => $account->name, 'label' => $account->name,
'currency_id' => (string)$currency->id, 'currency_id' => (string)$currency->id,
'currency_code' => $currency->code, 'currency_code' => $currency->code,
@ -125,6 +125,7 @@ class AccountController extends Controller
'yAxisID' => 0, // 0, 1, 2 'yAxisID' => 0, // 0, 1, 2
'entries' => [], 'entries' => [],
]; ];
// TODO this code is also present in the V2 chart account controller so this method is due to be deprecated.
$currentStart = clone $start; $currentStart = clone $start;
$range = app('steam')->balanceInRange($account, $start, clone $end); $range = app('steam')->balanceInRange($account, $start, clone $end);
// 2022-10-11 this method no longer converts to float. // 2022-10-11 this method no longer converts to float.

View File

@ -65,9 +65,8 @@ class AccountController extends Controller
* @param Request $request * @param Request $request
* *
* @return JsonResponse|Response * @return JsonResponse|Response
* @throws JsonException
*/ */
public function search(Request $request) public function search(Request $request): JsonResponse|Response
{ {
Log::debug('Now in account search()'); Log::debug('Now in account search()');
$manager = $this->getManager(); $manager = $this->getManager();

View File

@ -55,8 +55,6 @@ class AccountController extends Controller
parent::__construct(); parent::__construct();
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
/** @var User $user */
$user = auth()->user();
$this->repository = app(AccountRepositoryInterface::class); $this->repository = app(AccountRepositoryInterface::class);
$this->adminRepository = app(AdminAccountRepositoryInterface::class); $this->adminRepository = app(AdminAccountRepositoryInterface::class);
@ -113,10 +111,10 @@ class AccountController extends Controller
} }
// custom order. // custom order.
$order = [AccountType::ASSET, AccountType::REVENUE, AccountType::EXPENSE];
usort( usort(
$return, $return,
function ($a, $b) use ($order) { function ($a, $b) {
$order = [AccountType::ASSET, AccountType::REVENUE, AccountType::EXPENSE];
$pos_a = array_search($a['type'], $order, true); $pos_a = array_search($a['type'], $order, true);
$pos_b = array_search($b['type'], $order, true); $pos_b = array_search($b['type'], $order, true);

View File

@ -79,17 +79,11 @@ class AccountCurrencies extends Command
/** /**
* @return bool * @return bool
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
private function isExecuted(): bool private function isExecuted(): bool
{ {
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false); $configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
if (null !== $configVar) { return (bool)$configVar?->data;
return (bool)$configVar->data;
}
return false;
} }
/** /**
@ -122,10 +116,7 @@ class AccountCurrencies extends Command
$this->accountRepos->setUser($account->user); $this->accountRepos->setUser($account->user);
$accountCurrency = (int)$this->accountRepos->getMetaValue($account, 'currency_id'); $accountCurrency = (int)$this->accountRepos->getMetaValue($account, 'currency_id');
$openingBalance = $this->accountRepos->getOpeningBalance($account); $openingBalance = $this->accountRepos->getOpeningBalance($account);
$obCurrency = 0; $obCurrency = (int)$openingBalance?->transaction_currency_id;
if (null !== $openingBalance) {
$obCurrency = (int)$openingBalance->transaction_currency_id;
}
// both 0? set to default currency: // both 0? set to default currency:
if (0 === $accountCurrency && 0 === $obCurrency) { if (0 === $accountCurrency && 0 === $obCurrency) {
@ -158,8 +149,6 @@ class AccountCurrencies extends Command
); );
$this->line(sprintf('Account #%d ("%s") now has a correct currency for opening balance.', $account->id, $account->name)); $this->line(sprintf('Account #%d ("%s") now has a correct currency for opening balance.', $account->id, $account->name));
$this->count++; $this->count++;
return;
} }
} }

View File

@ -107,6 +107,7 @@ class AccountFactory
Log::debug(sprintf('Now in AccountFactory::find("%s", "%s")', $accountName, $accountType)); Log::debug(sprintf('Now in AccountFactory::find("%s", "%s")', $accountName, $accountType));
$type = AccountType::whereType($accountType)->first(); $type = AccountType::whereType($accountType)->first();
/** @var Account|null */
return $this->user->accounts()->where('account_type_id', $type->id)->where('name', $accountName)->first(); return $this->user->accounts()->where('account_type_id', $type->id)->where('name', $accountName)->first();
} }
@ -294,7 +295,7 @@ class AccountFactory
* *
* @throws FireflyException * @throws FireflyException
*/ */
private function storeCreditLiability(Account $account, array $data) private function storeCreditLiability(Account $account, array $data): void
{ {
Log::debug('storeCreditLiability'); Log::debug('storeCreditLiability');
$account->refresh(); $account->refresh();
@ -366,7 +367,7 @@ class AccountFactory
* *
* @throws FireflyException * @throws FireflyException
*/ */
private function storeOpeningBalance(Account $account, array $data) private function storeOpeningBalance(Account $account, array $data): void
{ {
$accountType = $account->accountType->type; $accountType = $account->accountType->type;

View File

@ -44,10 +44,10 @@ class AccountController extends Controller
* @param Carbon $start * @param Carbon $start
* @param Carbon $end * @param Carbon $end
* *
* @return mixed|string * @return string
* @throws FireflyException * @throws FireflyException
*/ */
public function general(Collection $accounts, Carbon $start, Carbon $end) public function general(Collection $accounts, Carbon $start, Carbon $end): string
{ {
// chart properties for cache: // chart properties for cache:
$cache = new CacheProperties(); $cache = new CacheProperties();

View File

@ -42,7 +42,7 @@ class AcceptHeaders
* @return Response * @return Response
* @throws BadHttpHeaderException * @throws BadHttpHeaderException
*/ */
public function handle($request, $next): mixed public function handle(Request $request, callable $next): mixed
{ {
$method = $request->getMethod(); $method = $request->getMethod();
$accepts = ['application/x-www-form-urlencoded', 'application/json', 'application/vnd.api+json', 'application/octet-stream', '*/*']; $accepts = ['application/x-www-form-urlencoded', 'application/json', 'application/vnd.api+json', 'application/octet-stream', '*/*'];
@ -67,7 +67,7 @@ class AcceptHeaders
} }
// throw bad request if trace id is not a UUID // throw bad request if trace id is not a UUID
$uuid = $request->header('X-Trace-Id', null); $uuid = $request->header('X-Trace-Id');
if (is_string($uuid) && '' !== trim($uuid) && (preg_match('/^[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}$/i', trim($uuid)) !== 1)) { if (is_string($uuid) && '' !== trim($uuid) && (preg_match('/^[a-f\d]{8}(-[a-f\d]{4}){4}[a-f\d]{8}$/i', trim($uuid)) !== 1)) {
throw new BadRequestHttpException('Bad X-Trace-Id header.'); throw new BadRequestHttpException('Bad X-Trace-Id header.');
} }

View File

@ -34,6 +34,7 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Query\Builder; use Illuminate\Database\Query\Builder;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@ -222,9 +223,9 @@ class Account extends Model
} }
/** /**
* Get all of the tags for the post. * Get all the tags for the post.
*/ */
public function objectGroups() public function objectGroups(): MorphToMany
{ {
return $this->morphToMany(ObjectGroup::class, 'object_groupable'); return $this->morphToMany(ObjectGroup::class, 'object_groupable');
} }
@ -257,7 +258,7 @@ class Account extends Model
* *
*/ */
public function setVirtualBalanceAttribute($value): void public function setVirtualBalanceAttribute(mixed $value): void
{ {
$value = (string)$value; $value = (string)$value;
if ('' === $value) { if ('' === $value) {

View File

@ -80,11 +80,10 @@ class AccountMeta extends Model
* @param mixed $value * @param mixed $value
* *
* @return mixed * @return mixed
* @throws JsonException
*/ */
public function getDataAttribute($value) public function getDataAttribute($value): string
{ {
return json_decode($value, true, 512, JSON_THROW_ON_ERROR); return (string)json_decode($value, true);
} }
/** /**

View File

@ -358,11 +358,7 @@ class AccountRepository implements AccountRepositoryInterface
->where('transactions.account_id', $account->id) ->where('transactions.account_id', $account->id)
->transactionTypes([TransactionType::LIABILITY_CREDIT]) ->transactionTypes([TransactionType::LIABILITY_CREDIT])
->first(['transaction_journals.*']); ->first(['transaction_journals.*']);
if (null === $journal) { return $journal?->transactionGroup;
return null;
}
return $journal->transactionGroup;
} }
/** /**
@ -433,13 +429,7 @@ class AccountRepository implements AccountRepositoryInterface
*/ */
public function getNoteText(Account $account): ?string public function getNoteText(Account $account): ?string
{ {
$note = $account->notes()->first(); return $account->notes()->first()?->text;
if (null === $note) {
return null;
}
return $note->text;
} }
/** /**
@ -488,15 +478,10 @@ class AccountRepository implements AccountRepositoryInterface
*/ */
public function getOpeningBalanceDate(Account $account): ?string public function getOpeningBalanceDate(Account $account): ?string
{ {
$journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') return TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $account->id) ->where('transactions.account_id', $account->id)
->transactionTypes([TransactionType::OPENING_BALANCE, TransactionType::LIABILITY_CREDIT]) ->transactionTypes([TransactionType::OPENING_BALANCE, TransactionType::LIABILITY_CREDIT])
->first(['transaction_journals.*']); ->first(['transaction_journals.*'])?->date->format('Y-m-d H:i:s');
if (null === $journal) {
return null;
}
return $journal->date->format('Y-m-d H:i:s');
} }
/** /**

View File

@ -90,8 +90,6 @@ class AccountTasker implements AccountTaskerInterface
'currency_symbol' => $currency->symbol, 'currency_symbol' => $currency->symbol,
'currency_name' => $currency->name, 'currency_name' => $currency->name,
'currency_decimal_places' => $currency->decimal_places, 'currency_decimal_places' => $currency->decimal_places,
'start_balance' => '0',
'end_balance' => '0',
]; ];
// get first journal date: // get first journal date:

View File

@ -151,7 +151,7 @@ trait AccountServiceTrait
if (is_bool($data[$field]) && false === $data[$field]) { if (is_bool($data[$field]) && false === $data[$field]) {
$data[$field] = 0; $data[$field] = 0;
} }
if (is_bool($data[$field]) && true === $data[$field]) { if (true === $data[$field]) {
$data[$field] = 1; $data[$field] = 1;
} }
if ($data[$field] instanceof Carbon) { if ($data[$field] instanceof Carbon) {
@ -171,15 +171,14 @@ trait AccountServiceTrait
*/ */
public function updateNote(Account $account, string $note): bool public function updateNote(Account $account, string $note): bool
{ {
$dbNote = $account->notes()->first();
if ('' === $note) { if ('' === $note) {
$dbNote = $account->notes()->first();
if (null !== $dbNote) { if (null !== $dbNote) {
$dbNote->delete(); $dbNote->delete();
} }
return true; return true;
} }
$dbNote = $account->notes()->first();
if (null === $dbNote) { if (null === $dbNote) {
$dbNote = new Note(); $dbNote = new Note();
$dbNote->noteable()->associate($account); $dbNote->noteable()->associate($account);

View File

@ -254,37 +254,6 @@ class AccountUpdateService
return $account; return $account;
} }
/**
* @param Account $account
* @param array $data
*
* @throws FireflyException
* @deprecated In Firefly III v5.8.0 and onwards, credit transactions for liabilities are no longer created.
*/
private function updateCreditLiability(Account $account, array $data): void
{
$type = $account->accountType;
$valid = config('firefly.valid_liabilities');
if (in_array($type->type, $valid, true)) {
$direction = array_key_exists('liability_direction', $data) ? $data['liability_direction'] : 'empty';
// check if is submitted as empty, that makes it valid:
if ($this->validOBData($data) && !$this->isEmptyOBData($data)) {
$openingBalance = $data['opening_balance'];
$openingBalanceDate = $data['opening_balance_date'];
if ('credit' === $direction) {
$this->updateCreditTransaction($account, $direction, $openingBalance, $openingBalanceDate);
}
}
if (!$this->validOBData($data) && $this->isEmptyOBData($data)) {
$this->deleteCreditTransaction($account);
}
if ($this->validOBData($data) && !$this->isEmptyOBData($data) && 'credit' !== $direction) {
$this->deleteCreditTransaction($account);
}
}
}
/** /**
* @param Account $account * @param Account $account
* @param array $data * @param array $data

View File

@ -51,7 +51,7 @@ class AccountForm
* *
* @return string * @return string
*/ */
public function activeDepositDestinations(string $name, $value = null, array $options = null): string public function activeDepositDestinations(string $name, mixed $value = null, array $options = null): string
{ {
$types = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN, AccountType::REVENUE,]; $types = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN, AccountType::REVENUE,];
$repository = $this->getAccountRepository(); $repository = $this->getAccountRepository();
@ -72,7 +72,7 @@ class AccountForm
* *
* @return string * @return string
*/ */
public function activeWithdrawalDestinations(string $name, $value = null, array $options = null): string public function activeWithdrawalDestinations(string $name, mixed $value = null, array $options = null): string
{ {
$types = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN, AccountType::EXPENSE,]; $types = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN, AccountType::EXPENSE,];
$repository = $this->getAccountRepository(); $repository = $this->getAccountRepository();

View File

@ -25,6 +25,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Search; namespace FireflyIII\Support\Search;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
@ -132,10 +133,13 @@ class AccountSearch implements GenericSearchInterface
} }
/** /**
* @param User $user * @param User|Authenticatable|null $user
* @return void
*/ */
public function setUser(User $user): void public function setUser(User|Authenticatable|null $user): void
{ {
$this->user = $user; if (null !== $user) {
$this->user = $user;
}
} }
} }

View File

@ -37,7 +37,7 @@ use Illuminate\Support\Facades\Log;
class ActionFactory class ActionFactory
{ {
/** @var array array of action types */ /** @var array array of action types */
protected static $actionTypes = []; protected static array $actionTypes = [];
/** /**
* This method returns the actual implementation (TransactionRules/Actions/[object]) for a given * This method returns the actual implementation (TransactionRules/Actions/[object]) for a given

View File

@ -91,7 +91,7 @@ class AccountValidator
Log::debug('AccountValidator source is set to NULL'); Log::debug('AccountValidator source is set to NULL');
} }
if (null !== $account) { if (null !== $account) {
Log::debug(sprintf('AccountValidator source is set to #%d: "%s" (%s)', $account->id, $account->name, $account?->accountType->type)); Log::debug(sprintf('AccountValidator source is set to #%d: "%s" (%s)', $account->id, $account->name, $account->accountType->type));
} }
$this->source = $account; $this->source = $account;
} }
@ -105,7 +105,7 @@ class AccountValidator
Log::debug('AccountValidator destination is set to NULL'); Log::debug('AccountValidator destination is set to NULL');
} }
if (null !== $account) { if (null !== $account) {
Log::debug(sprintf('AccountValidator destination is set to #%d: "%s" (%s)', $account->id, $account->name, $account?->accountType->type)); Log::debug(sprintf('AccountValidator destination is set to #%d: "%s" (%s)', $account->id, $account->name, $account->accountType->type));
} }
$this->destination = $account; $this->destination = $account;
} }

View File

@ -226,9 +226,9 @@ class ChangesForV550 extends Migration
$table->string('title', 255)->index(); $table->string('title', 255)->index();
$table->string('secret', 32)->index(); $table->string('secret', 32)->index();
$table->boolean('active')->default(true); $table->boolean('active')->default(true);
$table->unsignedSmallInteger('trigger', false); $table->unsignedSmallInteger('trigger');
$table->unsignedSmallInteger('response', false); $table->unsignedSmallInteger('response');
$table->unsignedSmallInteger('delivery', false); $table->unsignedSmallInteger('delivery');
$table->string('url', 1024); $table->string('url', 1024);
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->unique(['user_id', 'title']); $table->unique(['user_id', 'title']);

View File

@ -7,3 +7,9 @@ exclude:
paths: paths:
- .ci - .ci
- _ide_helper.php - _ide_helper.php
- public/v1/css/jquery-ui/**
- public/v1/fonts/**
- public/v1/lib/**
- public/v1/js/lib/**
- public/v3/**
- public/v3-local/**