Remove static references

This commit is contained in:
James Cole
2023-10-29 06:33:43 +01:00
parent 075d459b7c
commit 4f2159b54d
205 changed files with 1287 additions and 1287 deletions

View File

@@ -55,12 +55,12 @@ trait TransactionValidation
if ($validator->errors()->count() > 0) {
return;
}
Log::debug('Now in validateAccountInformation (TransactionValidation) ()');
app('log')->debug('Now in validateAccountInformation (TransactionValidation) ()');
$transactions = $this->getTransactionsArray($validator);
$data = $validator->getData();
$transactionType = $data['type'] ?? 'invalid';
Log::debug(sprintf('Going to loop %d transaction(s)', count($transactions)));
app('log')->debug(sprintf('Going to loop %d transaction(s)', count($transactions)));
/**
* @var int $index
* @var array $transaction
@@ -82,22 +82,22 @@ trait TransactionValidation
*/
protected function getTransactionsArray(Validator $validator): array
{
Log::debug('Now in getTransactionsArray');
app('log')->debug('Now in getTransactionsArray');
$data = $validator->getData();
$transactions = [];
if (is_array($data) && array_key_exists('transactions', $data) && is_array($data['transactions'])) {
Log::debug('Transactions key exists and is array.');
app('log')->debug('Transactions key exists and is array.');
$transactions = $data['transactions'];
}
if (is_array($data) && array_key_exists('transactions', $data) && !is_array($data['transactions'])) {
Log::debug(sprintf('Transactions key exists but is NOT array, its a %s', gettype($data['transactions'])));
app('log')->debug(sprintf('Transactions key exists but is NOT array, its a %s', gettype($data['transactions'])));
}
// should be impossible to hit this:
if (!is_countable($transactions)) {
app('log')->error(sprintf('Transactions array is not countable, because its a %s', gettype($transactions)));
return [];
}
//Log::debug('Returning transactions.', $transactions);
//app('log')->debug('Returning transactions.', $transactions);
return $transactions;
}
@@ -179,11 +179,11 @@ trait TransactionValidation
*/
protected function sanityCheckReconciliation(Validator $validator, string $transactionType, int $index, array $source, array $destination): void
{
Log::debug('Now in sanityCheckReconciliation');
app('log')->debug('Now in sanityCheckReconciliation');
if (TransactionType::RECONCILIATION === ucfirst($transactionType) &&
null === $source['id'] && null === $source['name'] && null === $destination['id'] && null === $destination['name']
) {
Log::debug('Both are NULL, error!');
app('log')->debug('Both are NULL, error!');
$validator->errors()->add(sprintf('transactions.%d.source_id', $index), trans('validation.reconciliation_either_account'));
$validator->errors()->add(sprintf('transactions.%d.source_name', $index), trans('validation.reconciliation_either_account'));
$validator->errors()->add(sprintf('transactions.%d.destination_id', $index), trans('validation.reconciliation_either_account'));
@@ -193,7 +193,7 @@ trait TransactionValidation
if (TransactionType::RECONCILIATION === $transactionType &&
(null !== $source['id'] || null !== $source['name']) &&
(null !== $destination['id'] || null !== $destination['name'])) {
Log::debug('Both are not NULL, error!');
app('log')->debug('Both are not NULL, error!');
$validator->errors()->add(sprintf('transactions.%d.source_id', $index), trans('validation.reconciliation_either_account'));
$validator->errors()->add(sprintf('transactions.%d.source_name', $index), trans('validation.reconciliation_either_account'));
$validator->errors()->add(sprintf('transactions.%d.destination_id', $index), trans('validation.reconciliation_either_account'));
@@ -219,27 +219,27 @@ trait TransactionValidation
string $transactionType,
int $index
): void {
Log::debug('Now in sanityCheckForeignCurrency()');
app('log')->debug('Now in sanityCheckForeignCurrency()');
if (0 !== $validator->errors()->count()) {
Log::debug('Already have errors, return');
app('log')->debug('Already have errors, return');
return;
}
if (null === $accountValidator->source) {
Log::debug('No source, return');
app('log')->debug('No source, return');
return;
}
if (null === $accountValidator->destination) {
Log::debug('No destination, return');
app('log')->debug('No destination, return');
return;
}
$source = $accountValidator->source;
$destination = $accountValidator->destination;
Log::debug(sprintf('Source: #%d "%s (%s)"', $source->id, $source->name, $source->accountType->type));
Log::debug(sprintf('Destination: #%d "%s" (%s)', $destination->id, $destination->name, $source->accountType->type));
app('log')->debug(sprintf('Source: #%d "%s (%s)"', $source->id, $source->name, $source->accountType->type));
app('log')->debug(sprintf('Destination: #%d "%s" (%s)', $destination->id, $destination->name, $source->accountType->type));
if (!$this->isLiabilityOrAsset($source) || !$this->isLiabilityOrAsset($destination)) {
Log::debug('Any account must be liability or asset account to continue.');
app('log')->debug('Any account must be liability or asset account to continue.');
return;
}
@@ -251,16 +251,16 @@ trait TransactionValidation
$destinationCurrency = $accountRepository->getAccountCurrency($destination) ?? $defaultCurrency;
// if both accounts have the same currency, continue.
if ($sourceCurrency->code === $destinationCurrency->code) {
Log::debug('Both accounts have the same currency, continue.');
app('log')->debug('Both accounts have the same currency, continue.');
return;
}
Log::debug(sprintf('Source account expects %s', $sourceCurrency->code));
Log::debug(sprintf('Destination account expects %s', $destinationCurrency->code));
app('log')->debug(sprintf('Source account expects %s', $sourceCurrency->code));
app('log')->debug(sprintf('Destination account expects %s', $destinationCurrency->code));
Log::debug(sprintf('Amount is %s', $transaction['amount']));
app('log')->debug(sprintf('Amount is %s', $transaction['amount']));
if (TransactionType::DEPOSIT === ucfirst($transactionType)) {
Log::debug(sprintf('Processing as a "%s"', $transactionType));
app('log')->debug(sprintf('Processing as a "%s"', $transactionType));
// use case: deposit from liability account to an asset account
// the foreign amount must be in the currency of the source
// the amount must be in the currency of the destination
@@ -274,14 +274,14 @@ trait TransactionValidation
// wrong currency information is present
$foreignCurrencyCode = $transaction['foreign_currency_code'] ?? false;
$foreignCurrencyId = (int)($transaction['foreign_currency_id'] ?? 0);
Log::debug(sprintf('Foreign currency code seems to be #%d "%s"', $foreignCurrencyId, $foreignCurrencyCode), $transaction);
app('log')->debug(sprintf('Foreign currency code seems to be #%d "%s"', $foreignCurrencyId, $foreignCurrencyCode), $transaction);
if ($foreignCurrencyCode !== $sourceCurrency->code && $foreignCurrencyId !== (int)$sourceCurrency->id) {
$validator->errors()->add(sprintf('transactions.%d.foreign_currency_code', $index), (string)trans('validation.require_foreign_src'));
return;
}
}
if (TransactionType::TRANSFER === ucfirst($transactionType) || TransactionType::WITHDRAWAL === ucfirst($transactionType)) {
Log::debug(sprintf('Processing as a "%s"', $transactionType));
app('log')->debug(sprintf('Processing as a "%s"', $transactionType));
// use case: withdrawal from asset account to a liability account.
// the foreign amount must be in the currency of the destination
// the amount must be in the currency of the source
@@ -299,10 +299,10 @@ trait TransactionValidation
// wrong currency information is present
$foreignCurrencyCode = $transaction['foreign_currency_code'] ?? false;
$foreignCurrencyId = (int)($transaction['foreign_currency_id'] ?? 0);
Log::debug(sprintf('Foreign currency code seems to be #%d "%s"', $foreignCurrencyId, $foreignCurrencyCode), $transaction);
app('log')->debug(sprintf('Foreign currency code seems to be #%d "%s"', $foreignCurrencyId, $foreignCurrencyCode), $transaction);
if ($foreignCurrencyCode !== $destinationCurrency->code && $foreignCurrencyId !== (int)$destinationCurrency->id) {
Log::debug(sprintf('No match on code, "%s" vs "%s"', $foreignCurrencyCode, $destinationCurrency->code));
Log::debug(sprintf('No match on ID, #%d vs #%d', $foreignCurrencyId, $destinationCurrency->id));
app('log')->debug(sprintf('No match on code, "%s" vs "%s"', $foreignCurrencyCode, $destinationCurrency->code));
app('log')->debug(sprintf('No match on ID, #%d vs #%d', $foreignCurrencyId, $destinationCurrency->id));
$validator->errors()->add(sprintf('transactions.%d.foreign_amount', $index), (string)trans('validation.require_foreign_dest'));
}
}
@@ -375,9 +375,9 @@ trait TransactionValidation
*/
public function validateAccountInformationUpdate(Validator $validator, TransactionGroup $transactionGroup): void
{
Log::debug('Now in validateAccountInformationUpdate()');
app('log')->debug('Now in validateAccountInformationUpdate()');
if ($validator->errors()->count() > 0) {
Log::debug('Validator already has errors, so return.');
app('log')->debug('Validator already has errors, so return.');
return;
}
@@ -403,7 +403,7 @@ trait TransactionValidation
*/
protected function validateSingleUpdate(Validator $validator, int $index, array $transaction, TransactionGroup $transactionGroup): void
{
Log::debug('Now validating single account update in validateSingleUpdate()');
app('log')->debug('Now validating single account update in validateSingleUpdate()');
// if no account types are given, just skip the check.
if (
@@ -411,7 +411,7 @@ trait TransactionValidation
&& !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.');
app('log')->debug('No account data has been submitted so will not validating account info.');
return;
}
@@ -429,7 +429,7 @@ trait TransactionValidation
array_key_exists('source_iban', $transaction) ||
array_key_exists('source_number', $transaction)
) {
Log::debug('Will try to validate source account information.');
app('log')->debug('Will try to validate source account information.');
$sourceId = (int)($transaction['source_id'] ?? 0);
$sourceName = $transaction['source_name'] ?? null;
$sourceIban = $transaction['source_iban'] ?? null;
@@ -448,7 +448,7 @@ trait TransactionValidation
return;
}
Log::debug('Source account info is valid.');
app('log')->debug('Source account info is valid.');
}
if (
@@ -458,15 +458,15 @@ trait TransactionValidation
array_key_exists('destination_number', $transaction)
) {
Log::debug('Will try to validate destination account information.');
app('log')->debug('Will try to validate destination account information.');
// at this point the validator may not have a source account, because it was never submitted for validation.
// must add it ourselves or the validator can never check if the destination is correct.
// the $transaction array must have a journal id or it's just one, this was validated before.
if (null === $accountValidator->source) {
Log::debug('Account validator has no source account, must find it.');
app('log')->debug('Account validator has no source account, must find it.');
$source = $this->getOriginalSource($transaction, $transactionGroup);
if (null !== $source) {
Log::debug('Found a source!');
app('log')->debug('Found a source!');
$accountValidator->source = $source;
}
}
@@ -482,9 +482,9 @@ trait TransactionValidation
$validator->errors()->add(sprintf('transactions.%d.destination_id', $index), $accountValidator->destError);
$validator->errors()->add(sprintf('transactions.%d.destination_name', $index), $accountValidator->destError);
}
Log::debug('Destination account info is valid.');
app('log')->debug('Destination account info is valid.');
}
Log::debug('Done with validateSingleUpdate().');
app('log')->debug('Done with validateSingleUpdate().');
}
/**
@@ -529,7 +529,7 @@ trait TransactionValidation
*/
public function validateOneRecurrenceTransaction(Validator $validator): void
{
Log::debug('Now in validateOneRecurrenceTransaction()');
app('log')->debug('Now in validateOneRecurrenceTransaction()');
$transactions = $this->getTransactionsArray($validator);
// need at least one transaction
@@ -545,20 +545,20 @@ trait TransactionValidation
*/
public function validateOneTransaction(Validator $validator): void
{
Log::debug('Now in validateOneTransaction');
app('log')->debug('Now in validateOneTransaction');
if ($validator->errors()->count() > 0) {
Log::debug('Validator already has errors, so return.');
app('log')->debug('Validator already has errors, so return.');
return;
}
$transactions = $this->getTransactionsArray($validator);
// need at least one transaction
if (0 === count($transactions)) {
$validator->errors()->add('transactions.0.description', (string)trans('validation.at_least_one_transaction'));
Log::debug('Added error: at_least_one_transaction.');
app('log')->debug('Added error: at_least_one_transaction.');
return;
}
Log::debug('Added NO errors.');
app('log')->debug('Added NO errors.');
}
/**
@@ -573,7 +573,7 @@ trait TransactionValidation
foreach ($transactions as $key => $value) {
if (!is_int($key)) {
$validator->errors()->add('transactions.0.description', (string)trans('validation.at_least_one_transaction'));
Log::debug('Added error: at_least_one_transaction.');
app('log')->debug('Added error: at_least_one_transaction.');
return;
}
@@ -590,7 +590,7 @@ trait TransactionValidation
if ($validator->errors()->count() > 0) {
return;
}
Log::debug('Now in validateTransactionTypes()');
app('log')->debug('Now in validateTransactionTypes()');
$transactions = $this->getTransactionsArray($validator);
$types = [];
@@ -616,7 +616,7 @@ trait TransactionValidation
*/
public function validateTransactionTypesForUpdate(Validator $validator): void
{
Log::debug('Now in validateTransactionTypesForUpdate()');
app('log')->debug('Now in validateTransactionTypesForUpdate()');
$transactions = $this->getTransactionsArray($validator);
$types = [];
foreach ($transactions as $transaction) {
@@ -631,7 +631,7 @@ trait TransactionValidation
return;
}
Log::debug('No errors in validateTransactionTypesForUpdate()');
app('log')->debug('No errors in validateTransactionTypesForUpdate()');
}
/**
@@ -661,7 +661,7 @@ trait TransactionValidation
if ($validator->errors()->count() > 0) {
return;
}
Log::debug('Now in validateEqualAccounts()');
app('log')->debug('Now in validateEqualAccounts()');
$transactions = $this->getTransactionsArray($validator);
// needs to be split
@@ -705,15 +705,15 @@ trait TransactionValidation
private function validateEqualAccountsForUpdate(Validator $validator, TransactionGroup $transactionGroup): void
{
if ($validator->errors()->count() > 0) {
Log::debug('Validator already has errors, so return.');
app('log')->debug('Validator already has errors, so return.');
return;
}
Log::debug('Now in validateEqualAccountsForUpdate()');
app('log')->debug('Now in validateEqualAccountsForUpdate()');
$transactions = $this->getTransactionsArray($validator);
if (2 !== count($transactions)) {
Log::debug('Less than 2 transactions, do nothing.');
app('log')->debug('Less than 2 transactions, do nothing.');
return;
}
@@ -741,7 +741,7 @@ trait TransactionValidation
return;
}
Log::debug('No errors found in validateEqualAccountsForUpdate');
app('log')->debug('No errors found in validateEqualAccountsForUpdate');
}
/**