mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-18 04:19:12 +00:00
Fix code quality with rector [skip ci]
This commit is contained in:
@@ -37,9 +37,9 @@ trait DepositValidation
|
||||
protected function validateDepositDestination(array $array): bool
|
||||
{
|
||||
$result = null;
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
|
||||
$accountIban = array_key_exists('iban', $array) ? $array['iban'] : null;
|
||||
$accountId = $array['id'] ?? null;
|
||||
$accountName = $array['name'] ?? null;
|
||||
$accountIban = $array['iban'] ?? null;
|
||||
|
||||
Log::debug('Now in validateDepositDestination', $array);
|
||||
|
||||
@@ -89,10 +89,10 @@ trait DepositValidation
|
||||
*/
|
||||
protected function validateDepositSource(array $array): bool
|
||||
{
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
|
||||
$accountIban = array_key_exists('iban', $array) ? $array['iban'] : null;
|
||||
$accountNumber = array_key_exists('number', $array) ? $array['number'] : null;
|
||||
$accountId = $array['id'] ?? null;
|
||||
$accountName = $array['name'] ?? null;
|
||||
$accountIban = $array['iban'] ?? null;
|
||||
$accountNumber = $array['number'] ?? null;
|
||||
Log::debug('Now in validateDepositSource', $array);
|
||||
|
||||
// null = we found nothing at all or didn't even search
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Validation\Account;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Enums\AccountTypeEnum;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
@@ -35,23 +36,23 @@ trait LiabilityValidation
|
||||
{
|
||||
protected function validateLCDestination(array $array): bool
|
||||
{
|
||||
app('log')->debug('Now in validateLCDestination', $array);
|
||||
Log::debug('Now in validateLCDestination', $array);
|
||||
$result = null;
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
|
||||
$accountId = $array['id'] ?? null;
|
||||
$accountName = $array['name'] ?? null;
|
||||
$validTypes = config('firefly.valid_liabilities');
|
||||
|
||||
// if the ID is not null the source account should be a dummy account of the type liability credit.
|
||||
// the ID of the destination must belong to a liability.
|
||||
if (null !== $accountId) {
|
||||
if (AccountTypeEnum::LIABILITY_CREDIT->value !== $this->source?->accountType?->type) {
|
||||
app('log')->error('Source account is not a liability.');
|
||||
Log::error('Source account is not a liability.');
|
||||
|
||||
return false;
|
||||
}
|
||||
$result = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $result) {
|
||||
app('log')->error('Destination account is not a liability.');
|
||||
Log::error('Destination account is not a liability.');
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -60,11 +61,11 @@ trait LiabilityValidation
|
||||
}
|
||||
|
||||
if (null !== $accountName && '' !== $accountName) {
|
||||
app('log')->debug('Destination ID is null, now we can assume the destination is a (new) liability credit account.');
|
||||
Log::debug('Destination ID is null, now we can assume the destination is a (new) liability credit account.');
|
||||
|
||||
return true;
|
||||
}
|
||||
app('log')->error('Destination ID is null, but destination name is also NULL.');
|
||||
Log::error('Destination ID is null, but destination name is also NULL.');
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -74,35 +75,35 @@ trait LiabilityValidation
|
||||
*/
|
||||
protected function validateLCSource(array $array): bool
|
||||
{
|
||||
app('log')->debug('Now in validateLCSource', $array);
|
||||
Log::debug('Now in validateLCSource', $array);
|
||||
// if the array has an ID and ID is not null, try to find it and check type.
|
||||
// this account must be a liability
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
$accountId = $array['id'] ?? null;
|
||||
if (null !== $accountId) {
|
||||
app('log')->debug('Source ID is not null, assume were looking for a liability.');
|
||||
Log::debug('Source ID is not null, assume were looking for a liability.');
|
||||
// find liability credit:
|
||||
$result = $this->findExistingAccount(config('firefly.valid_liabilities'), $array);
|
||||
if (null === $result) {
|
||||
app('log')->error('Did not find a liability account, return false.');
|
||||
Log::error('Did not find a liability account, return false.');
|
||||
|
||||
return false;
|
||||
}
|
||||
app('log')->debug(sprintf('Return true, found #%d ("%s")', $result->id, $result->name));
|
||||
Log::debug(sprintf('Return true, found #%d ("%s")', $result->id, $result->name));
|
||||
$this->setSource($result);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// if array has name and is not null, return true.
|
||||
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
|
||||
$accountName = $array['name'] ?? null;
|
||||
|
||||
$result = true;
|
||||
if ('' === $accountName || null === $accountName) {
|
||||
app('log')->error('Array must have a name, is not the case, return false.');
|
||||
Log::error('Array must have a name, is not the case, return false.');
|
||||
$result = false;
|
||||
}
|
||||
if (true === $result) {
|
||||
app('log')->error('Array has a name, return true.');
|
||||
if ($result) {
|
||||
Log::error('Array has a name, return true.');
|
||||
// set the source to be a (dummy) revenue account.
|
||||
$account = new Account();
|
||||
$accountType = AccountType::whereType(AccountTypeEnum::LIABILITY_CREDIT->value)->first();
|
||||
|
||||
@@ -37,8 +37,8 @@ trait OBValidation
|
||||
protected function validateOBDestination(array $array): bool
|
||||
{
|
||||
$result = null;
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
|
||||
$accountId = $array['id'] ?? null;
|
||||
$accountName = $array['name'] ?? null;
|
||||
Log::debug('Now in validateOBDestination', $array);
|
||||
|
||||
// source can be any of the following types.
|
||||
@@ -83,8 +83,8 @@ trait OBValidation
|
||||
*/
|
||||
protected function validateOBSource(array $array): bool
|
||||
{
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
|
||||
$accountId = $array['id'] ?? null;
|
||||
$accountName = $array['name'] ?? null;
|
||||
Log::debug('Now in validateOBSource', $array);
|
||||
$result = null;
|
||||
// source can be any of the following types.
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Validation\Account;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Models\Account;
|
||||
|
||||
/**
|
||||
@@ -36,8 +37,8 @@ trait ReconciliationValidation
|
||||
|
||||
protected function validateReconciliationDestination(array $array): bool
|
||||
{
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
|
||||
$accountId = $array['id'] ?? null;
|
||||
$accountName = $array['name'] ?? null;
|
||||
// if both are NULL, the destination is valid because the reconciliation
|
||||
// is expected to be "negative", i.e. the money flows towards the
|
||||
// destination to the asset account which is the source.
|
||||
@@ -47,19 +48,19 @@ trait ReconciliationValidation
|
||||
}
|
||||
|
||||
// after that, search for it expecting an asset account or a liability.
|
||||
app('log')->debug('Now in validateReconciliationDestination', $array);
|
||||
Log::debug('Now in validateReconciliationDestination', $array);
|
||||
|
||||
// source can be any of the following types.
|
||||
$validTypes = array_keys($this->combinations[$this->transactionType]);
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
$this->sourceError = (string) trans('validation.reconciliation_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
app('log')->warning('Not a valid source. Cant find it.', $validTypes);
|
||||
Log::warning('Not a valid source. Cant find it.', $validTypes);
|
||||
|
||||
return false;
|
||||
}
|
||||
$this->setSource($search);
|
||||
app('log')->debug('Valid source account!');
|
||||
Log::debug('Valid source account!');
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -69,32 +70,32 @@ trait ReconciliationValidation
|
||||
*/
|
||||
protected function validateReconciliationSource(array $array): bool
|
||||
{
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
|
||||
$accountId = $array['id'] ?? null;
|
||||
$accountName = $array['name'] ?? null;
|
||||
// if both are NULL, the source is valid because the reconciliation
|
||||
// is expected to be "positive", i.e. the money flows from the
|
||||
// source to the asset account that is the destination.
|
||||
if (null === $accountId && null === $accountName) {
|
||||
app('log')->debug('The source is valid because ID and name are NULL.');
|
||||
Log::debug('The source is valid because ID and name are NULL.');
|
||||
$this->setSource(new Account());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// after that, search for it expecting an asset account or a liability.
|
||||
app('log')->debug('Now in validateReconciliationSource', $array);
|
||||
Log::debug('Now in validateReconciliationSource', $array);
|
||||
|
||||
// source can be any of the following types.
|
||||
$validTypes = array_keys($this->combinations[$this->transactionType]);
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
$this->sourceError = (string) trans('validation.reconciliation_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
app('log')->warning('Not a valid source. Cant find it.', $validTypes);
|
||||
Log::warning('Not a valid source. Cant find it.', $validTypes);
|
||||
|
||||
return false;
|
||||
}
|
||||
$this->setSource($search);
|
||||
app('log')->debug('Valid source account!');
|
||||
Log::debug('Valid source account!');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Validation\Account;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Models\Account;
|
||||
|
||||
/**
|
||||
@@ -33,17 +34,17 @@ trait TransferValidation
|
||||
{
|
||||
protected function validateTransferDestination(array $array): bool
|
||||
{
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
|
||||
$accountIban = array_key_exists('iban', $array) ? $array['iban'] : null;
|
||||
app('log')->debug('Now in validateTransferDestination', $array);
|
||||
$accountId = $array['id'] ?? null;
|
||||
$accountName = $array['name'] ?? null;
|
||||
$accountIban = $array['iban'] ?? null;
|
||||
Log::debug('Now in validateTransferDestination', $array);
|
||||
// source can be any of the following types.
|
||||
$validTypes = $this->combinations[$this->transactionType][$this->source->accountType->type] ?? [];
|
||||
if (null === $accountId && null === $accountName && null === $accountIban && false === $this->canCreateTypes($validTypes)) {
|
||||
// if both values are NULL we return false,
|
||||
// because the destination of a transfer can't be created.
|
||||
$this->destError = (string) trans('validation.transfer_dest_need_data');
|
||||
app('log')->error('Both values are NULL, cant create transfer destination.');
|
||||
Log::error('Both values are NULL, cant create transfer destination.');
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -74,11 +75,11 @@ trait TransferValidation
|
||||
|
||||
protected function validateTransferSource(array $array): bool
|
||||
{
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
|
||||
$accountIban = array_key_exists('iban', $array) ? $array['iban'] : null;
|
||||
$accountNumber = array_key_exists('number', $array) ? $array['number'] : null;
|
||||
app('log')->debug('Now in validateTransferSource', $array);
|
||||
$accountId = $array['id'] ?? null;
|
||||
$accountName = $array['name'] ?? null;
|
||||
$accountIban = $array['iban'] ?? null;
|
||||
$accountNumber = $array['number'] ?? null;
|
||||
Log::debug('Now in validateTransferSource', $array);
|
||||
// source can be any of the following types.
|
||||
$validTypes = array_keys($this->combinations[$this->transactionType]);
|
||||
if (null === $accountId && null === $accountName
|
||||
@@ -87,7 +88,7 @@ trait TransferValidation
|
||||
// if both values are NULL we return false,
|
||||
// because the source of a withdrawal can't be created.
|
||||
$this->sourceError = (string) trans('validation.transfer_source_need_data');
|
||||
app('log')->warning('Not a valid source, need more data.');
|
||||
Log::warning('Not a valid source, need more data.');
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -96,12 +97,12 @@ trait TransferValidation
|
||||
$search = $this->findExistingAccount($validTypes, $array);
|
||||
if (null === $search) {
|
||||
$this->sourceError = (string) trans('validation.transfer_source_bad_data', ['id' => $accountId, 'name' => $accountName]);
|
||||
app('log')->warning('Not a valid source, cant find it.', $validTypes);
|
||||
Log::warning('Not a valid source, cant find it.', $validTypes);
|
||||
|
||||
return false;
|
||||
}
|
||||
$this->setSource($search);
|
||||
app('log')->debug('Valid source!');
|
||||
Log::debug('Valid source!');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -35,9 +35,9 @@ trait WithdrawalValidation
|
||||
{
|
||||
protected function validateGenericSource(array $array): bool
|
||||
{
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
|
||||
$accountIban = array_key_exists('iban', $array) ? $array['iban'] : null;
|
||||
$accountId = $array['id'] ?? null;
|
||||
$accountName = $array['name'] ?? null;
|
||||
$accountIban = $array['iban'] ?? null;
|
||||
Log::debug('Now in validateGenericSource', $array);
|
||||
// source can be any of the following types.
|
||||
$validTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::REVENUE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value];
|
||||
@@ -70,10 +70,10 @@ trait WithdrawalValidation
|
||||
|
||||
protected function validateWithdrawalDestination(array $array): bool
|
||||
{
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
|
||||
$accountIban = array_key_exists('iban', $array) ? $array['iban'] : null;
|
||||
$accountNumber = array_key_exists('number', $array) ? $array['number'] : null;
|
||||
$accountId = $array['id'] ?? null;
|
||||
$accountName = $array['name'] ?? null;
|
||||
$accountIban = $array['iban'] ?? null;
|
||||
$accountNumber = $array['number'] ?? null;
|
||||
Log::debug('Now in validateWithdrawalDestination()', $array);
|
||||
// source can be any of the following types.
|
||||
$validTypes = $this->combinations[$this->transactionType][$this->source->accountType->type] ?? [];
|
||||
@@ -121,10 +121,10 @@ trait WithdrawalValidation
|
||||
|
||||
protected function validateWithdrawalSource(array $array): bool
|
||||
{
|
||||
$accountId = array_key_exists('id', $array) ? $array['id'] : null;
|
||||
$accountName = array_key_exists('name', $array) ? $array['name'] : null;
|
||||
$accountIban = array_key_exists('iban', $array) ? $array['iban'] : null;
|
||||
$accountNumber = array_key_exists('number', $array) ? $array['number'] : null;
|
||||
$accountId = $array['id'] ?? null;
|
||||
$accountName = $array['name'] ?? null;
|
||||
$accountIban = $array['iban'] ?? null;
|
||||
$accountNumber = $array['number'] ?? null;
|
||||
|
||||
Log::debug('Now in validateWithdrawalSource', $array);
|
||||
// source can be any of the following types.
|
||||
|
||||
Reference in New Issue
Block a user