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

@@ -79,7 +79,7 @@ class AccountFactory
*/
public function findOrCreate(string $accountName, string $accountType): Account
{
Log::debug(sprintf('findOrCreate("%s", "%s")', $accountName, $accountType));
app('log')->debug(sprintf('findOrCreate("%s", "%s")', $accountName, $accountType));
$type = $this->accountRepository->getAccountTypeByType($accountType);
if (null === $type) {
@@ -88,7 +88,7 @@ class AccountFactory
$return = $this->user->accounts->where('account_type_id', $type->id)->where('name', $accountName)->first();
if (null === $return) {
Log::debug('Found nothing. Will create a new one.');
app('log')->debug('Found nothing. Will create a new one.');
$return = $this->create(
[
'user_id' => $this->user->id,
@@ -115,7 +115,7 @@ class AccountFactory
*/
public function create(array $data): Account
{
Log::debug('Now in AccountFactory::create()');
app('log')->debug('Now in AccountFactory::create()');
$type = $this->getAccountType($data);
$data['iban'] = $this->filterIban($data['iban'] ?? null);
@@ -163,7 +163,7 @@ class AccountFactory
app('log')->warning(sprintf('Found NO account type based on %d and "%s"', $accountTypeId, $accountTypeName));
throw new FireflyException(sprintf('AccountFactory::create() was unable to find account type #%d ("%s").', $accountTypeId, $accountTypeName));
}
Log::debug(sprintf('Found account type based on %d and "%s": "%s"', $accountTypeId, $accountTypeName, $result->type));
app('log')->debug(sprintf('Found account type based on %d and "%s": "%s"', $accountTypeId, $accountTypeName, $result->type));
return $result;
}
@@ -176,7 +176,7 @@ class AccountFactory
*/
public function find(string $accountName, string $accountType): ?Account
{
Log::debug(sprintf('Now in AccountFactory::find("%s", "%s")', $accountName, $accountType));
app('log')->debug(sprintf('Now in AccountFactory::find("%s", "%s")', $accountName, $accountType));
$type = AccountType::whereType($accountType)->first();
/** @var Account|null */
@@ -358,22 +358,22 @@ class AccountFactory
*/
private function storeCreditLiability(Account $account, array $data): void
{
Log::debug('storeCreditLiability');
app('log')->debug('storeCreditLiability');
$account->refresh();
$accountType = $account->accountType->type;
$direction = $this->accountRepository->getMetaValue($account, 'liability_direction');
$valid = config('firefly.valid_liabilities');
if (in_array($accountType, $valid, true)) {
Log::debug('Is a liability with credit ("i am owed") direction.');
app('log')->debug('Is a liability with credit ("i am owed") direction.');
if ($this->validOBData($data)) {
Log::debug('Has valid CL data.');
app('log')->debug('Has valid CL data.');
$openingBalance = $data['opening_balance'];
$openingBalanceDate = $data['opening_balance_date'];
// store credit transaction.
$this->updateCreditTransaction($account, $direction, $openingBalance, $openingBalanceDate);
}
if (!$this->validOBData($data)) {
Log::debug('Does NOT have valid CL data, deletr any CL transaction.');
app('log')->debug('Does NOT have valid CL data, deletr any CL transaction.');
$this->deleteCreditTransaction($account);
}
}

View File

@@ -52,7 +52,7 @@ class BillFactory
*/
public function create(array $data): ?Bill
{
Log::debug(sprintf('Now in %s', __METHOD__), $data);
app('log')->debug(sprintf('Now in %s', __METHOD__), $data);
$factory = app(TransactionCurrencyFactory::class);
$currency = $factory->find((int)($data['currency_id'] ?? null), (string)($data['currency_code'] ?? null)) ??
app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);

View File

@@ -48,7 +48,7 @@ class CategoryFactory
$categoryId = (int)$categoryId;
$categoryName = (string)$categoryName;
Log::debug(sprintf('Going to find category with ID %d and name "%s"', $categoryId, $categoryName));
app('log')->debug(sprintf('Going to find category with ID %d and name "%s"', $categoryId, $categoryName));
if ('' === $categoryName && 0 === $categoryId) {
return null;

View File

@@ -41,9 +41,9 @@ class PiggyBankEventFactory
*/
public function create(TransactionJournal $journal, ?PiggyBank $piggyBank): void
{
Log::debug(sprintf('Now in PiggyBankEventCreate for a %s', $journal->transactionType->type));
app('log')->debug(sprintf('Now in PiggyBankEventCreate for a %s', $journal->transactionType->type));
if (null === $piggyBank) {
Log::debug('Piggy bank is null');
app('log')->debug('Piggy bank is null');
return;
}
@@ -58,10 +58,10 @@ class PiggyBankEventFactory
return;
}
Log::debug('Found repetition');
app('log')->debug('Found repetition');
$amount = $piggyRepos->getExactAmount($piggyBank, $repetition, $journal);
if (0 === bccomp($amount, '0')) {
Log::debug('Amount is zero, will not create event.');
app('log')->debug('Amount is zero, will not create event.');
return;
}

View File

@@ -43,12 +43,12 @@ class TagFactory
public function findOrCreate(string $tag): ?Tag
{
$tag = trim($tag);
Log::debug(sprintf('Now in TagFactory::findOrCreate("%s")', $tag));
app('log')->debug(sprintf('Now in TagFactory::findOrCreate("%s")', $tag));
/** @var Tag|null $dbTag */
$dbTag = $this->user->tags()->where('tag', $tag)->first();
if (null !== $dbTag) {
Log::debug(sprintf('Tag exists (#%d), return it.', $dbTag->id));
app('log')->debug(sprintf('Tag exists (#%d), return it.', $dbTag->id));
return $dbTag;
}
@@ -67,7 +67,7 @@ class TagFactory
return null;
}
Log::debug(sprintf('Created new tag #%d ("%s")', $newTag->id, $newTag->tag));
app('log')->debug(sprintf('Created new tag #%d ("%s")', $newTag->id, $newTag->tag));
return $newTag;
}

View File

@@ -87,7 +87,7 @@ class TransactionCurrencyFactory
$currencyId = (int)$currencyId;
if ('' === $currencyCode && 0 === $currencyId) {
Log::debug('Cannot find anything on empty currency code and empty currency ID!');
app('log')->debug('Cannot find anything on empty currency code and empty currency ID!');
return null;
}

View File

@@ -116,7 +116,7 @@ class TransactionFactory
throw new FireflyException('Transaction is NULL.');
}
Log::debug(
app('log')->debug(
sprintf(
'Created transaction #%d (%s %s, account %s), part of journal #%d',
$result->id,
@@ -147,15 +147,15 @@ class TransactionFactory
private function updateAccountInformation(): void
{
if (!array_key_exists('iban', $this->accountInformation)) {
Log::debug('No IBAN information in array, will not update.');
app('log')->debug('No IBAN information in array, will not update.');
return;
}
if ('' !== (string)$this->account->iban) {
Log::debug('Account already has IBAN information, will not update.');
app('log')->debug('Account already has IBAN information, will not update.');
return;
}
if ($this->account->iban === $this->accountInformation['iban']) {
Log::debug('Account already has this IBAN, will not update.');
app('log')->debug('Account already has this IBAN, will not update.');
return;
}
// validate info:
@@ -163,11 +163,11 @@ class TransactionFactory
'iban' => ['required', new UniqueIban($this->account, $this->account->accountType->type)],
]);
if ($validator->fails()) {
Log::debug('Invalid or non-unique IBAN, will not update.');
app('log')->debug('Invalid or non-unique IBAN, will not update.');
return;
}
Log::debug('Will update account with IBAN information.');
app('log')->debug('Will update account with IBAN information.');
$service = app(AccountUpdateService::class);
$service->update($this->account, ['iban' => $this->accountInformation['iban']]);
}

View File

@@ -60,7 +60,7 @@ class TransactionGroupFactory
*/
public function create(array $data): TransactionGroup
{
Log::debug('Now in TransactionGroupFactory::create()');
app('log')->debug('Now in TransactionGroupFactory::create()');
$this->journalFactory->setUser($this->user);
$this->journalFactory->setErrorOnHash($data['error_if_duplicate_hash'] ?? false);
try {

View File

@@ -102,11 +102,11 @@ class TransactionJournalFactory
*/
public function create(array $data): Collection
{
Log::debug('Now in TransactionJournalFactory::create()');
app('log')->debug('Now in TransactionJournalFactory::create()');
// convert to special object.
$dataObject = new NullArrayObject($data);
Log::debug('Start of TransactionJournalFactory::create()');
app('log')->debug('Start of TransactionJournalFactory::create()');
$collection = new Collection();
$transactions = $dataObject['transactions'] ?? [];
if (0 === count($transactions)) {
@@ -117,7 +117,7 @@ class TransactionJournalFactory
try {
/** @var array $row */
foreach ($transactions as $index => $row) {
Log::debug(sprintf('Now creating journal %d/%d', $index + 1, count($transactions)));
app('log')->debug(sprintf('Now creating journal %d/%d', $index + 1, count($transactions)));
$journal = $this->createJournal(new NullArrayObject($row));
if (null !== $journal) {
$collection->push($journal);
@@ -201,13 +201,13 @@ class TransactionJournalFactory
'bic' => $row['destination_bic'],
'currency_id' => $currency->id,
];
Log::debug('Source info:', $sourceInfo);
Log::debug('Destination info:', $destInfo);
Log::debug('Now calling getAccount for the source.');
app('log')->debug('Source info:', $sourceInfo);
app('log')->debug('Destination info:', $destInfo);
app('log')->debug('Now calling getAccount for the source.');
$sourceAccount = $this->getAccount($type->type, 'source', $sourceInfo);
Log::debug('Now calling getAccount for the destination.');
app('log')->debug('Now calling getAccount for the destination.');
$destinationAccount = $this->getAccount($type->type, 'destination', $destInfo);
Log::debug('Done with getAccount(2x)');
app('log')->debug('Done with getAccount(2x)');
// this is the moment for a reconciliation sanity check (again).
if (TransactionType::RECONCILIATION === $type->type) {
@@ -219,7 +219,7 @@ class TransactionJournalFactory
$foreignCurrency = $this->getForeignByAccount($type->type, $foreignCurrency, $destinationAccount);
$description = $this->getDescription($description);
Log::debug(sprintf('Date: %s (%s)', $carbon->toW3cString(), $carbon->getTimezone()->getName()));
app('log')->debug(sprintf('Date: %s (%s)', $carbon->toW3cString(), $carbon->getTimezone()->getName()));
/** Create a basic journal. */
$journal = TransactionJournal::create(
@@ -236,7 +236,7 @@ class TransactionJournalFactory
'completed' => 0,
]
);
Log::debug(sprintf('Created new journal #%d: "%s"', $journal->id, $journal->description));
app('log')->debug(sprintf('Created new journal #%d: "%s"', $journal->id, $journal->description));
/** Create two transactions. */
$transactionFactory = app(TransactionFactory::class);
@@ -318,7 +318,7 @@ class TransactionJournalFactory
unset($dataRow['import_hash_v2'], $dataRow['original_source']);
$json = json_encode($dataRow, JSON_THROW_ON_ERROR);
$hash = hash('sha256', $json);
Log::debug(sprintf('The hash is: %s', $hash), $dataRow);
app('log')->debug(sprintf('The hash is: %s', $hash), $dataRow);
return $hash;
}
@@ -333,11 +333,11 @@ class TransactionJournalFactory
*/
private function errorIfDuplicate(string $hash): void
{
Log::debug(sprintf('In errorIfDuplicate(%s)', $hash));
app('log')->debug(sprintf('In errorIfDuplicate(%s)', $hash));
if (false === $this->errorOnHash) {
return;
}
Log::debug('Will verify duplicate!');
app('log')->debug('Will verify duplicate!');
/** @var TransactionJournalMeta|null $result */
$result = TransactionJournalMeta::withTrashed()
->where('data', json_encode($hash, JSON_THROW_ON_ERROR))
@@ -362,7 +362,7 @@ class TransactionJournalFactory
*/
private function validateAccounts(NullArrayObject $data): void
{
Log::debug(sprintf('Now in %s', __METHOD__));
app('log')->debug(sprintf('Now in %s', __METHOD__));
$transactionType = $data['type'] ?? 'invalid';
$this->accountValidator->setUser($this->user);
$this->accountValidator->setTransactionType($transactionType);
@@ -380,7 +380,7 @@ class TransactionJournalFactory
if (false === $validSource) {
throw new FireflyException(sprintf('Source: %s', $this->accountValidator->sourceError));
}
Log::debug('Source seems valid.');
app('log')->debug('Source seems valid.');
// validate destination account
$array = [
@@ -422,25 +422,25 @@ class TransactionJournalFactory
*/
private function reconciliationSanityCheck(?Account $sourceAccount, ?Account $destinationAccount): array
{
Log::debug(sprintf('Now in %s', __METHOD__));
app('log')->debug(sprintf('Now in %s', __METHOD__));
if (null !== $sourceAccount && null !== $destinationAccount) {
Log::debug('Both accounts exist, simply return them.');
app('log')->debug('Both accounts exist, simply return them.');
return [$sourceAccount, $destinationAccount];
}
if (null !== $sourceAccount && null === $destinationAccount) {
Log::debug('Destination account is NULL, source account is not.');
app('log')->debug('Destination account is NULL, source account is not.');
$account = $this->accountRepository->getReconciliation($sourceAccount);
Log::debug(sprintf('Will return account #%d ("%s") of type "%s"', $account->id, $account->name, $account->accountType->type));
app('log')->debug(sprintf('Will return account #%d ("%s") of type "%s"', $account->id, $account->name, $account->accountType->type));
return [$sourceAccount, $account];
}
if (null === $sourceAccount && null !== $destinationAccount) {
Log::debug('Source account is NULL, destination account is not.');
app('log')->debug('Source account is NULL, destination account is not.');
$account = $this->accountRepository->getReconciliation($destinationAccount);
Log::debug(sprintf('Will return account #%d ("%s") of type "%s"', $account->id, $account->name, $account->accountType->type));
app('log')->debug(sprintf('Will return account #%d ("%s") of type "%s"', $account->id, $account->name, $account->accountType->type));
return [$account, $destinationAccount];
}
Log::debug('Unused fallback');
app('log')->debug('Unused fallback');
return [$sourceAccount, $destinationAccount];
}
@@ -456,7 +456,7 @@ class TransactionJournalFactory
*/
private function getCurrencyByAccount(string $type, ?TransactionCurrency $currency, Account $source, Account $destination): TransactionCurrency
{
Log::debug('Now in getCurrencyByAccount()');
app('log')->debug('Now in getCurrencyByAccount()');
return match ($type) {
default => $this->getCurrency($currency, $source),
@@ -474,7 +474,7 @@ class TransactionJournalFactory
*/
private function getCurrency(?TransactionCurrency $currency, Account $account): TransactionCurrency
{
Log::debug('Now in getCurrency()');
app('log')->debug('Now in getCurrency()');
/** @var Preference|null $preference */
$preference = $this->accountRepository->getAccountCurrency($account);
if (null === $preference && null === $currency) {
@@ -482,7 +482,7 @@ class TransactionJournalFactory
return app('amount')->getDefaultCurrencyByUserGroup($this->user->userGroup);
}
$result = ($preference ?? $currency) ?? app('amount')->getSystemCurrency();
Log::debug(sprintf('Currency is now #%d (%s) because of account #%d (%s)', $result->id, $result->code, $account->id, $account->name));
app('log')->debug(sprintf('Currency is now #%d (%s) because of account #%d (%s)', $result->id, $result->code, $account->id, $account->name));
return $result;
}
@@ -545,11 +545,11 @@ class TransactionJournalFactory
*/
private function forceDeleteOnError(Collection $collection): void
{
Log::debug(sprintf('forceDeleteOnError on collection size %d item(s)', $collection->count()));
app('log')->debug(sprintf('forceDeleteOnError on collection size %d item(s)', $collection->count()));
$service = app(JournalDestroyService::class);
/** @var TransactionJournal $journal */
foreach ($collection as $journal) {
Log::debug(sprintf('forceDeleteOnError on journal #%d', $journal->id));
app('log')->debug(sprintf('forceDeleteOnError on journal #%d', $journal->id));
$service->destroy($journal);
}
}
@@ -570,17 +570,17 @@ class TransactionJournalFactory
*/
private function storePiggyEvent(TransactionJournal $journal, NullArrayObject $data): void
{
Log::debug('Will now store piggy event.');
app('log')->debug('Will now store piggy event.');
$piggyBank = $this->piggyRepository->findPiggyBank((int)$data['piggy_bank_id'], $data['piggy_bank_name']);
if (null !== $piggyBank) {
$this->piggyEventFactory->create($journal, $piggyBank);
Log::debug('Create piggy event.');
app('log')->debug('Create piggy event.');
return;
}
Log::debug('Create no piggy event');
app('log')->debug('Create no piggy event');
}
/**
@@ -608,11 +608,11 @@ class TransactionJournalFactory
];
if ($data[$field] instanceof Carbon) {
$data[$field]->setTimezone(config('app.timezone'));
Log::debug(sprintf('%s Date: %s (%s)', $field, $data[$field], $data[$field]->timezone->getName()));
app('log')->debug(sprintf('%s Date: %s (%s)', $field, $data[$field], $data[$field]->timezone->getName()));
$set['data'] = $data[$field]->format('Y-m-d H:i:s');
}
Log::debug(sprintf('Going to store meta-field "%s", with value "%s".', $set['name'], $set['data']));
app('log')->debug(sprintf('Going to store meta-field "%s", with value "%s".', $set['name'], $set['data']));
/** @var TransactionJournalMetaFactory $factory */
$factory = app(TransactionJournalMetaFactory::class);

View File

@@ -39,26 +39,26 @@ class TransactionJournalMetaFactory
*/
public function updateOrCreate(array $data): ?TransactionJournalMeta
{
//Log::debug('In updateOrCreate()');
//app('log')->debug('In updateOrCreate()');
$value = $data['data'];
/** @var TransactionJournalMeta|null $entry */
$entry = $data['journal']->transactionJournalMeta()->where('name', $data['name'])->first();
if (null === $value && null !== $entry) {
//Log::debug('Value is empty, delete meta value.');
//app('log')->debug('Value is empty, delete meta value.');
$entry->delete();
return null;
}
if ($data['data'] instanceof Carbon) {
Log::debug('Is a carbon object.');
app('log')->debug('Is a carbon object.');
$value = $data['data']->toW3cString();
}
if ('' === (string)$value) {
// Log::debug('Is an empty string.');
// app('log')->debug('Is an empty string.');
// don't store blank strings.
if (null !== $entry) {
Log::debug('Will not store empty strings, delete meta value');
app('log')->debug('Will not store empty strings, delete meta value');
$entry->delete();
}
@@ -66,13 +66,13 @@ class TransactionJournalMetaFactory
}
if (null === $entry) {
//Log::debug('Will create new object.');
Log::debug(sprintf('Going to create new meta-data entry to store "%s".', $data['name']));
//app('log')->debug('Will create new object.');
app('log')->debug(sprintf('Going to create new meta-data entry to store "%s".', $data['name']));
$entry = new TransactionJournalMeta();
$entry->transactionJournal()->associate($data['journal']);
$entry->name = $data['name'];
}
Log::debug('Will update value and return.');
app('log')->debug('Will update value and return.');
$entry->data = $value;
$entry->save();