Fix various code.

This commit is contained in:
James Cole
2025-05-27 17:06:15 +02:00
parent d8f512ca3a
commit 2cb14f6b72
123 changed files with 581 additions and 500 deletions

View File

@@ -115,7 +115,7 @@ class Amount
public function convertToNative(?User $user = null): bool
{
if (null === $user) {
if (!$user instanceof User) {
return true === Preferences::get('convert_to_native', false)->data && true === config('cer.enabled');
// Log::debug(sprintf('convertToNative [a]: %s', var_export($result, true)));
}
@@ -286,7 +286,7 @@ class Amount
public static function getAmountJsConfig(bool $sepBySpace, int $signPosn, string $sign, bool $csPrecedes): string
{
// negative first:
$space = ' ';
$space = ' ';
// require space between symbol and amount?
if (false === $sepBySpace) {
@@ -295,11 +295,11 @@ class Amount
// there are five possible positions for the "+" or "-" sign (if it is even used)
// pos_a and pos_e could be the ( and ) symbol.
$posA = ''; // before everything
$posB = ''; // before currency symbol
$posC = ''; // after currency symbol
$posD = ''; // before amount
$posE = ''; // after everything
$posA = ''; // before everything
$posB = ''; // before currency symbol
$posC = ''; // after currency symbol
$posD = ''; // before amount
$posE = ''; // after everything
// format would be (currency before amount)
// AB%sC_D%vE
@@ -340,14 +340,10 @@ class Amount
$posC = $sign;
}
// default is amount before currency
$format = $posA.$posD.'%v'.$space.$posB.'%s'.$posC.$posE;
if ($csPrecedes) {
// alternative is currency before amount
$format = $posA.$posB.'%s'.$posC.$space.$posD.'%v'.$posE;
return $posA.$posB.'%s'.$posC.$space.$posD.'%v'.$posE;
}
return $format;
return $posA.$posD.'%v'.$space.$posB.'%s'.$posC.$posE;
}
}

View File

@@ -56,7 +56,7 @@ class RemoteUserGuard implements Guard
public function authenticate(): void
{
Log::debug(sprintf('Now at %s', __METHOD__));
if (null !== $this->user) {
if ($this->user instanceof User) {
Log::debug(sprintf('%s is found: #%d, "%s".', $this->user::class, $this->user->id, $this->user->email));
return;
@@ -112,14 +112,14 @@ class RemoteUserGuard implements Guard
{
Log::debug(sprintf('Now at %s', __METHOD__));
return null !== $this->user();
return $this->user() instanceof User;
}
public function user(): ?User
{
Log::debug(sprintf('Now at %s', __METHOD__));
$user = $this->user;
if (null === $user) {
if (!$user instanceof User) {
Log::debug('User is NULL');
return null;

View File

@@ -23,10 +23,13 @@ declare(strict_types=1);
namespace FireflyIII\Support;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
use JsonException;
use function Safe\json_encode;
/**
* Class CacheProperties.
*/
@@ -80,10 +83,10 @@ class CacheProperties
$content = '';
foreach ($this->properties as $property) {
try {
$content = sprintf('%s%s', $content, \Safe\json_encode($property, JSON_THROW_ON_ERROR));
$content = sprintf('%s%s', $content, json_encode($property, JSON_THROW_ON_ERROR));
} catch (JsonException) {
// @ignoreException
$content = sprintf('%s%s', $content, hash('sha256', (string) time()));
$content = sprintf('%s%s', $content, hash('sha256', (string) Carbon::now()->getTimestamp()));
}
}
$this->hash = substr(hash('sha256', $content), 0, 16);

View File

@@ -65,7 +65,7 @@ class Calculator
private static function loadIntervalMap(): SplObjectStorage
{
if (null !== self::$intervalMap) {
if (self::$intervalMap instanceof SplObjectStorage) {
return self::$intervalMap;
}
self::$intervalMap = new SplObjectStorage();

View File

@@ -124,7 +124,7 @@ class WholePeriodChartGenerator
$step = '1M';
}
if ($months > 100) {
$step = '1Y';
return '1Y';
}
return $step;

View File

@@ -38,7 +38,7 @@ class AutoBudgetCronjob extends AbstractCronjob
/** @var Configuration $config */
$config = app('fireflyconfig')->get('last_ab_job', 0);
$lastTime = (int) $config->data;
$diff = time() - $lastTime;
$diff = Carbon::now()->getTimestamp() - $lastTime;
$diffForHumans = today(config('app.timezone'))->diffForHumans(Carbon::createFromTimestamp($lastTime), null, true);
if (0 === $lastTime) {
app('log')->info('Auto budget cron-job has never fired before.');

View File

@@ -44,7 +44,7 @@ class BillWarningCronjob extends AbstractCronjob
/** @var Configuration $config */
$config = app('fireflyconfig')->get('last_bw_job', 0);
$lastTime = (int) $config->data;
$diff = time() - $lastTime;
$diff = Carbon::now()->getTimestamp() - $lastTime;
$diffForHumans = today(config('app.timezone'))->diffForHumans(Carbon::createFromTimestamp($lastTime), null, true);
if (0 === $lastTime) {

View File

@@ -39,7 +39,7 @@ class ExchangeRatesCronjob extends AbstractCronjob
/** @var Configuration $config */
$config = app('fireflyconfig')->get('last_cer_job', 0);
$lastTime = (int) $config->data;
$diff = time() - $lastTime;
$diff = Carbon::now()->getTimestamp() - $lastTime;
$diffForHumans = today(config('app.timezone'))->diffForHumans(Carbon::createFromTimestamp($lastTime), null, true);
if (0 === $lastTime) {
Log::info('Exchange rates cron-job has never fired before.');

View File

@@ -44,7 +44,7 @@ class RecurringCronjob extends AbstractCronjob
/** @var Configuration $config */
$config = app('fireflyconfig')->get('last_rt_job', 0);
$lastTime = (int) $config->data;
$diff = time() - $lastTime;
$diff = Carbon::now()->getTimestamp() - $lastTime;
$diffForHumans = today(config('app.timezone'))->diffForHumans(Carbon::createFromTimestamp($lastTime), null, true);
if (0 === $lastTime) {

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Cronjobs;
use Carbon\Carbon;
use FireflyIII\Helpers\Update\UpdateTrait;
use FireflyIII\Models\Configuration;
use FireflyIII\Support\Facades\FireflyConfig;
@@ -55,8 +56,8 @@ class UpdateCheckCronjob extends AbstractCronjob
// TODO this is duplicate.
/** @var Configuration $lastCheckTime */
$lastCheckTime = FireflyConfig::get('last_update_check', time());
$now = time();
$lastCheckTime = FireflyConfig::get('last_update_check', Carbon::now()->getTimestamp());
$now = Carbon::now()->getTimestamp();
$diff = $now - $lastCheckTime->data;
Log::debug(sprintf('Last check time is %d, current time is %d, difference is %d', $lastCheckTime->data, $now, $diff));
if ($diff < 604800 && false === $this->force) {
@@ -64,7 +65,7 @@ class UpdateCheckCronjob extends AbstractCronjob
$this->jobFired = false;
$this->jobErrored = false;
$this->jobSucceeded = true;
$this->message = sprintf('Checked for updates less than a week ago (on %s).', date('Y-m-d H:i:s', $lastCheckTime->data));
$this->message = sprintf('Checked for updates less than a week ago (on %s).', Carbon::createFromTimestamp($lastCheckTime->data)->format('Y-m-d H:i:s'));
return;
}

View File

@@ -54,7 +54,7 @@ class FireflyConfig
public function getEncrypted(string $name, mixed $default = null): ?Configuration
{
$result = $this->get($name, $default);
if (null === $result) {
if (!$result instanceof Configuration) {
return null;
}
if ('' === $result->data) {

View File

@@ -59,7 +59,7 @@ class AccountForm
private function getAccountsGrouped(array $types, ?AccountRepositoryInterface $repository = null): array
{
if (null === $repository) {
if (!$repository instanceof AccountRepositoryInterface) {
$repository = $this->getAccountRepository();
}
$accountList = $repository->getActiveAccountsByType($types);

View File

@@ -85,14 +85,13 @@ trait FormSupport
{
// Get errors from session:
/** @var null|MessageBag $errors */
$errors = session('errors');
$classes = 'form-group';
$errors = session('errors');
if (null !== $errors && $errors->has($name)) {
$classes = 'form-group has-error has-feedback';
return 'form-group has-error has-feedback';
}
return $classes;
return 'form-group';
}
/**
@@ -112,7 +111,7 @@ trait FormSupport
}
if ($value instanceof Carbon) {
$value = $value->format('Y-m-d');
return $value->format('Y-m-d');
}
return $value;

View File

@@ -215,7 +215,6 @@ class AccountBalanceGrouped
private function getDataKey(array $journal): string
{
$key = 'spent';
// deposit = incoming
// transfer or reconcile or opening balance, and these accounts are the destination.
if (
@@ -230,10 +229,10 @@ class AccountBalanceGrouped
&& in_array($journal['destination_account_id'], $this->accountIds, true)
)
) {
$key = 'earned';
return 'earned';
}
return $key;
return 'spent';
}
private function getRate(TransactionCurrency $currency, Carbon $date): string

View File

@@ -33,6 +33,8 @@ use Illuminate\Support\Facades\Log;
use Laravel\Passport\Passport;
use phpseclib3\Crypt\RSA;
use function Safe\file_put_contents;
/**
* Trait CreateStuff
*/
@@ -106,8 +108,8 @@ trait CreateStuff
Log::alert('NO OAuth keys were found. They have been created.');
\Safe\file_put_contents($publicKey, (string) $key->getPublicKey());
\Safe\file_put_contents($privateKey, $key->toString('PKCS1'));
file_put_contents($publicKey, (string) $key->getPublicKey());
file_put_contents($privateKey, $key->toString('PKCS1'));
}
/**

View File

@@ -77,7 +77,7 @@ trait DateCalculation
$step = '1M';
}
if ($months > 100) {
$step = '1Y';
return '1Y';
}
return $step;

View File

@@ -207,7 +207,7 @@ trait GetConfigurationData
{
$config = app('fireflyconfig')->get('last_rt_job', 0);
$lastTime = (int) $config?->data;
$now = time();
$now = Carbon::now()->getTimestamp();
app('log')->debug(sprintf('verifyRecurringCronJob: last time is %d ("%s"), now is %d', $lastTime, $config?->data, $now));
if (0 === $lastTime) {
request()->session()->flash('info', trans('firefly.recurring_never_cron'));

View File

@@ -36,6 +36,8 @@ use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Route as RouteFacade;
use Hash;
use function Safe\parse_url;
/**
* Trait RequestInformation
*/
@@ -47,7 +49,7 @@ trait RequestInformation
final protected function getDomain(): string // get request info
{
$url = url()->to('/');
$parts = \Safe\parse_url($url);
$parts = parse_url($url);
return $parts['host'] ?? '';
}
@@ -95,7 +97,7 @@ trait RequestInformation
$shownDemo = app('preferences')->get($key, false)->data;
}
if (!is_bool($shownDemo)) {
$shownDemo = true;
return true;
}
return $shownDemo;
@@ -123,20 +125,19 @@ trait RequestInformation
final protected function notInSessionRange(Carbon $date): bool // Validate a preference
{
/** @var Carbon $start */
$start = session('start', today(config('app.timezone'))->startOfMonth());
$start = session('start', today(config('app.timezone'))->startOfMonth());
/** @var Carbon $end */
$end = session('end', today(config('app.timezone'))->endOfMonth());
$result = false;
$end = session('end', today(config('app.timezone'))->endOfMonth());
if ($start->greaterThanOrEqualTo($date) && $end->greaterThanOrEqualTo($date)) {
$result = true;
return true;
}
// start and end in the past? use $end
if ($start->lessThanOrEqualTo($date) && $end->lessThanOrEqualTo($date)) {
$result = true;
return true;
}
return $result;
return false;
}
/**
@@ -147,14 +148,14 @@ trait RequestInformation
$attributes['location'] ??= '';
$attributes['accounts'] = AccountList::routeBinder($attributes['accounts'] ?? '', new Route('get', '', []));
$date = Carbon::createFromFormat('Ymd', $attributes['startDate']);
if (null === $date) {
if (!$date instanceof Carbon) {
$date = today(config('app.timezone'));
}
$date->startOfMonth();
$attributes['startDate'] = $date;
$date2 = Carbon::createFromFormat('Ymd', $attributes['endDate']);
if (null === $date2) {
if (!$date2 instanceof Carbon) {
$date2 = today(config('app.timezone'));
}
$date2->endOfDay();

View File

@@ -83,7 +83,7 @@ class AccountBalanceCalculator
if ($accounts->count() > 0) {
$query->whereIn('transactions.account_id', $accounts->pluck('id')->toArray());
}
if (null !== $notBefore) {
if ($notBefore instanceof Carbon) {
$notBefore->startOfDay();
$query->where('transaction_journals.date', '>=', $notBefore);
}
@@ -124,7 +124,7 @@ class AccountBalanceCalculator
private function getLatestBalance(int $accountId, int $currencyId, ?Carbon $notBefore): string
{
if (null === $notBefore) {
if (!$notBefore instanceof Carbon) {
return '0';
}
Log::debug(sprintf('getLatestBalance: notBefore date is "%s", calculating', $notBefore->format('Y-m-d')));

View File

@@ -83,7 +83,7 @@ class BillDateCalculator
// AND date is after last paid date
if (
$nextExpectedMatch->gte($earliest) // date is after "earliest possible date"
&& (null === $lastPaid || $nextExpectedMatch->gt($lastPaid)) // date is after last paid date, if that date is not NULL
&& (!$lastPaid instanceof Carbon || $nextExpectedMatch->gt($lastPaid)) // date is after last paid date, if that date is not NULL
) {
Log::debug('Add date to set, because it is after earliest possible date and after last paid date.');
$set->push(clone $nextExpectedMatch);

View File

@@ -421,7 +421,7 @@ class Navigation
$currentEnd->{$function}(); // @phpstan-ignore-line
}
if (null !== $maxDate && $currentEnd > $maxDate) {
if ($maxDate instanceof Carbon && $currentEnd > $maxDate) {
return clone $maxDate;
}
@@ -502,7 +502,7 @@ class Navigation
if ($diff >= 12.001) {
// Log::debug(sprintf('Return Y because %s', $diff));
$format = 'Y';
return 'Y';
}
return $format;
@@ -565,16 +565,15 @@ class Navigation
public function preferredCarbonLocalizedFormat(Carbon $start, Carbon $end): string
{
$locale = app('steam')->getLocale();
$format = (string) trans('config.month_and_day_js', [], $locale);
if ($start->diffInMonths($end, true) > 1) {
$format = (string) trans('config.month_js', [], $locale);
return (string) trans('config.month_js', [], $locale);
}
if ($start->diffInMonths($end, true) > 12) {
$format = (string) trans('config.year_js', [], $locale);
return (string) trans('config.year_js', [], $locale);
}
return $format;
return (string) trans('config.month_and_day_js', [], $locale);
}
/**
@@ -583,16 +582,15 @@ class Navigation
*/
public function preferredEndOfPeriod(Carbon $start, Carbon $end): string
{
$format = 'endOfDay';
if ((int) $start->diffInMonths($end, true) > 1) {
$format = 'endOfMonth';
return 'endOfMonth';
}
if ((int) $start->diffInMonths($end, true) > 12) {
$format = 'endOfYear';
return 'endOfYear';
}
return $format;
return 'endOfDay';
}
/**
@@ -601,16 +599,15 @@ class Navigation
*/
public function preferredRangeFormat(Carbon $start, Carbon $end): string
{
$format = '1D';
if ((int) $start->diffInMonths($end, true) > 1) {
$format = '1M';
return '1M';
}
if ((int) $start->diffInMonths($end, true) > 12) {
$format = '1Y';
return '1Y';
}
return $format;
return '1D';
}
/**
@@ -619,16 +616,15 @@ class Navigation
*/
public function preferredSqlFormat(Carbon $start, Carbon $end): string
{
$format = '%Y-%m-%d';
if ((int) $start->diffInMonths($end, true) > 1) {
$format = '%Y-%m';
return '%Y-%m';
}
if ((int) $start->diffInMonths($end, true) > 12) {
$format = '%Y';
return '%Y';
}
return $format;
return '%Y-%m-%d';
}
/**

View File

@@ -30,6 +30,8 @@ use Carbon\Exceptions\InvalidFormatException;
use FireflyIII\Exceptions\FireflyException;
use Illuminate\Support\Facades\Log;
use function Safe\preg_match;
/**
* Class ParseDateString
*/
@@ -85,7 +87,7 @@ class ParseDateString
// if regex for YYYY-MM-DD:
$pattern = '/^(19|20)\d\d-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])$/';
$result = \Safe\preg_match($pattern, $date);
$result = preg_match($pattern, $date);
if (false !== $result && 0 !== $result) {
return $this->parseDefaultDate($date);
}
@@ -148,7 +150,7 @@ class ParseDateString
Log::error(sprintf('parseDefaultDate("%s") ran into an error, but dont mind: %s', $date, $e->getMessage()));
}
if (false === $result) {
$result = today(config('app.timezone'))->startOfDay();
return today(config('app.timezone'))->startOfDay();
}
return $result;
@@ -182,7 +184,7 @@ class ParseDateString
// verify if correct
$pattern = '/[+-]\d+[wqmdy]/';
$result = \Safe\preg_match($pattern, $part);
$result = preg_match($pattern, $part);
if (0 === $result || false === $result) {
app('log')->error(sprintf('Part "%s" does not match regular expression. Will be skipped.', $part));
@@ -256,7 +258,7 @@ class ParseDateString
protected function isDayRange(string $date): bool
{
$pattern = '/^xxxx-xx-(0[1-9]|[12]\d|3[01])$/';
$result = \Safe\preg_match($pattern, $date);
$result = preg_match($pattern, $date);
if (false !== $result && 0 !== $result) {
app('log')->debug(sprintf('"%s" is a day range.', $date));
@@ -283,7 +285,7 @@ class ParseDateString
{
// if regex for xxxx-MM-xx:
$pattern = '/^xxxx-(0[1-9]|1[012])-xx$/';
$result = \Safe\preg_match($pattern, $date);
$result = preg_match($pattern, $date);
if (false !== $result && 0 !== $result) {
app('log')->debug(sprintf('"%s" is a month range.', $date));
@@ -311,7 +313,7 @@ class ParseDateString
{
// if regex for YYYY-xx-xx:
$pattern = '/^(19|20)\d\d-xx-xx$/';
$result = \Safe\preg_match($pattern, $date);
$result = preg_match($pattern, $date);
if (false !== $result && 0 !== $result) {
app('log')->debug(sprintf('"%s" is a year range.', $date));
@@ -339,7 +341,7 @@ class ParseDateString
{
// if regex for xxxx-MM-DD:
$pattern = '/^xxxx-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])$/';
$result = \Safe\preg_match($pattern, $date);
$result = preg_match($pattern, $date);
if (false !== $result && 0 !== $result) {
app('log')->debug(sprintf('"%s" is a month/day range.', $date));
@@ -368,7 +370,7 @@ class ParseDateString
{
// if regex for YYYY-xx-DD:
$pattern = '/^(19|20)\d\d-xx-(0[1-9]|[12]\d|3[01])$/';
$result = \Safe\preg_match($pattern, $date);
$result = preg_match($pattern, $date);
if (false !== $result && 0 !== $result) {
app('log')->debug(sprintf('"%s" is a day/year range.', $date));
@@ -397,7 +399,7 @@ class ParseDateString
{
// if regex for YYYY-MM-xx:
$pattern = '/^(19|20)\d\d-(0[1-9]|1[012])-xx$/';
$result = \Safe\preg_match($pattern, $date);
$result = preg_match($pattern, $date);
if (false !== $result && 0 !== $result) {
app('log')->debug(sprintf('"%s" is a month/year range.', $date));

View File

@@ -110,7 +110,7 @@ class Preferences
$groupId = null;
$items = config('firefly.admin_specific_prefs') ?? [];
if (in_array($preferenceName, $items, true)) {
$groupId = (int) $user->user_group_id;
return (int) $user->user_group_id;
}
return $groupId;
@@ -215,7 +215,7 @@ class Preferences
public function getEncrypted(string $name, mixed $default = null): ?Preference
{
$result = $this->get($name, $default);
if (null === $result) {
if (!$result instanceof Preference) {
return null;
}
if ('' === $result->data) {
@@ -286,7 +286,7 @@ class Preferences
$lastActivity = microtime();
$preference = $this->get('lastActivity', microtime());
if (null !== $preference && null !== $preference->data) {
if ($preference instanceof Preference && null !== $preference->data) {
$lastActivity = $preference->data;
}
if (is_array($lastActivity)) {

View File

@@ -37,7 +37,7 @@ class TransactionSummarizer
public function __construct(?User $user = null)
{
if (null !== $user) {
if ($user instanceof User) {
$this->setUser($user);
}
}

View File

@@ -32,6 +32,8 @@ use FireflyIII\Support\Facades\Steam;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use function Safe\preg_replace;
/**
* Trait ConvertsDataTypes
*/
@@ -125,7 +127,7 @@ trait ConvertsDataTypes
$string = str_replace($this->characters, "\x20", $string);
// clear zalgo text (TODO also in API v2)
$string = \Safe\preg_replace('/(\pM{2})\pM+/u', '\1', $string);
$string = preg_replace('/(\pM{2})\pM+/u', '\1', $string);
return trim((string) $string);
}
@@ -263,7 +265,7 @@ trait ConvertsDataTypes
return null;
}
if (null === $carbon) {
if (!$carbon instanceof Carbon) {
app('log')->error(sprintf('[2] "%s" is of an invalid format.', $value));
return null;
@@ -316,7 +318,7 @@ trait ConvertsDataTypes
} catch (InvalidFormatException) {
// @ignoreException
}
if (null === $carbon) {
if (!$carbon instanceof Carbon) {
app('log')->debug(sprintf('Invalid date: %s', $string));
return null;
@@ -380,7 +382,7 @@ trait ConvertsDataTypes
// @ignoreException
Log::debug(sprintf('Exception when parsing date "%s".', $this->get($field)));
}
if (null === $result) {
if (!$result instanceof Carbon) {
app('log')->debug(sprintf('Exception when parsing date "%s".', $this->get($field)));
}

View File

@@ -29,6 +29,8 @@ use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use function Safe\json_encode;
/**
* Class AccountSearch
*/
@@ -81,7 +83,7 @@ class AccountSearch implements GenericSearchInterface
// meta data:
$searchQuery->orWhere(
static function (Builder $q) use ($originalQuery): void {
$json = \Safe\json_encode($originalQuery, JSON_THROW_ON_ERROR);
$json = json_encode($originalQuery, JSON_THROW_ON_ERROR);
$q->where('account_meta.name', '=', 'account_number');
$q->whereLike('account_meta.data', $json);
}
@@ -108,7 +110,7 @@ class AccountSearch implements GenericSearchInterface
// meta data:
$searchQuery->Where(
static function (Builder $q) use ($originalQuery): void {
$json = \Safe\json_encode($originalQuery, JSON_THROW_ON_ERROR);
$json = json_encode($originalQuery, JSON_THROW_ON_ERROR);
$q->where('account_meta.name', 'account_number');
$q->where('account_meta.data', $json);
}

View File

@@ -719,10 +719,10 @@ class OperatorQuerySearch implements SearchInterface
//
case 'currency_is':
$currency = $this->findCurrency($value);
if (null !== $currency) {
if ($currency instanceof TransactionCurrency) {
$this->collector->setCurrency($currency);
}
if (null === $currency) {
if (!$currency instanceof TransactionCurrency) {
$this->collector->findNothing();
}
@@ -730,10 +730,10 @@ class OperatorQuerySearch implements SearchInterface
case '-currency_is':
$currency = $this->findCurrency($value);
if (null !== $currency) {
if ($currency instanceof TransactionCurrency) {
$this->collector->excludeCurrency($currency);
}
if (null === $currency) {
if (!$currency instanceof TransactionCurrency) {
$this->collector->findNothing();
}
@@ -741,10 +741,10 @@ class OperatorQuerySearch implements SearchInterface
case 'foreign_currency_is':
$currency = $this->findCurrency($value);
if (null !== $currency) {
if ($currency instanceof TransactionCurrency) {
$this->collector->setForeignCurrency($currency);
}
if (null === $currency) {
if (!$currency instanceof TransactionCurrency) {
$this->collector->findNothing();
}
@@ -752,10 +752,10 @@ class OperatorQuerySearch implements SearchInterface
case '-foreign_currency_is':
$currency = $this->findCurrency($value);
if (null !== $currency) {
if ($currency instanceof TransactionCurrency) {
$this->collector->excludeForeignCurrency($currency);
}
if (null === $currency) {
if (!$currency instanceof TransactionCurrency) {
$this->collector->findNothing();
}
@@ -2109,7 +2109,7 @@ class OperatorQuerySearch implements SearchInterface
}
$result = $this->currencyRepository->findByCode($value);
if (null === $result) {
$result = $this->currencyRepository->findByName($value);
return $this->currencyRepository->findByName($value);
}
return $result;

View File

@@ -33,6 +33,8 @@ use Illuminate\Support\Facades\Log;
use LogicException;
use TypeError;
use function Safe\fwrite;
class GdbotsQueryParser implements QueryParserInterface
{
private readonly BaseQueryParser $parser;
@@ -56,7 +58,7 @@ class GdbotsQueryParser implements QueryParserInterface
return new NodeGroup($nodes);
} catch (LogicException|TypeError $e) {
\Safe\fwrite(STDERR, "Setting up GdbotsQueryParserTest\n");
fwrite(STDERR, "Setting up GdbotsQueryParserTest\n");
app('log')->error($e->getMessage());
app('log')->error(sprintf('Could not parse search: "%s".', $query));

View File

@@ -51,7 +51,7 @@ class QueryParser implements QueryParserInterface
$nodes = [];
$nodeResult = $this->buildNextNode($isSubquery);
while (null !== $nodeResult->node) {
while ($nodeResult->node instanceof Node) {
$nodes[] = $nodeResult->node;
if ($nodeResult->isSubqueryEnd) {
break;

View File

@@ -37,6 +37,9 @@ use Illuminate\Support\Str;
use Exception;
use ValueError;
use function Safe\preg_replace;
use function Safe\parse_url;
/**
* Class Steam.
*/
@@ -97,25 +100,25 @@ class Steam
unset($set[$defaultCurrency->code]);
}
// todo rethink this logic.
if (null !== $currency && $defaultCurrency->id !== $currency->id) {
if ($currency instanceof TransactionCurrency && $defaultCurrency->id !== $currency->id) {
Log::debug(sprintf('Unset balance for account #%d', $account->id));
unset($set['balance']);
}
if (null === $currency) {
if (!$currency instanceof TransactionCurrency) {
Log::debug(sprintf('Unset balance for account #%d', $account->id));
unset($set['balance']);
}
}
if (!$convertToNative) {
if (null === $currency) {
if (!$currency instanceof TransactionCurrency) {
Log::debug(sprintf('Unset native_balance and make defaultCurrency balance the balance for account #%d', $account->id));
$set['balance'] = $set[$defaultCurrency->code] ?? '0';
unset($set[$defaultCurrency->code]);
}
if (null !== $currency) {
if ($currency instanceof TransactionCurrency) {
Log::debug(sprintf('Unset [%s] + [%s] balance for account #%d', $defaultCurrency->code, $currency->code, $account->id));
unset($set[$defaultCurrency->code], $set[$currency->code]);
}
@@ -186,8 +189,8 @@ class Steam
];
// clear zalgo text
$string = \Safe\preg_replace('/(\pM{2})\pM+/u', '\1', $string);
$string = \Safe\preg_replace('/\s+/', '', $string);
$string = preg_replace('/(\pM{2})\pM+/u', '\1', $string);
$string = preg_replace('/\s+/', '', $string);
return str_replace($search, '', $string);
}
@@ -223,7 +226,7 @@ class Steam
$startBalance = $this->finalAccountBalance($account, $request);
$nativeCurrency = app('amount')->getNativeCurrencyByUserGroup($account->user->userGroup);
$accountCurrency = $this->getAccountCurrency($account);
$hasCurrency = null !== $accountCurrency;
$hasCurrency = $accountCurrency instanceof TransactionCurrency;
$currency = $accountCurrency ?? $nativeCurrency;
Log::debug(sprintf('Currency is %s', $currency->code));
@@ -341,7 +344,7 @@ class Steam
if (null === $convertToNative) {
$convertToNative = Amount::convertToNative($account->user);
}
if (null === $native) {
if (!$native instanceof TransactionCurrency) {
$native = Amount::getNativeCurrencyByUserGroup($account->user->userGroup);
}
// account balance thing.
@@ -516,7 +519,7 @@ class Steam
// Check for Windows to replace the locale correctly.
if ('WIN' === strtoupper(substr(PHP_OS, 0, 3))) {
$locale = str_replace('_', '-', $locale);
return str_replace('_', '-', $locale);
}
return $locale;
@@ -568,8 +571,8 @@ class Steam
{
// Log::debug(sprintf('getSafeUrl(%s, %s)', $unknownUrl, $safeUrl));
$returnUrl = $safeUrl;
$unknownHost = \Safe\parse_url($unknownUrl, PHP_URL_HOST);
$safeHost = \Safe\parse_url($safeUrl, PHP_URL_HOST);
$unknownHost = parse_url($unknownUrl, PHP_URL_HOST);
$safeHost = parse_url($safeUrl, PHP_URL_HOST);
if (null !== $unknownHost && $unknownHost === $safeHost) {
$returnUrl = $unknownUrl;
@@ -578,7 +581,7 @@ class Steam
// URL must not lead to weird pages
$forbiddenWords = ['jscript', 'json', 'debug', 'serviceworker', 'offline', 'delete', '/login', '/attachments/view'];
if (Str::contains($returnUrl, $forbiddenWords)) {
$returnUrl = $safeUrl;
return $safeUrl;
}
return $returnUrl;
@@ -592,7 +595,7 @@ class Steam
$amount = $this->floatalize($amount);
if (1 === bccomp($amount, '0')) {
$amount = bcmul($amount, '-1');
return bcmul($amount, '-1');
}
return $amount;

View File

@@ -32,6 +32,9 @@ use Laravel\Passport\Console\KeysCommand;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use function Safe\file_get_contents;
use function Safe\file_put_contents;
/**
* Class OAuthKeys
*/
@@ -97,8 +100,8 @@ class OAuthKeys
{
$private = storage_path('oauth-private.key');
$public = storage_path('oauth-public.key');
app('fireflyconfig')->set(self::PRIVATE_KEY, Crypt::encrypt(\Safe\file_get_contents($private)));
app('fireflyconfig')->set(self::PUBLIC_KEY, Crypt::encrypt(\Safe\file_get_contents($public)));
app('fireflyconfig')->set(self::PRIVATE_KEY, Crypt::encrypt(file_get_contents($private)));
app('fireflyconfig')->set(self::PUBLIC_KEY, Crypt::encrypt(file_get_contents($public)));
}
/**
@@ -124,8 +127,8 @@ class OAuthKeys
}
$private = storage_path('oauth-private.key');
$public = storage_path('oauth-public.key');
\Safe\file_put_contents($private, $privateContent);
\Safe\file_put_contents($public, $publicContent);
file_put_contents($private, $privateContent);
file_put_contents($public, $publicContent);
return true;
}

View File

@@ -39,6 +39,8 @@ use Twig\TwigFilter;
use Twig\TwigFunction;
use Override;
use function Safe\parse_url;
/**
* Class TwigSupport.
*/
@@ -64,7 +66,7 @@ class General extends AbstractExtension
return new TwigFilter(
'balance',
static function (?Account $account): string {
if (null === $account) {
if (!$account instanceof Account) {
return '0';
}
@@ -180,8 +182,8 @@ class General extends AbstractExtension
return new TwigFilter(
'phphost',
static function (string $string): string {
$proto = (string) \Safe\parse_url($string, PHP_URL_SCHEME);
$host = (string) \Safe\parse_url($string, PHP_URL_HOST);
$proto = (string) parse_url($string, PHP_URL_SCHEME);
$host = (string) parse_url($string, PHP_URL_HOST);
return e(sprintf('%s://%s', $proto, $host));
}

View File

@@ -35,6 +35,8 @@ use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
use Override;
use function Safe\json_decode;
/**
* Class TransactionGroupTwig
*/
@@ -91,7 +93,7 @@ class TransactionGroupTwig extends AbstractExtension
$result = app('amount')->formatFlat($array['currency_symbol'], (int) $array['currency_decimal_places'], $amount, $colored);
if (TransactionTypeEnum::TRANSFER->value === $type) {
$result = sprintf('<span class="text-info money-transfer">%s</span>', $result);
return sprintf('<span class="text-info money-transfer">%s</span>', $result);
}
return $result;
@@ -111,7 +113,7 @@ class TransactionGroupTwig extends AbstractExtension
// reconciliation and it comes from reconciliation?
if (TransactionTypeEnum::RECONCILIATION->value === $transactionType && AccountTypeEnum::RECONCILIATION->value !== $sourceType) {
$amount = bcmul($amount, '-1');
return bcmul($amount, '-1');
}
return $amount;
@@ -134,7 +136,7 @@ class TransactionGroupTwig extends AbstractExtension
}
$result = app('amount')->formatFlat($array['foreign_currency_symbol'], (int) $array['foreign_currency_decimal_places'], $amount, $colored);
if (TransactionTypeEnum::TRANSFER->value === $type) {
$result = sprintf('<span class="text-info money-transfer">%s</span>', $result);
return sprintf('<span class="text-info money-transfer">%s</span>', $result);
}
return $result;
@@ -182,7 +184,7 @@ class TransactionGroupTwig extends AbstractExtension
}
$result = app('amount')->formatFlat($currency->symbol, $currency->decimal_places, $amount, $colored);
if (TransactionTypeEnum::TRANSFER->value === $type) {
$result = sprintf('<span class="text-info money-transfer">%s</span>', $result);
return sprintf('<span class="text-info money-transfer">%s</span>', $result);
}
return $result;
@@ -217,7 +219,7 @@ class TransactionGroupTwig extends AbstractExtension
}
$result = app('amount')->formatFlat($currency->symbol, $currency->decimal_places, $amount, $colored);
if (TransactionTypeEnum::TRANSFER->value === $type) {
$result = sprintf('<span class="text-info money-transfer">%s</span>', $result);
return sprintf('<span class="text-info money-transfer">%s</span>', $result);
}
return $result;
@@ -256,7 +258,7 @@ class TransactionGroupTwig extends AbstractExtension
return today(config('app.timezone'));
}
return new Carbon(\Safe\json_decode($entry->data, false));
return new Carbon(json_decode((string) $entry->data, false));
}
);
}
@@ -277,7 +279,7 @@ class TransactionGroupTwig extends AbstractExtension
return '';
}
return \Safe\json_decode($entry->data, true);
return json_decode((string) $entry->data, true);
}
);
}