mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 18:41:08 +00:00
Update configuration and fix some files.
This commit is contained in:
@@ -29,7 +29,7 @@ rm -f .php-cs-fixer.cache
|
||||
PHP_CS_FIXER_IGNORE_ENV=true ./vendor/bin/php-cs-fixer fix \
|
||||
--config $SCRIPT_DIR/php-cs-fixer/.php-cs-fixer.php \
|
||||
--format=txt -v \
|
||||
--allow-risky=yes -v
|
||||
--allow-risky=yes
|
||||
|
||||
EXIT_CODE=$?
|
||||
|
||||
|
@@ -33,6 +33,15 @@ return RectorConfig::configure()
|
||||
->withPaths([
|
||||
// __DIR__ . '/../app',
|
||||
__DIR__ . '/../app/Api',
|
||||
__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__ . '/../config',
|
||||
@@ -66,5 +75,4 @@ __DIR__ . '/../app/Http',
|
||||
->withTypeCoverageLevel(0)
|
||||
->withDeadCodeLevel(0)
|
||||
->withCodeQualityLevel(0)
|
||||
|
||||
->withImportNames(removeUnusedImports: true);// import statements instead of full classes.
|
||||
|
@@ -76,7 +76,7 @@ class CorrectsOpeningBalanceCurrencies extends Command
|
||||
{
|
||||
// get the asset account for this opening balance:
|
||||
$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);
|
||||
app('log')->warning($message);
|
||||
$this->friendlyError($message);
|
||||
|
@@ -387,7 +387,7 @@ class CorrectsUnevenAmount extends Command
|
||||
|
||||
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.');
|
||||
|
||||
continue;
|
||||
|
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Console\Commands\Export;
|
||||
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
|
||||
use FireflyIII\Console\Commands\VerifiesAccessToken;
|
||||
@@ -38,6 +39,8 @@ use Illuminate\Support\Collection;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
|
||||
use function Safe\file_put_contents;
|
||||
|
||||
class ExportsData extends Command
|
||||
{
|
||||
use ShowsFriendlyMessages;
|
||||
@@ -203,7 +206,7 @@ class ExportsData extends Command
|
||||
|
||||
if (true === $error && 'start' === $field) {
|
||||
$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();
|
||||
|
||||
return $date;
|
||||
@@ -275,7 +278,7 @@ class ExportsData extends Command
|
||||
*/
|
||||
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) {
|
||||
$file = sprintf('%s%s_%s.csv', $options['directory'], $date, $key);
|
||||
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));
|
||||
}
|
||||
// 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));
|
||||
}
|
||||
}
|
||||
|
@@ -43,6 +43,9 @@ use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Collection;
|
||||
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
|
||||
* 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' === (string) config('database.default')) {
|
||||
DB::connection()->getPdo()->sqliteCreateFunction('REGEXP', static function ($pattern, $value) {
|
||||
\Safe\mb_regex_encoding('UTF-8');
|
||||
mb_regex_encoding('UTF-8');
|
||||
$pattern = trim($pattern, '"');
|
||||
|
||||
return (false !== mb_ereg($pattern, (string) $value)) ? 1 : 0;
|
||||
@@ -234,7 +237,7 @@ class ForcesDecimalSize extends Command
|
||||
/** @var Builder $query */
|
||||
$query = Account::leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_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 {
|
||||
foreach ($fields as $field) {
|
||||
@@ -338,7 +341,7 @@ class ForcesDecimalSize extends Command
|
||||
->leftJoin('accounts', 'piggy_banks.account_id', '=', 'accounts.id')
|
||||
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_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 {
|
||||
foreach ($fields as $field) {
|
||||
$q->orWhere(
|
||||
@@ -394,7 +397,7 @@ class ForcesDecimalSize extends Command
|
||||
->leftJoin('accounts', 'piggy_banks.account_id', '=', 'accounts.id')
|
||||
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_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 {
|
||||
foreach ($fields as $field) {
|
||||
$q->orWhere(
|
||||
@@ -448,7 +451,7 @@ class ForcesDecimalSize extends Command
|
||||
$query = PiggyBank::leftJoin('accounts', 'piggy_banks.account_id', '=', 'accounts.id')
|
||||
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_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 {
|
||||
foreach ($fields as $field) {
|
||||
$q->orWhere(
|
||||
|
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Console\Commands\System;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Support\System\GeneratesInstallationId;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
@@ -111,8 +112,8 @@ class OutputsInstructions extends Command
|
||||
*/
|
||||
private function showLogo(): void
|
||||
{
|
||||
$today = date('m-d');
|
||||
$month = date('m');
|
||||
$today = Carbon::now()->format('m-d');
|
||||
$month = Carbon::now()->format('m');
|
||||
// variation in colors and effects just because I can!
|
||||
// default is Ukraine flag:
|
||||
$colors = ['blue', 'blue', 'blue', 'yellow', 'yellow', 'yellow', 'default', 'default'];
|
||||
|
@@ -31,6 +31,11 @@ use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
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
|
||||
{
|
||||
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()));
|
||||
$decryptedContent = $encryptedContent;
|
||||
}
|
||||
$tempFileName = \Safe\tempnam(sys_get_temp_dir(), 'FireflyIII');
|
||||
$tempFileName = tempnam(sys_get_temp_dir(), 'FireflyIII');
|
||||
if (false === $tempFileName) {
|
||||
app('log')->error(sprintf('Could not create temporary file for attachment #%d', $attachment->id));
|
||||
|
||||
exit(1);
|
||||
}
|
||||
\Safe\file_put_contents($tempFileName, $decryptedContent);
|
||||
$attachment->md5 = (string) \Safe\md5_file($tempFileName);
|
||||
$attachment->mime = (string) \Safe\mime_content_type($tempFileName);
|
||||
file_put_contents($tempFileName, $decryptedContent);
|
||||
$attachment->md5 = (string) md5_file($tempFileName);
|
||||
$attachment->mime = (string) mime_content_type($tempFileName);
|
||||
$attachment->save();
|
||||
$this->friendlyInfo(sprintf('Fixed attachment #%d', $attachment->id));
|
||||
}
|
||||
|
@@ -30,6 +30,8 @@ use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use League\Flysystem\FilesystemException;
|
||||
|
||||
use function Safe\json_decode;
|
||||
|
||||
class VerifySecurityAlerts extends Command
|
||||
{
|
||||
use ShowsFriendlyMessages;
|
||||
@@ -57,7 +59,7 @@ class VerifySecurityAlerts extends Command
|
||||
return 0;
|
||||
}
|
||||
$content = $disk->get('alerts.json');
|
||||
$json = \Safe\json_decode($content, true, 10);
|
||||
$json = json_decode((string) $content, true, 10);
|
||||
|
||||
/** @var array $array */
|
||||
foreach ($json as $array) {
|
||||
|
@@ -248,7 +248,7 @@ class ApplyRules extends Command
|
||||
|
||||
foreach ($ruleList as $ruleId) {
|
||||
$rule = $this->ruleRepository->find((int) $ruleId);
|
||||
if (null !== $rule && true === $rule->active) {
|
||||
if ($rule instanceof Rule && true === $rule->active) {
|
||||
$this->ruleSelection[] = $rule->id;
|
||||
}
|
||||
}
|
||||
|
@@ -134,7 +134,7 @@ class Cron extends Command
|
||||
$exchangeRates = new ExchangeRatesCronjob();
|
||||
$exchangeRates->setForce($force);
|
||||
// set date in cron job:
|
||||
if (null !== $date) {
|
||||
if ($date instanceof Carbon) {
|
||||
$exchangeRates->setDate($date);
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ class Cron extends Command
|
||||
$recurring->setForce($force);
|
||||
|
||||
// set date in cron job:
|
||||
if (null !== $date) {
|
||||
if ($date instanceof Carbon) {
|
||||
$recurring->setDate($date);
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ class Cron extends Command
|
||||
$autoBudget = new AutoBudgetCronjob();
|
||||
$autoBudget->setForce($force);
|
||||
// set date in cron job:
|
||||
if (null !== $date) {
|
||||
if ($date instanceof Carbon) {
|
||||
$autoBudget->setDate($date);
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ class Cron extends Command
|
||||
$autoBudget = new BillWarningCronjob();
|
||||
$autoBudget->setForce($force);
|
||||
// set date in cron job:
|
||||
if (null !== $date) {
|
||||
if ($date instanceof Carbon) {
|
||||
$autoBudget->setDate($date);
|
||||
}
|
||||
|
||||
|
@@ -120,7 +120,7 @@ class AddsTransactionIdentifiers extends Command
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$opposing = $this->findOpposing($transaction, $exclude);
|
||||
if (null !== $opposing) {
|
||||
if ($opposing instanceof Transaction) {
|
||||
// give both a new identifier:
|
||||
$transaction->identifier = $identifier;
|
||||
$opposing->identifier = $identifier;
|
||||
|
@@ -34,6 +34,8 @@ use Illuminate\Support\Facades\DB;
|
||||
use JsonException;
|
||||
use stdClass;
|
||||
|
||||
use function Safe\json_decode;
|
||||
|
||||
class RemovesDatabaseDecryption extends Command
|
||||
{
|
||||
use ShowsFriendlyMessages;
|
||||
@@ -169,7 +171,7 @@ class RemovesDatabaseDecryption extends Command
|
||||
{
|
||||
// try to json_decrypt the value.
|
||||
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) {
|
||||
$message = sprintf('Could not JSON decode preference row #%d: %s. This does not have to be a problem.', $id, $e->getMessage());
|
||||
$this->friendlyError($message);
|
||||
|
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Console\Commands\Upgrade;
|
||||
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
|
||||
use FireflyIII\Enums\AccountTypeEnum;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
@@ -141,7 +142,7 @@ class UpgradesAccountCurrencies extends Command
|
||||
return;
|
||||
}
|
||||
// do not match and opening balance id is not null.
|
||||
if ($accountCurrency !== $obCurrency && null !== $openingBalance) {
|
||||
if ($accountCurrency !== $obCurrency && $openingBalance instanceof TransactionJournal) {
|
||||
// update opening balance:
|
||||
$openingBalance->transaction_currency_id = $accountCurrency;
|
||||
$openingBalance->save();
|
||||
|
@@ -123,7 +123,7 @@ class UpgradesBillsToRules extends Command
|
||||
$groupTitle = (string) trans('firefly.rulegroup_for_bills_title', [], $language);
|
||||
$ruleGroup = $this->ruleGroupRepository->findByTitle($groupTitle);
|
||||
|
||||
if (null === $ruleGroup) {
|
||||
if (!$ruleGroup instanceof RuleGroup) {
|
||||
$ruleGroup = $this->ruleGroupRepository->store(
|
||||
[
|
||||
'title' => (string) trans('firefly.rulegroup_for_bills_title', [], $language),
|
||||
|
@@ -27,8 +27,10 @@ namespace FireflyIII\Console\Commands\Upgrade;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Safe\Exceptions\InfoException;
|
||||
|
||||
use function Safe\set_time_limit;
|
||||
|
||||
try {
|
||||
\Safe\set_time_limit(0);
|
||||
set_time_limit(0);
|
||||
} catch (InfoException) {
|
||||
Log::warning('set_time_limit returned false. This could be an issue, unless you also run XDebug.');
|
||||
}
|
||||
|
@@ -122,7 +122,7 @@ class UpgradesLiabilities extends Command
|
||||
{
|
||||
$source = $this->getSourceTransaction($openingBalance);
|
||||
$destination = $this->getDestinationTransaction($openingBalance);
|
||||
if (null === $source || null === $destination) {
|
||||
if (!$source instanceof Transaction || !$destination instanceof Transaction) {
|
||||
return;
|
||||
}
|
||||
// source MUST be the liability.
|
||||
|
@@ -30,6 +30,8 @@ use FireflyIII\Models\RecurrenceMeta;
|
||||
use FireflyIII\Models\RecurrenceTransactionMeta;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
use function Safe\json_encode;
|
||||
|
||||
class UpgradesRecurrenceMetaData extends Command
|
||||
{
|
||||
use ShowsFriendlyMessages;
|
||||
@@ -100,7 +102,7 @@ class UpgradesRecurrenceMetaData extends Command
|
||||
|
||||
if ('tags' === $meta->name) {
|
||||
$array = explode(',', $meta->value);
|
||||
$value = \Safe\json_encode($array, JSON_THROW_ON_ERROR);
|
||||
$value = json_encode($array, JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
RecurrenceTransactionMeta::create(
|
||||
|
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Console\Commands\Upgrade;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Console\Commands\ShowsFriendlyMessages;
|
||||
use FireflyIII\Factory\TransactionGroupFactory;
|
||||
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));
|
||||
$opposingTr = $this->findOpposingTransaction($journal, $transaction);
|
||||
|
||||
if (null === $opposingTr) {
|
||||
if (!$opposingTr instanceof Transaction) {
|
||||
$this->friendlyError(
|
||||
sprintf(
|
||||
'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(
|
||||
[
|
||||
'created_at' => date('Y-m-d H:i:s'),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
|
||||
'updated_at' => Carbon::now()->format('Y-m-d H:i:s'),
|
||||
'title' => null,
|
||||
'user_id' => $array['user_id'],
|
||||
]
|
||||
|
@@ -202,7 +202,7 @@ class UpgradesTransferCurrencies extends Command
|
||||
{
|
||||
$this->sourceTransaction = $this->getSourceTransaction($journal);
|
||||
$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
|
||||
@@ -221,7 +221,7 @@ class UpgradesTransferCurrencies extends Command
|
||||
return $this->accountCurrencies[$accountId];
|
||||
}
|
||||
$currency = $this->accountRepos->getAccountCurrency($account);
|
||||
if (null === $currency) {
|
||||
if (!$currency instanceof TransactionCurrency) {
|
||||
$this->accountCurrencies[$accountId] = 0;
|
||||
|
||||
return null;
|
||||
@@ -238,7 +238,7 @@ class UpgradesTransferCurrencies extends Command
|
||||
{
|
||||
$this->destinationTransaction = $this->getDestinationTransaction($journal);
|
||||
$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
|
||||
@@ -252,15 +252,15 @@ class UpgradesTransferCurrencies extends Command
|
||||
*/
|
||||
private function isEmptyTransactions(): bool
|
||||
{
|
||||
return null === $this->sourceTransaction || null === $this->destinationTransaction
|
||||
|| null === $this->sourceAccount
|
||||
|| null === $this->destinationAccount;
|
||||
return !$this->sourceTransaction instanceof Transaction || !$this->destinationTransaction instanceof Transaction
|
||||
|| !$this->sourceAccount instanceof Account
|
||||
|| !$this->destinationAccount instanceof Account;
|
||||
}
|
||||
|
||||
private function isNoCurrencyPresent(): bool
|
||||
{
|
||||
// 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);
|
||||
app('log')->error($message);
|
||||
$this->friendlyError($message);
|
||||
@@ -269,7 +269,7 @@ class UpgradesTransferCurrencies extends Command
|
||||
}
|
||||
|
||||
// destination account must have a currency preference.
|
||||
if (null === $this->destinationCurrency) {
|
||||
if (!$this->destinationCurrency instanceof TransactionCurrency) {
|
||||
$message = sprintf(
|
||||
'Account #%d ("%s") must have currency preference but has none.',
|
||||
$this->destinationAccount->id,
|
||||
@@ -290,7 +290,7 @@ class UpgradesTransferCurrencies extends Command
|
||||
*/
|
||||
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
|
||||
->transaction_currency_id
|
||||
= $this->sourceCurrency->id
|
||||
@@ -312,7 +312,7 @@ class UpgradesTransferCurrencies extends Command
|
||||
*/
|
||||
private function fixSourceUnmatchedCurrency(): void
|
||||
{
|
||||
if (null !== $this->sourceCurrency
|
||||
if ($this->sourceCurrency instanceof TransactionCurrency
|
||||
&& null === $this->sourceTransaction->foreign_amount
|
||||
&& (int) $this->sourceTransaction->transaction_currency_id !== $this->sourceCurrency->id
|
||||
) {
|
||||
@@ -336,7 +336,7 @@ class UpgradesTransferCurrencies extends Command
|
||||
*/
|
||||
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
|
||||
->transaction_currency_id
|
||||
= $this->destinationCurrency->id
|
||||
@@ -358,7 +358,7 @@ class UpgradesTransferCurrencies extends Command
|
||||
*/
|
||||
private function fixDestinationUnmatchedCurrency(): void
|
||||
{
|
||||
if (null !== $this->destinationCurrency
|
||||
if ($this->destinationCurrency instanceof TransactionCurrency
|
||||
&& null === $this->destinationTransaction->foreign_amount
|
||||
&& (int) $this->destinationTransaction->transaction_currency_id !== $this->destinationCurrency->id
|
||||
) {
|
||||
|
@@ -120,7 +120,7 @@ class UpgradesVariousCurrencyInformation extends Command
|
||||
|
||||
$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));
|
||||
|
||||
return;
|
||||
@@ -129,7 +129,7 @@ class UpgradesVariousCurrencyInformation extends Command
|
||||
$account = $leadTransaction->account;
|
||||
$currency = $this->getCurrency($account);
|
||||
$isMultiCurrency = $this->isMultiCurrency($account);
|
||||
if (null === $currency) {
|
||||
if (!$currency instanceof TransactionCurrency) {
|
||||
$this->friendlyError(
|
||||
sprintf(
|
||||
'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];
|
||||
}
|
||||
$currency = $this->accountRepos->getAccountCurrency($account);
|
||||
if (null === $currency) {
|
||||
if (!$currency instanceof TransactionCurrency) {
|
||||
$this->accountCurrencies[$accountId] = 0;
|
||||
|
||||
return null;
|
||||
|
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Exceptions;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Brick\Math\Exception\NumberFormatException;
|
||||
use FireflyIII\Jobs\MailError;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
@@ -48,6 +49,9 @@ use ErrorException;
|
||||
use Override;
|
||||
use Throwable;
|
||||
|
||||
use function Safe\json_encode;
|
||||
use function Safe\parse_url;
|
||||
|
||||
// temp
|
||||
/**
|
||||
* Class Handler
|
||||
@@ -231,7 +235,7 @@ class Handler extends ExceptionHandler
|
||||
$data = [
|
||||
'class' => $e::class,
|
||||
'errorMessage' => $e->getMessage(),
|
||||
'time' => date('r'),
|
||||
'time' => Carbon::now()->format('r'),
|
||||
'stackTrace' => $e->getTraceAsString(),
|
||||
'file' => $e->getFile(),
|
||||
'line' => $e->getLine(),
|
||||
@@ -242,7 +246,7 @@ class Handler extends ExceptionHandler
|
||||
'json' => request()->acceptsJson(),
|
||||
'method' => request()->method(),
|
||||
'headers' => $headers,
|
||||
'post' => 'POST' === request()->method() ? \Safe\json_encode(request()->all()) : '',
|
||||
'post' => 'POST' === request()->method() ? json_encode(request()->all()) : '',
|
||||
];
|
||||
|
||||
// create job that will mail.
|
||||
@@ -289,8 +293,8 @@ class Handler extends ExceptionHandler
|
||||
}
|
||||
$safe = route('index');
|
||||
$previous = $exception->redirectTo;
|
||||
$previousHost = \Safe\parse_url($previous, PHP_URL_HOST);
|
||||
$safeHost = \Safe\parse_url($safe, PHP_URL_HOST);
|
||||
$previousHost = parse_url($previous, PHP_URL_HOST);
|
||||
$safeHost = parse_url($safe, PHP_URL_HOST);
|
||||
|
||||
return null !== $previousHost && $previousHost === $safeHost ? $previous : $safe;
|
||||
}
|
||||
|
@@ -75,7 +75,7 @@ class AccountFactory
|
||||
app('log')->debug(sprintf('findOrCreate("%s", "%s")', $accountName, $accountType));
|
||||
|
||||
$type = $this->accountRepository->getAccountTypeByType($accountType);
|
||||
if (null === $type) {
|
||||
if (!$type instanceof 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();
|
||||
@@ -111,7 +111,7 @@ class AccountFactory
|
||||
// account may exist already:
|
||||
$return = $this->find($data['name'], $type->type);
|
||||
|
||||
if (null !== $return) {
|
||||
if ($return instanceof Account) {
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Factory;
|
||||
|
||||
use FireflyIII\Models\ObjectGroup;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups;
|
||||
@@ -93,7 +94,7 @@ class BillFactory
|
||||
$objectGroupTitle = $data['object_group_title'] ?? '';
|
||||
if ('' !== $objectGroupTitle) {
|
||||
$objectGroup = $this->findOrCreateObjectGroup($objectGroupTitle);
|
||||
if (null !== $objectGroup) {
|
||||
if ($objectGroup instanceof ObjectGroup) {
|
||||
$bill->objectGroups()->sync([$objectGroup->id]);
|
||||
$bill->save();
|
||||
}
|
||||
@@ -102,7 +103,7 @@ class BillFactory
|
||||
$objectGroupId = (int) ($data['object_group_id'] ?? 0);
|
||||
if (0 !== $objectGroupId) {
|
||||
$objectGroup = $this->findObjectGroupById($objectGroupId);
|
||||
if (null !== $objectGroup) {
|
||||
if ($objectGroup instanceof ObjectGroup) {
|
||||
$bill->objectGroups()->sync([$objectGroup->id]);
|
||||
$bill->save();
|
||||
}
|
||||
@@ -124,7 +125,7 @@ class BillFactory
|
||||
|
||||
// then find by name:
|
||||
if (null === $bill && '' !== $billName) {
|
||||
$bill = $this->findByName($billName);
|
||||
return $this->findByName($billName);
|
||||
}
|
||||
|
||||
return $bill;
|
||||
|
@@ -53,7 +53,7 @@ class BudgetFactory
|
||||
|
||||
if ('' !== $budgetName) {
|
||||
$budget = $this->findByName($budgetName);
|
||||
if (null !== $budget) {
|
||||
if ($budget instanceof Budget) {
|
||||
return $budget;
|
||||
}
|
||||
}
|
||||
|
@@ -59,7 +59,7 @@ class CategoryFactory
|
||||
|
||||
if ('' !== $categoryName) {
|
||||
$category = $this->findByName($categoryName);
|
||||
if (null !== $category) {
|
||||
if ($category instanceof Category) {
|
||||
return $category;
|
||||
}
|
||||
|
||||
|
@@ -37,7 +37,7 @@ class PiggyBankEventFactory
|
||||
public function create(TransactionJournal $journal, ?PiggyBank $piggyBank): void
|
||||
{
|
||||
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');
|
||||
|
||||
return;
|
||||
|
@@ -23,6 +23,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Factory;
|
||||
|
||||
use FireflyIII\Models\ObjectGroup;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Events\Model\PiggyBank\ChangedAmount;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
@@ -35,6 +37,8 @@ use FireflyIII\User;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use function Safe\json_encode;
|
||||
|
||||
/**
|
||||
* Class PiggyBankFactory
|
||||
*/
|
||||
@@ -99,7 +103,7 @@ class PiggyBankFactory
|
||||
$objectGroupTitle = $data['object_group_title'] ?? '';
|
||||
if ('' !== $objectGroupTitle) {
|
||||
$objectGroup = $this->findOrCreateObjectGroup($objectGroupTitle);
|
||||
if (null !== $objectGroup) {
|
||||
if ($objectGroup instanceof ObjectGroup) {
|
||||
$piggyBank->objectGroups()->sync([$objectGroup->id]);
|
||||
}
|
||||
}
|
||||
@@ -107,7 +111,7 @@ class PiggyBankFactory
|
||||
$objectGroupId = (int) ($data['object_group_id'] ?? 0);
|
||||
if (0 !== $objectGroupId) {
|
||||
$objectGroup = $this->findObjectGroupById($objectGroupId);
|
||||
if (null !== $objectGroup) {
|
||||
if ($objectGroup instanceof ObjectGroup) {
|
||||
$piggyBank->objectGroups()->sync([$objectGroup->id]);
|
||||
}
|
||||
}
|
||||
@@ -241,7 +245,7 @@ class PiggyBankFactory
|
||||
/** @var array $info */
|
||||
foreach ($accounts as $info) {
|
||||
$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)));
|
||||
|
||||
continue;
|
||||
@@ -284,7 +288,7 @@ class PiggyBankFactory
|
||||
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)) {
|
||||
$piggyBank->accounts()->sync($toBeLinked);
|
||||
}
|
||||
|
@@ -59,7 +59,7 @@ class TagFactory
|
||||
'zoom_level' => null,
|
||||
]
|
||||
);
|
||||
if (null === $newTag) {
|
||||
if (!$newTag instanceof Tag) {
|
||||
app('log')->error(sprintf('TagFactory::findOrCreate("%s") but tag is unexpectedly NULL!', $tag));
|
||||
|
||||
return null;
|
||||
|
@@ -118,7 +118,7 @@ class TransactionFactory
|
||||
);
|
||||
|
||||
// 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
|
||||
&& $this->foreignCurrency->id !== $this->currency->id) {
|
||||
$result->foreign_currency_id = $this->foreignCurrency->id;
|
||||
|
@@ -24,6 +24,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Factory;
|
||||
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Enums\AccountTypeEnum;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
@@ -54,6 +56,8 @@ use Illuminate\Support\Facades\Log;
|
||||
use Exception;
|
||||
use JsonException;
|
||||
|
||||
use function Safe\json_encode;
|
||||
|
||||
/**
|
||||
* Class TransactionJournalFactory
|
||||
*
|
||||
@@ -122,10 +126,10 @@ class TransactionJournalFactory
|
||||
foreach ($transactions as $index => $row) {
|
||||
Log::debug(sprintf('Now creating journal %d/%d', $index + 1, count($transactions)));
|
||||
$journal = $this->createJournal(new NullArrayObject($row));
|
||||
if (null !== $journal) {
|
||||
if ($journal instanceof TransactionJournal) {
|
||||
$collection->push($journal);
|
||||
}
|
||||
if (null === $journal) {
|
||||
if (!$journal instanceof TransactionJournal) {
|
||||
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']);
|
||||
$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'];
|
||||
|
||||
// Manipulate basic fields
|
||||
@@ -286,7 +290,7 @@ class TransactionJournalFactory
|
||||
// see the currency they expect to see.
|
||||
$amount = (string) $row['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))
|
||||
) {
|
||||
$transactionFactory->setCurrency($foreignCurrency);
|
||||
@@ -325,7 +329,7 @@ class TransactionJournalFactory
|
||||
unset($dataRow['import_hash_v2'], $dataRow['original_source']);
|
||||
|
||||
try {
|
||||
$json = \Safe\json_encode($dataRow, JSON_THROW_ON_ERROR);
|
||||
$json = json_encode($dataRow, JSON_THROW_ON_ERROR);
|
||||
} catch (JsonException $e) {
|
||||
Log::error(sprintf('Could not encode dataRow: %s', $e->getMessage()));
|
||||
$json = microtime();
|
||||
@@ -354,7 +358,7 @@ class TransactionJournalFactory
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'journal_meta.transaction_journal_id')
|
||||
->whereNotNull('transaction_journals.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'])
|
||||
->first(['journal_meta.*'])
|
||||
;
|
||||
@@ -427,12 +431,12 @@ class TransactionJournalFactory
|
||||
private function reconciliationSanityCheck(?Account $sourceAccount, ?Account $destinationAccount): array
|
||||
{
|
||||
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.');
|
||||
|
||||
return [$sourceAccount, $destinationAccount];
|
||||
}
|
||||
if (null === $destinationAccount) {
|
||||
if (!$destinationAccount instanceof Account) {
|
||||
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));
|
||||
@@ -440,7 +444,7 @@ class TransactionJournalFactory
|
||||
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.');
|
||||
$account = $this->accountRepository->getReconciliation($destinationAccount);
|
||||
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 */
|
||||
$preference = $this->accountRepository->getAccountCurrency($account);
|
||||
if (null === $preference && null === $currency) {
|
||||
if (null === $preference && !$currency instanceof TransactionCurrency) {
|
||||
// return user's default:
|
||||
return app('amount')->getNativeCurrencyByUserGroup($this->user->userGroup);
|
||||
}
|
||||
@@ -498,10 +502,10 @@ class TransactionJournalFactory
|
||||
private function compareCurrencies(?TransactionCurrency $currency, ?TransactionCurrency $foreignCurrency): ?TransactionCurrency
|
||||
{
|
||||
Log::debug(sprintf('Now in compareCurrencies("%s", "%s")', $currency?->code, $foreignCurrency?->code));
|
||||
if (null === $currency) {
|
||||
if (!$currency instanceof TransactionCurrency) {
|
||||
return null;
|
||||
}
|
||||
if (null !== $foreignCurrency && $foreignCurrency->id === $currency->id) {
|
||||
if ($foreignCurrency instanceof TransactionCurrency && $foreignCurrency->id === $currency->id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -558,7 +562,7 @@ class TransactionJournalFactory
|
||||
|
||||
$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);
|
||||
Log::debug('Create piggy event.');
|
||||
|
||||
|
Reference in New Issue
Block a user