Update configuration and fix some files.

This commit is contained in:
James Cole
2025-05-27 17:02:18 +02:00
parent c074fec0a7
commit d8f512ca3a
31 changed files with 154 additions and 111 deletions

View File

@@ -29,7 +29,7 @@ rm -f .php-cs-fixer.cache
PHP_CS_FIXER_IGNORE_ENV=true ./vendor/bin/php-cs-fixer fix \ PHP_CS_FIXER_IGNORE_ENV=true ./vendor/bin/php-cs-fixer fix \
--config $SCRIPT_DIR/php-cs-fixer/.php-cs-fixer.php \ --config $SCRIPT_DIR/php-cs-fixer/.php-cs-fixer.php \
--format=txt -v \ --format=txt -v \
--allow-risky=yes -v --allow-risky=yes
EXIT_CODE=$? EXIT_CODE=$?

View File

@@ -28,43 +28,51 @@ use Rector\EarlyReturn\Rector\If_\ChangeOrIfContinueToMultiContinueRector;
return RectorConfig::configure() return RectorConfig::configure()
->withSkip([ ->withSkip([
ChangeOrIfContinueToMultiContinueRector::class, ChangeOrIfContinueToMultiContinueRector::class,
]) ])
->withPaths([ ->withPaths([
// __DIR__ . '/../app', // __DIR__ . '/../app',
__DIR__ . '/../app/Api', __DIR__ . '/../app/Api',
__DIR__ . '/../app/Http', __DIR__ . '/../app/Casts',
__DIR__ . '/../app/Console',
__DIR__ . '/../app/Entities',
__DIR__ . '/../app/Enums',
__DIR__ . '/../app/Enums',
__DIR__ . '/../app/Events',
__DIR__ . '/../app/Exceptions',
__DIR__ . '/../app/Factory',
__DIR__ . '/../app/Generator',
__DIR__ . '/../app/Http',
// __DIR__ . '/../bootstrap', // __DIR__ . '/../bootstrap',
// __DIR__ . '/../config', // __DIR__ . '/../config',
// __DIR__ . '/../public', // __DIR__ . '/../public',
// __DIR__ . '/../resources', // __DIR__ . '/../resources',
// __DIR__ . '/../routes', // __DIR__ . '/../routes',
// __DIR__ . '/../tests', // __DIR__ . '/../tests',
]) ])
// uncomment to reach your current PHP version // uncomment to reach your current PHP version
->withPhpSets() ->withPhpSets()
->withPreparedSets( ->withPreparedSets(
codingStyle : false, // leave false codingStyle: false, // leave false
privatization: false, // leave false. privatization: false, // leave false.
naming : false, // leave false naming: false, // leave false
instanceOf : true, instanceOf: true,
earlyReturn : true, earlyReturn: true,
strictBooleans : true, strictBooleans: true,
carbon : true, carbon: true,
rectorPreset : true, rectorPreset: true,
phpunitCodeQuality : true, phpunitCodeQuality: true,
doctrineCodeQuality: true, doctrineCodeQuality: true,
symfonyCodeQuality : true, symfonyCodeQuality: true,
symfonyConfigs : true symfonyConfigs: true
) )
->withComposerBased( ->withComposerBased(
twig: true, twig: true,
doctrine: true, doctrine: true,
phpunit: true, phpunit: true,
symfony: true) symfony: true)
->withTypeCoverageLevel(0) ->withTypeCoverageLevel(0)
->withDeadCodeLevel(0) ->withDeadCodeLevel(0)
->withCodeQualityLevel(0) ->withCodeQualityLevel(0)
->withImportNames(removeUnusedImports: true);// import statements instead of full classes.
->withImportNames(removeUnusedImports: true);// import statements instead of full classes.

View File

@@ -76,7 +76,7 @@ class CorrectsOpeningBalanceCurrencies extends Command
{ {
// get the asset account for this opening balance: // get the asset account for this opening balance:
$account = $this->getAccount($journal); $account = $this->getAccount($journal);
if (null === $account) { if (!$account instanceof Account) {
$message = sprintf('Transaction journal #%d has no valid account. Can\'t fix this line.', $journal->id); $message = sprintf('Transaction journal #%d has no valid account. Can\'t fix this line.', $journal->id);
app('log')->warning($message); app('log')->warning($message);
$this->friendlyError($message); $this->friendlyError($message);

View File

@@ -387,7 +387,7 @@ class CorrectsUnevenAmount extends Command
continue; continue;
} }
if (0 === bccomp($source->amount, $source->foreign_amount) && 0 === bccomp($source->foreign_amount, $source->amount)) { if (0 === bccomp((string) $source->amount, (string) $source->foreign_amount) && 0 === bccomp((string) $source->foreign_amount, (string) $source->amount)) {
Log::debug('Already fixed, continue.'); Log::debug('Already fixed, continue.');
continue; continue;

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Export; namespace FireflyIII\Console\Commands\Export;
use FireflyIII\Models\TransactionJournal;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Console\Commands\VerifiesAccessToken; use FireflyIII\Console\Commands\VerifiesAccessToken;
@@ -38,6 +39,8 @@ use Illuminate\Support\Collection;
use Exception; use Exception;
use InvalidArgumentException; use InvalidArgumentException;
use function Safe\file_put_contents;
class ExportsData extends Command class ExportsData extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
@@ -203,7 +206,7 @@ class ExportsData extends Command
if (true === $error && 'start' === $field) { if (true === $error && 'start' === $field) {
$journal = $this->journalRepository->firstNull(); $journal = $this->journalRepository->firstNull();
$date = null === $journal ? today(config('app.timezone'))->subYear() : $journal->date; $date = $journal instanceof TransactionJournal ? $journal->date : today(config('app.timezone'))->subYear();
$date->startOfDay(); $date->startOfDay();
return $date; return $date;
@@ -275,7 +278,7 @@ class ExportsData extends Command
*/ */
private function exportData(array $options, array $data): void private function exportData(array $options, array $data): void
{ {
$date = date('Y_m_d'); $date = Carbon::now()->format('Y_m_d');
foreach ($data as $key => $content) { foreach ($data as $key => $content) {
$file = sprintf('%s%s_%s.csv', $options['directory'], $date, $key); $file = sprintf('%s%s_%s.csv', $options['directory'], $date, $key);
if (false === $options['force'] && file_exists($file)) { if (false === $options['force'] && file_exists($file)) {
@@ -285,7 +288,7 @@ class ExportsData extends Command
$this->friendlyWarning(sprintf('File "%s" exists already but will be replaced.', $file)); $this->friendlyWarning(sprintf('File "%s" exists already but will be replaced.', $file));
} }
// continue to write to file. // continue to write to file.
\Safe\file_put_contents($file, $content); file_put_contents($file, $content);
$this->friendlyPositive(sprintf('Wrote %s-export to file "%s".', $key, $file)); $this->friendlyPositive(sprintf('Wrote %s-export to file "%s".', $key, $file));
} }
} }

View File

@@ -43,6 +43,9 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use function Safe\mb_regex_encoding;
use function Safe\json_encode;
/** /**
* This command was inspired by https://github.com/elliot-gh. It will check all amount fields * This command was inspired by https://github.com/elliot-gh. It will check all amount fields
* and their values and correct them to the correct number of decimal places. This fixes issues where * and their values and correct them to the correct number of decimal places. This fixes issues where
@@ -130,7 +133,7 @@ class ForcesDecimalSize extends Command
// if sqlite, add function? // if sqlite, add function?
if ('sqlite' === (string) config('database.default')) { if ('sqlite' === (string) config('database.default')) {
DB::connection()->getPdo()->sqliteCreateFunction('REGEXP', static function ($pattern, $value) { DB::connection()->getPdo()->sqliteCreateFunction('REGEXP', static function ($pattern, $value) {
\Safe\mb_regex_encoding('UTF-8'); mb_regex_encoding('UTF-8');
$pattern = trim($pattern, '"'); $pattern = trim($pattern, '"');
return (false !== mb_ereg($pattern, (string) $value)) ? 1 : 0; return (false !== mb_ereg($pattern, (string) $value)) ? 1 : 0;
@@ -234,7 +237,7 @@ class ForcesDecimalSize extends Command
/** @var Builder $query */ /** @var Builder $query */
$query = Account::leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id') $query = Account::leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
->where('account_meta.name', 'currency_id') ->where('account_meta.name', 'currency_id')
->where('account_meta.data', \Safe\json_encode((string) $currency->id)) ->where('account_meta.data', json_encode((string) $currency->id))
; ;
$query->where(static function (Builder $q) use ($fields, $currency, $operator, $cast, $regularExpression): void { $query->where(static function (Builder $q) use ($fields, $currency, $operator, $cast, $regularExpression): void {
foreach ($fields as $field) { foreach ($fields as $field) {
@@ -338,7 +341,7 @@ class ForcesDecimalSize extends Command
->leftJoin('accounts', 'piggy_banks.account_id', '=', 'accounts.id') ->leftJoin('accounts', 'piggy_banks.account_id', '=', 'accounts.id')
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id') ->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
->where('account_meta.name', 'currency_id') ->where('account_meta.name', 'currency_id')
->where('account_meta.data', \Safe\json_encode((string) $currency->id)) ->where('account_meta.data', json_encode((string) $currency->id))
->where(static function (Builder $q) use ($fields, $currency, $cast, $operator, $regularExpression): void { ->where(static function (Builder $q) use ($fields, $currency, $cast, $operator, $regularExpression): void {
foreach ($fields as $field) { foreach ($fields as $field) {
$q->orWhere( $q->orWhere(
@@ -394,7 +397,7 @@ class ForcesDecimalSize extends Command
->leftJoin('accounts', 'piggy_banks.account_id', '=', 'accounts.id') ->leftJoin('accounts', 'piggy_banks.account_id', '=', 'accounts.id')
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id') ->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
->where('account_meta.name', 'currency_id') ->where('account_meta.name', 'currency_id')
->where('account_meta.data', \Safe\json_encode((string) $currency->id)) ->where('account_meta.data', json_encode((string) $currency->id))
->where(static function (Builder $q) use ($fields, $currency, $operator, $cast, $regularExpression): void { ->where(static function (Builder $q) use ($fields, $currency, $operator, $cast, $regularExpression): void {
foreach ($fields as $field) { foreach ($fields as $field) {
$q->orWhere( $q->orWhere(
@@ -448,7 +451,7 @@ class ForcesDecimalSize extends Command
$query = PiggyBank::leftJoin('accounts', 'piggy_banks.account_id', '=', 'accounts.id') $query = PiggyBank::leftJoin('accounts', 'piggy_banks.account_id', '=', 'accounts.id')
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id') ->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
->where('account_meta.name', 'currency_id') ->where('account_meta.name', 'currency_id')
->where('account_meta.data', \Safe\json_encode((string) $currency->id)) ->where('account_meta.data', json_encode((string) $currency->id))
->where(static function (Builder $q) use ($fields, $currency, $operator, $cast, $regularExpression): void { ->where(static function (Builder $q) use ($fields, $currency, $operator, $cast, $regularExpression): void {
foreach ($fields as $field) { foreach ($fields as $field) {
$q->orWhere( $q->orWhere(

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\System; namespace FireflyIII\Console\Commands\System;
use Carbon\Carbon;
use FireflyIII\Support\System\GeneratesInstallationId; use FireflyIII\Support\System\GeneratesInstallationId;
use Illuminate\Console\Command; use Illuminate\Console\Command;
@@ -111,8 +112,8 @@ class OutputsInstructions extends Command
*/ */
private function showLogo(): void private function showLogo(): void
{ {
$today = date('m-d'); $today = Carbon::now()->format('m-d');
$month = date('m'); $month = Carbon::now()->format('m');
// variation in colors and effects just because I can! // variation in colors and effects just because I can!
// default is Ukraine flag: // default is Ukraine flag:
$colors = ['blue', 'blue', 'blue', 'yellow', 'yellow', 'yellow', 'default', 'default']; $colors = ['blue', 'blue', 'blue', 'yellow', 'yellow', 'yellow', 'default', 'default'];

View File

@@ -31,6 +31,11 @@ use Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use function Safe\tempnam;
use function Safe\file_put_contents;
use function Safe\md5_file;
use function Safe\mime_content_type;
class ScansAttachments extends Command class ScansAttachments extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
@@ -63,15 +68,15 @@ class ScansAttachments extends Command
app('log')->error(sprintf('Could not decrypt data of attachment #%d: %s', $attachment->id, $e->getMessage())); app('log')->error(sprintf('Could not decrypt data of attachment #%d: %s', $attachment->id, $e->getMessage()));
$decryptedContent = $encryptedContent; $decryptedContent = $encryptedContent;
} }
$tempFileName = \Safe\tempnam(sys_get_temp_dir(), 'FireflyIII'); $tempFileName = tempnam(sys_get_temp_dir(), 'FireflyIII');
if (false === $tempFileName) { if (false === $tempFileName) {
app('log')->error(sprintf('Could not create temporary file for attachment #%d', $attachment->id)); app('log')->error(sprintf('Could not create temporary file for attachment #%d', $attachment->id));
exit(1); exit(1);
} }
\Safe\file_put_contents($tempFileName, $decryptedContent); file_put_contents($tempFileName, $decryptedContent);
$attachment->md5 = (string) \Safe\md5_file($tempFileName); $attachment->md5 = (string) md5_file($tempFileName);
$attachment->mime = (string) \Safe\mime_content_type($tempFileName); $attachment->mime = (string) mime_content_type($tempFileName);
$attachment->save(); $attachment->save();
$this->friendlyInfo(sprintf('Fixed attachment #%d', $attachment->id)); $this->friendlyInfo(sprintf('Fixed attachment #%d', $attachment->id));
} }

View File

@@ -30,6 +30,8 @@ use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use League\Flysystem\FilesystemException; use League\Flysystem\FilesystemException;
use function Safe\json_decode;
class VerifySecurityAlerts extends Command class VerifySecurityAlerts extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
@@ -57,7 +59,7 @@ class VerifySecurityAlerts extends Command
return 0; return 0;
} }
$content = $disk->get('alerts.json'); $content = $disk->get('alerts.json');
$json = \Safe\json_decode($content, true, 10); $json = json_decode((string) $content, true, 10);
/** @var array $array */ /** @var array $array */
foreach ($json as $array) { foreach ($json as $array) {

View File

@@ -248,7 +248,7 @@ class ApplyRules extends Command
foreach ($ruleList as $ruleId) { foreach ($ruleList as $ruleId) {
$rule = $this->ruleRepository->find((int) $ruleId); $rule = $this->ruleRepository->find((int) $ruleId);
if (null !== $rule && true === $rule->active) { if ($rule instanceof Rule && true === $rule->active) {
$this->ruleSelection[] = $rule->id; $this->ruleSelection[] = $rule->id;
} }
} }

View File

@@ -134,7 +134,7 @@ class Cron extends Command
$exchangeRates = new ExchangeRatesCronjob(); $exchangeRates = new ExchangeRatesCronjob();
$exchangeRates->setForce($force); $exchangeRates->setForce($force);
// set date in cron job: // set date in cron job:
if (null !== $date) { if ($date instanceof Carbon) {
$exchangeRates->setDate($date); $exchangeRates->setDate($date);
} }
@@ -177,7 +177,7 @@ class Cron extends Command
$recurring->setForce($force); $recurring->setForce($force);
// set date in cron job: // set date in cron job:
if (null !== $date) { if ($date instanceof Carbon) {
$recurring->setDate($date); $recurring->setDate($date);
} }
@@ -198,7 +198,7 @@ class Cron extends Command
$autoBudget = new AutoBudgetCronjob(); $autoBudget = new AutoBudgetCronjob();
$autoBudget->setForce($force); $autoBudget->setForce($force);
// set date in cron job: // set date in cron job:
if (null !== $date) { if ($date instanceof Carbon) {
$autoBudget->setDate($date); $autoBudget->setDate($date);
} }
@@ -223,7 +223,7 @@ class Cron extends Command
$autoBudget = new BillWarningCronjob(); $autoBudget = new BillWarningCronjob();
$autoBudget->setForce($force); $autoBudget->setForce($force);
// set date in cron job: // set date in cron job:
if (null !== $date) { if ($date instanceof Carbon) {
$autoBudget->setDate($date); $autoBudget->setDate($date);
} }

View File

@@ -120,7 +120,7 @@ class AddsTransactionIdentifiers extends Command
/** @var Transaction $transaction */ /** @var Transaction $transaction */
foreach ($transactions as $transaction) { foreach ($transactions as $transaction) {
$opposing = $this->findOpposing($transaction, $exclude); $opposing = $this->findOpposing($transaction, $exclude);
if (null !== $opposing) { if ($opposing instanceof Transaction) {
// give both a new identifier: // give both a new identifier:
$transaction->identifier = $identifier; $transaction->identifier = $identifier;
$opposing->identifier = $identifier; $opposing->identifier = $identifier;

View File

@@ -34,6 +34,8 @@ use Illuminate\Support\Facades\DB;
use JsonException; use JsonException;
use stdClass; use stdClass;
use function Safe\json_decode;
class RemovesDatabaseDecryption extends Command class RemovesDatabaseDecryption extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
@@ -169,7 +171,7 @@ class RemovesDatabaseDecryption extends Command
{ {
// try to json_decrypt the value. // try to json_decrypt the value.
try { try {
$newValue = \Safe\json_decode($value, true, 512, JSON_THROW_ON_ERROR) ?? $value; $newValue = json_decode($value, true, 512, JSON_THROW_ON_ERROR) ?? $value;
} catch (JsonException $e) { } catch (JsonException $e) {
$message = sprintf('Could not JSON decode preference row #%d: %s. This does not have to be a problem.', $id, $e->getMessage()); $message = sprintf('Could not JSON decode preference row #%d: %s. This does not have to be a problem.', $id, $e->getMessage());
$this->friendlyError($message); $this->friendlyError($message);

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Enums\AccountTypeEnum; use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
@@ -141,7 +142,7 @@ class UpgradesAccountCurrencies extends Command
return; return;
} }
// do not match and opening balance id is not null. // do not match and opening balance id is not null.
if ($accountCurrency !== $obCurrency && null !== $openingBalance) { if ($accountCurrency !== $obCurrency && $openingBalance instanceof TransactionJournal) {
// update opening balance: // update opening balance:
$openingBalance->transaction_currency_id = $accountCurrency; $openingBalance->transaction_currency_id = $accountCurrency;
$openingBalance->save(); $openingBalance->save();

View File

@@ -123,7 +123,7 @@ class UpgradesBillsToRules extends Command
$groupTitle = (string) trans('firefly.rulegroup_for_bills_title', [], $language); $groupTitle = (string) trans('firefly.rulegroup_for_bills_title', [], $language);
$ruleGroup = $this->ruleGroupRepository->findByTitle($groupTitle); $ruleGroup = $this->ruleGroupRepository->findByTitle($groupTitle);
if (null === $ruleGroup) { if (!$ruleGroup instanceof RuleGroup) {
$ruleGroup = $this->ruleGroupRepository->store( $ruleGroup = $this->ruleGroupRepository->store(
[ [
'title' => (string) trans('firefly.rulegroup_for_bills_title', [], $language), 'title' => (string) trans('firefly.rulegroup_for_bills_title', [], $language),

View File

@@ -27,8 +27,10 @@ namespace FireflyIII\Console\Commands\Upgrade;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Safe\Exceptions\InfoException; use Safe\Exceptions\InfoException;
use function Safe\set_time_limit;
try { try {
\Safe\set_time_limit(0); set_time_limit(0);
} catch (InfoException) { } catch (InfoException) {
Log::warning('set_time_limit returned false. This could be an issue, unless you also run XDebug.'); Log::warning('set_time_limit returned false. This could be an issue, unless you also run XDebug.');
} }

View File

@@ -122,7 +122,7 @@ class UpgradesLiabilities extends Command
{ {
$source = $this->getSourceTransaction($openingBalance); $source = $this->getSourceTransaction($openingBalance);
$destination = $this->getDestinationTransaction($openingBalance); $destination = $this->getDestinationTransaction($openingBalance);
if (null === $source || null === $destination) { if (!$source instanceof Transaction || !$destination instanceof Transaction) {
return; return;
} }
// source MUST be the liability. // source MUST be the liability.

View File

@@ -30,6 +30,8 @@ use FireflyIII\Models\RecurrenceMeta;
use FireflyIII\Models\RecurrenceTransactionMeta; use FireflyIII\Models\RecurrenceTransactionMeta;
use Illuminate\Console\Command; use Illuminate\Console\Command;
use function Safe\json_encode;
class UpgradesRecurrenceMetaData extends Command class UpgradesRecurrenceMetaData extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
@@ -100,7 +102,7 @@ class UpgradesRecurrenceMetaData extends Command
if ('tags' === $meta->name) { if ('tags' === $meta->name) {
$array = explode(',', $meta->value); $array = explode(',', $meta->value);
$value = \Safe\json_encode($array, JSON_THROW_ON_ERROR); $value = json_encode($array, JSON_THROW_ON_ERROR);
} }
RecurrenceTransactionMeta::create( RecurrenceTransactionMeta::create(

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Console\Commands\Upgrade; namespace FireflyIII\Console\Commands\Upgrade;
use Carbon\Carbon;
use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Console\Commands\ShowsFriendlyMessages;
use FireflyIII\Factory\TransactionGroupFactory; use FireflyIII\Factory\TransactionGroupFactory;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
@@ -192,7 +193,7 @@ class UpgradesToGroups extends Command
app('log')->debug(sprintf('Now going to add transaction #%d to the array.', $transaction->id)); app('log')->debug(sprintf('Now going to add transaction #%d to the array.', $transaction->id));
$opposingTr = $this->findOpposingTransaction($journal, $transaction); $opposingTr = $this->findOpposingTransaction($journal, $transaction);
if (null === $opposingTr) { if (!$opposingTr instanceof Transaction) {
$this->friendlyError( $this->friendlyError(
sprintf( sprintf(
'Journal #%d has no opposing transaction for transaction #%d. Cannot upgrade this entry.', 'Journal #%d has no opposing transaction for transaction #%d. Cannot upgrade this entry.',
@@ -367,8 +368,8 @@ class UpgradesToGroups extends Command
{ {
$groupId = DB::table('transaction_groups')->insertGetId( $groupId = DB::table('transaction_groups')->insertGetId(
[ [
'created_at' => date('Y-m-d H:i:s'), 'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'), 'updated_at' => Carbon::now()->format('Y-m-d H:i:s'),
'title' => null, 'title' => null,
'user_id' => $array['user_id'], 'user_id' => $array['user_id'],
] ]

View File

@@ -202,7 +202,7 @@ class UpgradesTransferCurrencies extends Command
{ {
$this->sourceTransaction = $this->getSourceTransaction($journal); $this->sourceTransaction = $this->getSourceTransaction($journal);
$this->sourceAccount = $this->sourceTransaction?->account; $this->sourceAccount = $this->sourceTransaction?->account;
$this->sourceCurrency = null === $this->sourceAccount ? null : $this->getCurrency($this->sourceAccount); $this->sourceCurrency = $this->sourceAccount instanceof Account ? $this->getCurrency($this->sourceAccount) : null;
} }
private function getSourceTransaction(TransactionJournal $transfer): ?Transaction private function getSourceTransaction(TransactionJournal $transfer): ?Transaction
@@ -221,7 +221,7 @@ class UpgradesTransferCurrencies extends Command
return $this->accountCurrencies[$accountId]; return $this->accountCurrencies[$accountId];
} }
$currency = $this->accountRepos->getAccountCurrency($account); $currency = $this->accountRepos->getAccountCurrency($account);
if (null === $currency) { if (!$currency instanceof TransactionCurrency) {
$this->accountCurrencies[$accountId] = 0; $this->accountCurrencies[$accountId] = 0;
return null; return null;
@@ -238,7 +238,7 @@ class UpgradesTransferCurrencies extends Command
{ {
$this->destinationTransaction = $this->getDestinationTransaction($journal); $this->destinationTransaction = $this->getDestinationTransaction($journal);
$this->destinationAccount = $this->destinationTransaction?->account; $this->destinationAccount = $this->destinationTransaction?->account;
$this->destinationCurrency = null === $this->destinationAccount ? null : $this->getCurrency($this->destinationAccount); $this->destinationCurrency = $this->destinationAccount instanceof Account ? $this->getCurrency($this->destinationAccount) : null;
} }
private function getDestinationTransaction(TransactionJournal $transfer): ?Transaction private function getDestinationTransaction(TransactionJournal $transfer): ?Transaction
@@ -252,15 +252,15 @@ class UpgradesTransferCurrencies extends Command
*/ */
private function isEmptyTransactions(): bool private function isEmptyTransactions(): bool
{ {
return null === $this->sourceTransaction || null === $this->destinationTransaction return !$this->sourceTransaction instanceof Transaction || !$this->destinationTransaction instanceof Transaction
|| null === $this->sourceAccount || !$this->sourceAccount instanceof Account
|| null === $this->destinationAccount; || !$this->destinationAccount instanceof Account;
} }
private function isNoCurrencyPresent(): bool private function isNoCurrencyPresent(): bool
{ {
// source account must have a currency preference. // source account must have a currency preference.
if (null === $this->sourceCurrency) { if (!$this->sourceCurrency instanceof TransactionCurrency) {
$message = sprintf('Account #%d ("%s") must have currency preference but has none.', $this->sourceAccount->id, $this->sourceAccount->name); $message = sprintf('Account #%d ("%s") must have currency preference but has none.', $this->sourceAccount->id, $this->sourceAccount->name);
app('log')->error($message); app('log')->error($message);
$this->friendlyError($message); $this->friendlyError($message);
@@ -269,7 +269,7 @@ class UpgradesTransferCurrencies extends Command
} }
// destination account must have a currency preference. // destination account must have a currency preference.
if (null === $this->destinationCurrency) { if (!$this->destinationCurrency instanceof TransactionCurrency) {
$message = sprintf( $message = sprintf(
'Account #%d ("%s") must have currency preference but has none.', 'Account #%d ("%s") must have currency preference but has none.',
$this->destinationAccount->id, $this->destinationAccount->id,
@@ -290,7 +290,7 @@ class UpgradesTransferCurrencies extends Command
*/ */
private function fixSourceNoCurrency(): void private function fixSourceNoCurrency(): void
{ {
if (null === $this->sourceTransaction->transaction_currency_id && null !== $this->sourceCurrency) { if (null === $this->sourceTransaction->transaction_currency_id && $this->sourceCurrency instanceof TransactionCurrency) {
$this->sourceTransaction $this->sourceTransaction
->transaction_currency_id ->transaction_currency_id
= $this->sourceCurrency->id = $this->sourceCurrency->id
@@ -312,7 +312,7 @@ class UpgradesTransferCurrencies extends Command
*/ */
private function fixSourceUnmatchedCurrency(): void private function fixSourceUnmatchedCurrency(): void
{ {
if (null !== $this->sourceCurrency if ($this->sourceCurrency instanceof TransactionCurrency
&& null === $this->sourceTransaction->foreign_amount && null === $this->sourceTransaction->foreign_amount
&& (int) $this->sourceTransaction->transaction_currency_id !== $this->sourceCurrency->id && (int) $this->sourceTransaction->transaction_currency_id !== $this->sourceCurrency->id
) { ) {
@@ -336,7 +336,7 @@ class UpgradesTransferCurrencies extends Command
*/ */
private function fixDestNoCurrency(): void private function fixDestNoCurrency(): void
{ {
if (null === $this->destinationTransaction->transaction_currency_id && null !== $this->destinationCurrency) { if (null === $this->destinationTransaction->transaction_currency_id && $this->destinationCurrency instanceof TransactionCurrency) {
$this->destinationTransaction $this->destinationTransaction
->transaction_currency_id ->transaction_currency_id
= $this->destinationCurrency->id = $this->destinationCurrency->id
@@ -358,7 +358,7 @@ class UpgradesTransferCurrencies extends Command
*/ */
private function fixDestinationUnmatchedCurrency(): void private function fixDestinationUnmatchedCurrency(): void
{ {
if (null !== $this->destinationCurrency if ($this->destinationCurrency instanceof TransactionCurrency
&& null === $this->destinationTransaction->foreign_amount && null === $this->destinationTransaction->foreign_amount
&& (int) $this->destinationTransaction->transaction_currency_id !== $this->destinationCurrency->id && (int) $this->destinationTransaction->transaction_currency_id !== $this->destinationCurrency->id
) { ) {

View File

@@ -120,7 +120,7 @@ class UpgradesVariousCurrencyInformation extends Command
$leadTransaction = $this->getLeadTransaction($journal); $leadTransaction = $this->getLeadTransaction($journal);
if (null === $leadTransaction) { if (!$leadTransaction instanceof Transaction) {
$this->friendlyError(sprintf('Could not reliably determine which transaction is in the lead for transaction journal #%d.', $journal->id)); $this->friendlyError(sprintf('Could not reliably determine which transaction is in the lead for transaction journal #%d.', $journal->id));
return; return;
@@ -129,7 +129,7 @@ class UpgradesVariousCurrencyInformation extends Command
$account = $leadTransaction->account; $account = $leadTransaction->account;
$currency = $this->getCurrency($account); $currency = $this->getCurrency($account);
$isMultiCurrency = $this->isMultiCurrency($account); $isMultiCurrency = $this->isMultiCurrency($account);
if (null === $currency) { if (!$currency instanceof TransactionCurrency) {
$this->friendlyError( $this->friendlyError(
sprintf( sprintf(
'Account #%d ("%s") has no currency preference, so transaction journal #%d can\'t be corrected', 'Account #%d ("%s") has no currency preference, so transaction journal #%d can\'t be corrected',
@@ -227,7 +227,7 @@ class UpgradesVariousCurrencyInformation extends Command
return $this->accountCurrencies[$accountId]; return $this->accountCurrencies[$accountId];
} }
$currency = $this->accountRepos->getAccountCurrency($account); $currency = $this->accountRepos->getAccountCurrency($account);
if (null === $currency) { if (!$currency instanceof TransactionCurrency) {
$this->accountCurrencies[$accountId] = 0; $this->accountCurrencies[$accountId] = 0;
return null; return null;

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Exceptions; namespace FireflyIII\Exceptions;
use Carbon\Carbon;
use Brick\Math\Exception\NumberFormatException; use Brick\Math\Exception\NumberFormatException;
use FireflyIII\Jobs\MailError; use FireflyIII\Jobs\MailError;
use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Auth\Access\AuthorizationException;
@@ -48,6 +49,9 @@ use ErrorException;
use Override; use Override;
use Throwable; use Throwable;
use function Safe\json_encode;
use function Safe\parse_url;
// temp // temp
/** /**
* Class Handler * Class Handler
@@ -231,7 +235,7 @@ class Handler extends ExceptionHandler
$data = [ $data = [
'class' => $e::class, 'class' => $e::class,
'errorMessage' => $e->getMessage(), 'errorMessage' => $e->getMessage(),
'time' => date('r'), 'time' => Carbon::now()->format('r'),
'stackTrace' => $e->getTraceAsString(), 'stackTrace' => $e->getTraceAsString(),
'file' => $e->getFile(), 'file' => $e->getFile(),
'line' => $e->getLine(), 'line' => $e->getLine(),
@@ -242,7 +246,7 @@ class Handler extends ExceptionHandler
'json' => request()->acceptsJson(), 'json' => request()->acceptsJson(),
'method' => request()->method(), 'method' => request()->method(),
'headers' => $headers, 'headers' => $headers,
'post' => 'POST' === request()->method() ? \Safe\json_encode(request()->all()) : '', 'post' => 'POST' === request()->method() ? json_encode(request()->all()) : '',
]; ];
// create job that will mail. // create job that will mail.
@@ -289,8 +293,8 @@ class Handler extends ExceptionHandler
} }
$safe = route('index'); $safe = route('index');
$previous = $exception->redirectTo; $previous = $exception->redirectTo;
$previousHost = \Safe\parse_url($previous, PHP_URL_HOST); $previousHost = parse_url($previous, PHP_URL_HOST);
$safeHost = \Safe\parse_url($safe, PHP_URL_HOST); $safeHost = parse_url($safe, PHP_URL_HOST);
return null !== $previousHost && $previousHost === $safeHost ? $previous : $safe; return null !== $previousHost && $previousHost === $safeHost ? $previous : $safe;
} }

View File

@@ -75,7 +75,7 @@ class AccountFactory
app('log')->debug(sprintf('findOrCreate("%s", "%s")', $accountName, $accountType)); app('log')->debug(sprintf('findOrCreate("%s", "%s")', $accountName, $accountType));
$type = $this->accountRepository->getAccountTypeByType($accountType); $type = $this->accountRepository->getAccountTypeByType($accountType);
if (null === $type) { if (!$type instanceof AccountType) {
throw new FireflyException(sprintf('Cannot find account type "%s"', $accountType)); throw new FireflyException(sprintf('Cannot find account type "%s"', $accountType));
} }
$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();
@@ -111,7 +111,7 @@ class AccountFactory
// account may exist already: // account may exist already:
$return = $this->find($data['name'], $type->type); $return = $this->find($data['name'], $type->type);
if (null !== $return) { if ($return instanceof Account) {
return $return; return $return;
} }

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Factory; namespace FireflyIII\Factory;
use FireflyIII\Models\ObjectGroup;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Bill; use FireflyIII\Models\Bill;
use FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups; use FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups;
@@ -93,7 +94,7 @@ class BillFactory
$objectGroupTitle = $data['object_group_title'] ?? ''; $objectGroupTitle = $data['object_group_title'] ?? '';
if ('' !== $objectGroupTitle) { if ('' !== $objectGroupTitle) {
$objectGroup = $this->findOrCreateObjectGroup($objectGroupTitle); $objectGroup = $this->findOrCreateObjectGroup($objectGroupTitle);
if (null !== $objectGroup) { if ($objectGroup instanceof ObjectGroup) {
$bill->objectGroups()->sync([$objectGroup->id]); $bill->objectGroups()->sync([$objectGroup->id]);
$bill->save(); $bill->save();
} }
@@ -102,7 +103,7 @@ class BillFactory
$objectGroupId = (int) ($data['object_group_id'] ?? 0); $objectGroupId = (int) ($data['object_group_id'] ?? 0);
if (0 !== $objectGroupId) { if (0 !== $objectGroupId) {
$objectGroup = $this->findObjectGroupById($objectGroupId); $objectGroup = $this->findObjectGroupById($objectGroupId);
if (null !== $objectGroup) { if ($objectGroup instanceof ObjectGroup) {
$bill->objectGroups()->sync([$objectGroup->id]); $bill->objectGroups()->sync([$objectGroup->id]);
$bill->save(); $bill->save();
} }
@@ -124,7 +125,7 @@ class BillFactory
// then find by name: // then find by name:
if (null === $bill && '' !== $billName) { if (null === $bill && '' !== $billName) {
$bill = $this->findByName($billName); return $this->findByName($billName);
} }
return $bill; return $bill;

View File

@@ -53,7 +53,7 @@ class BudgetFactory
if ('' !== $budgetName) { if ('' !== $budgetName) {
$budget = $this->findByName($budgetName); $budget = $this->findByName($budgetName);
if (null !== $budget) { if ($budget instanceof Budget) {
return $budget; return $budget;
} }
} }

View File

@@ -59,7 +59,7 @@ class CategoryFactory
if ('' !== $categoryName) { if ('' !== $categoryName) {
$category = $this->findByName($categoryName); $category = $this->findByName($categoryName);
if (null !== $category) { if ($category instanceof Category) {
return $category; return $category;
} }

View File

@@ -37,7 +37,7 @@ class PiggyBankEventFactory
public function create(TransactionJournal $journal, ?PiggyBank $piggyBank): void public function create(TransactionJournal $journal, ?PiggyBank $piggyBank): void
{ {
app('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) { if (!$piggyBank instanceof PiggyBank) {
app('log')->debug('Piggy bank is null'); app('log')->debug('Piggy bank is null');
return; return;

View File

@@ -23,6 +23,8 @@ declare(strict_types=1);
namespace FireflyIII\Factory; namespace FireflyIII\Factory;
use FireflyIII\Models\ObjectGroup;
use FireflyIII\Models\Account;
use FireflyIII\Events\Model\PiggyBank\ChangedAmount; use FireflyIII\Events\Model\PiggyBank\ChangedAmount;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\PiggyBank; use FireflyIII\Models\PiggyBank;
@@ -35,6 +37,8 @@ use FireflyIII\User;
use Illuminate\Database\QueryException; use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use function Safe\json_encode;
/** /**
* Class PiggyBankFactory * Class PiggyBankFactory
*/ */
@@ -99,7 +103,7 @@ class PiggyBankFactory
$objectGroupTitle = $data['object_group_title'] ?? ''; $objectGroupTitle = $data['object_group_title'] ?? '';
if ('' !== $objectGroupTitle) { if ('' !== $objectGroupTitle) {
$objectGroup = $this->findOrCreateObjectGroup($objectGroupTitle); $objectGroup = $this->findOrCreateObjectGroup($objectGroupTitle);
if (null !== $objectGroup) { if ($objectGroup instanceof ObjectGroup) {
$piggyBank->objectGroups()->sync([$objectGroup->id]); $piggyBank->objectGroups()->sync([$objectGroup->id]);
} }
} }
@@ -107,7 +111,7 @@ class PiggyBankFactory
$objectGroupId = (int) ($data['object_group_id'] ?? 0); $objectGroupId = (int) ($data['object_group_id'] ?? 0);
if (0 !== $objectGroupId) { if (0 !== $objectGroupId) {
$objectGroup = $this->findObjectGroupById($objectGroupId); $objectGroup = $this->findObjectGroupById($objectGroupId);
if (null !== $objectGroup) { if ($objectGroup instanceof ObjectGroup) {
$piggyBank->objectGroups()->sync([$objectGroup->id]); $piggyBank->objectGroups()->sync([$objectGroup->id]);
} }
} }
@@ -241,7 +245,7 @@ class PiggyBankFactory
/** @var array $info */ /** @var array $info */
foreach ($accounts as $info) { foreach ($accounts as $info) {
$account = $this->accountRepository->find((int) ($info['account_id'] ?? 0)); $account = $this->accountRepository->find((int) ($info['account_id'] ?? 0));
if (null === $account) { if (!$account instanceof Account) {
Log::debug(sprintf('Account #%d not found, skipping.', (int) ($info['account_id'] ?? 0))); Log::debug(sprintf('Account #%d not found, skipping.', (int) ($info['account_id'] ?? 0)));
continue; continue;
@@ -284,7 +288,7 @@ class PiggyBankFactory
Log::debug(sprintf('Will link account #%d with info: ', $account->id), $toBeLinked[$account->id]); Log::debug(sprintf('Will link account #%d with info: ', $account->id), $toBeLinked[$account->id]);
} }
} }
Log::debug(sprintf('Link information: %s', \Safe\json_encode($toBeLinked))); Log::debug(sprintf('Link information: %s', json_encode($toBeLinked)));
if (0 !== count($toBeLinked)) { if (0 !== count($toBeLinked)) {
$piggyBank->accounts()->sync($toBeLinked); $piggyBank->accounts()->sync($toBeLinked);
} }

View File

@@ -59,7 +59,7 @@ class TagFactory
'zoom_level' => null, 'zoom_level' => null,
] ]
); );
if (null === $newTag) { if (!$newTag instanceof Tag) {
app('log')->error(sprintf('TagFactory::findOrCreate("%s") but tag is unexpectedly NULL!', $tag)); app('log')->error(sprintf('TagFactory::findOrCreate("%s") but tag is unexpectedly NULL!', $tag));
return null; return null;

View File

@@ -118,7 +118,7 @@ class TransactionFactory
); );
// do foreign currency thing: add foreign currency info to $one and $two if necessary. // do foreign currency thing: add foreign currency info to $one and $two if necessary.
if (null !== $this->foreignCurrency if ($this->foreignCurrency instanceof TransactionCurrency
&& null !== $foreignAmount && null !== $foreignAmount
&& $this->foreignCurrency->id !== $this->currency->id) { && $this->foreignCurrency->id !== $this->currency->id) {
$result->foreign_currency_id = $this->foreignCurrency->id; $result->foreign_currency_id = $this->foreignCurrency->id;

View File

@@ -24,6 +24,8 @@ declare(strict_types=1);
namespace FireflyIII\Factory; namespace FireflyIII\Factory;
use FireflyIII\Models\Bill;
use FireflyIII\Models\PiggyBank;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum; use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum; use FireflyIII\Enums\TransactionTypeEnum;
@@ -54,6 +56,8 @@ use Illuminate\Support\Facades\Log;
use Exception; use Exception;
use JsonException; use JsonException;
use function Safe\json_encode;
/** /**
* Class TransactionJournalFactory * Class TransactionJournalFactory
* *
@@ -122,10 +126,10 @@ class TransactionJournalFactory
foreach ($transactions as $index => $row) { foreach ($transactions as $index => $row) {
Log::debug(sprintf('Now creating journal %d/%d', $index + 1, count($transactions))); Log::debug(sprintf('Now creating journal %d/%d', $index + 1, count($transactions)));
$journal = $this->createJournal(new NullArrayObject($row)); $journal = $this->createJournal(new NullArrayObject($row));
if (null !== $journal) { if ($journal instanceof TransactionJournal) {
$collection->push($journal); $collection->push($journal);
} }
if (null === $journal) { if (!$journal instanceof TransactionJournal) {
Log::error('The createJournal() method returned NULL. This may indicate an error.'); Log::error('The createJournal() method returned NULL. This may indicate an error.');
} }
} }
@@ -175,7 +179,7 @@ class TransactionJournalFactory
$foreignCurrency = $this->currencyRepository->findCurrencyNull($row['foreign_currency_id'], $row['foreign_currency_code']); $foreignCurrency = $this->currencyRepository->findCurrencyNull($row['foreign_currency_id'], $row['foreign_currency_code']);
$bill = $this->billRepository->findBill((int) $row['bill_id'], $row['bill_name']); $bill = $this->billRepository->findBill((int) $row['bill_id'], $row['bill_name']);
$billId = TransactionTypeEnum::WITHDRAWAL->value === $type->type && null !== $bill ? $bill->id : null; $billId = TransactionTypeEnum::WITHDRAWAL->value === $type->type && $bill instanceof Bill ? $bill->id : null;
$description = (string) $row['description']; $description = (string) $row['description'];
// Manipulate basic fields // Manipulate basic fields
@@ -286,7 +290,7 @@ class TransactionJournalFactory
// see the currency they expect to see. // see the currency they expect to see.
$amount = (string) $row['amount']; $amount = (string) $row['amount'];
$foreignAmount = (string) $row['foreign_amount']; $foreignAmount = (string) $row['foreign_amount'];
if (null !== $foreignCurrency && $foreignCurrency->id !== $currency->id if ($foreignCurrency instanceof TransactionCurrency && $foreignCurrency->id !== $currency->id
&& (TransactionTypeEnum::TRANSFER->value === $type->type || $this->isBetweenAssetAndLiability($sourceAccount, $destinationAccount)) && (TransactionTypeEnum::TRANSFER->value === $type->type || $this->isBetweenAssetAndLiability($sourceAccount, $destinationAccount))
) { ) {
$transactionFactory->setCurrency($foreignCurrency); $transactionFactory->setCurrency($foreignCurrency);
@@ -325,7 +329,7 @@ class TransactionJournalFactory
unset($dataRow['import_hash_v2'], $dataRow['original_source']); unset($dataRow['import_hash_v2'], $dataRow['original_source']);
try { try {
$json = \Safe\json_encode($dataRow, JSON_THROW_ON_ERROR); $json = json_encode($dataRow, JSON_THROW_ON_ERROR);
} catch (JsonException $e) { } catch (JsonException $e) {
Log::error(sprintf('Could not encode dataRow: %s', $e->getMessage())); Log::error(sprintf('Could not encode dataRow: %s', $e->getMessage()));
$json = microtime(); $json = microtime();
@@ -354,7 +358,7 @@ class TransactionJournalFactory
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id') ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')
->whereNotNull('transaction_journals.id') ->whereNotNull('transaction_journals.id')
->where('transaction_journals.user_id', $this->user->id) ->where('transaction_journals.user_id', $this->user->id)
->where('data', \Safe\json_encode($hash, JSON_THROW_ON_ERROR)) ->where('data', json_encode($hash, JSON_THROW_ON_ERROR))
->with(['transactionJournal', 'transactionJournal.transactionGroup']) ->with(['transactionJournal', 'transactionJournal.transactionGroup'])
->first(['journal_meta.*']) ->first(['journal_meta.*'])
; ;
@@ -427,12 +431,12 @@ class TransactionJournalFactory
private function reconciliationSanityCheck(?Account $sourceAccount, ?Account $destinationAccount): array private function reconciliationSanityCheck(?Account $sourceAccount, ?Account $destinationAccount): array
{ {
Log::debug(sprintf('Now in %s', __METHOD__)); Log::debug(sprintf('Now in %s', __METHOD__));
if (null !== $sourceAccount && null !== $destinationAccount) { if ($sourceAccount instanceof Account && $destinationAccount instanceof Account) {
Log::debug('Both accounts exist, simply return them.'); Log::debug('Both accounts exist, simply return them.');
return [$sourceAccount, $destinationAccount]; return [$sourceAccount, $destinationAccount];
} }
if (null === $destinationAccount) { if (!$destinationAccount instanceof Account) {
Log::debug('Destination account is NULL, source account is not.'); Log::debug('Destination account is NULL, source account is not.');
$account = $this->accountRepository->getReconciliation($sourceAccount); $account = $this->accountRepository->getReconciliation($sourceAccount);
Log::debug(sprintf('Will return account #%d ("%s") of type "%s"', $account->id, $account->name, $account->accountType->type)); Log::debug(sprintf('Will return account #%d ("%s") of type "%s"', $account->id, $account->name, $account->accountType->type));
@@ -440,7 +444,7 @@ class TransactionJournalFactory
return [$sourceAccount, $account]; return [$sourceAccount, $account];
} }
if (null === $sourceAccount) { // @phpstan-ignore-line if (!$sourceAccount instanceof Account) { // @phpstan-ignore-line
Log::debug('Source account is NULL, destination account is not.'); Log::debug('Source account is NULL, destination account is not.');
$account = $this->accountRepository->getReconciliation($destinationAccount); $account = $this->accountRepository->getReconciliation($destinationAccount);
Log::debug(sprintf('Will return account #%d ("%s") of type "%s"', $account->id, $account->name, $account->accountType->type)); Log::debug(sprintf('Will return account #%d ("%s") of type "%s"', $account->id, $account->name, $account->accountType->type));
@@ -482,7 +486,7 @@ class TransactionJournalFactory
/** @var null|TransactionCurrency $preference */ /** @var null|TransactionCurrency $preference */
$preference = $this->accountRepository->getAccountCurrency($account); $preference = $this->accountRepository->getAccountCurrency($account);
if (null === $preference && null === $currency) { if (null === $preference && !$currency instanceof TransactionCurrency) {
// return user's default: // return user's default:
return app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup); return app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup);
} }
@@ -498,10 +502,10 @@ class TransactionJournalFactory
private function compareCurrencies(?TransactionCurrency $currency, ?TransactionCurrency $foreignCurrency): ?TransactionCurrency private function compareCurrencies(?TransactionCurrency $currency, ?TransactionCurrency $foreignCurrency): ?TransactionCurrency
{ {
Log::debug(sprintf('Now in compareCurrencies("%s", "%s")', $currency?->code, $foreignCurrency?->code)); Log::debug(sprintf('Now in compareCurrencies("%s", "%s")', $currency?->code, $foreignCurrency?->code));
if (null === $currency) { if (!$currency instanceof TransactionCurrency) {
return null; return null;
} }
if (null !== $foreignCurrency && $foreignCurrency->id === $currency->id) { if ($foreignCurrency instanceof TransactionCurrency && $foreignCurrency->id === $currency->id) {
return null; return null;
} }
@@ -558,7 +562,7 @@ class TransactionJournalFactory
$piggyBank = $this->piggyRepository->findPiggyBank((int) $data['piggy_bank_id'], $data['piggy_bank_name']); $piggyBank = $this->piggyRepository->findPiggyBank((int) $data['piggy_bank_id'], $data['piggy_bank_name']);
if (null !== $piggyBank) { if ($piggyBank instanceof PiggyBank) {
$this->piggyEventFactory->create($journal, $piggyBank); $this->piggyEventFactory->create($journal, $piggyBank);
Log::debug('Create piggy event.'); Log::debug('Create piggy event.');