Fix code quality with rector [skip ci]

This commit is contained in:
James Cole
2025-11-09 09:08:03 +01:00
parent d2610be790
commit 68183a0a0e
209 changed files with 1021 additions and 1248 deletions

View File

@@ -174,7 +174,7 @@ class Amount
$fmt->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, $decimalPlaces);
$result = (string)$fmt->format((float)$rounded); // intentional float
if (true === $coloured) {
if ($coloured) {
if (1 === bccomp($rounded, '0')) {
return sprintf('<span class="text-success money-positive">%s</span>', $result);
}
@@ -355,7 +355,7 @@ class Amount
private function getLocaleField(array $info, string $field): bool
{
return (is_bool($info[$field]) && true === $info[$field])
return (is_bool($info[$field]) && $info[$field])
|| (is_int($info[$field]) && 1 === $info[$field]);
}

View File

@@ -40,18 +40,16 @@ use Illuminate\Support\Facades\Log;
class RemoteUserGuard implements Guard
{
protected Application $application;
protected ?User $user;
protected ?User $user = null;
/**
* Create a new authentication guard.
*/
public function __construct(protected UserProvider $provider, Application $app)
{
/** @var null|Request $request */
$request = $app->get('request');
$app->get('request');
// Log::debug(sprintf('Created RemoteUserGuard for %s "%s"', $request?->getMethod(), $request?->getRequestUri()));
$this->application = $app;
$this->user = null;
}
public function authenticate(): void

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Authentication;
use Illuminate\Support\Facades\Log;
use FireflyIII\Console\Commands\Correction\CreatesGroupMemberships;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Role;
@@ -41,7 +42,7 @@ class RemoteUserProvider implements UserProvider
#[Override]
public function rehashPasswordIfRequired(Authenticatable $user, array $credentials, bool $force = false): void
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
Log::debug(sprintf('Now at %s', __METHOD__));
throw new FireflyException(sprintf('Did not implement %s', __METHOD__));
}
@@ -53,7 +54,7 @@ class RemoteUserProvider implements UserProvider
*/
public function retrieveByCredentials(array $credentials): ?Authenticatable
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
Log::debug(sprintf('Now at %s', __METHOD__));
throw new FireflyException(sprintf('Did not implement %s', __METHOD__));
}
@@ -65,10 +66,10 @@ class RemoteUserProvider implements UserProvider
*/
public function retrieveById($identifier): User
{
app('log')->debug(sprintf('Now at %s(%s)', __METHOD__, $identifier));
Log::debug(sprintf('Now at %s(%s)', __METHOD__, $identifier));
$user = User::where('email', $identifier)->first();
if (null === $user) {
app('log')->debug(sprintf('User with email "%s" not found. Will be created.', $identifier));
Log::debug(sprintf('User with email "%s" not found. Will be created.', $identifier));
$user = User::create(
[
'blocked' => false,
@@ -86,7 +87,7 @@ class RemoteUserProvider implements UserProvider
// make sure the user gets an administration as well.
CreatesGroupMemberships::createGroupMembership($user);
app('log')->debug(sprintf('Going to return user #%d (%s)', $user->id, $user->email));
Log::debug(sprintf('Going to return user #%d (%s)', $user->id, $user->email));
return $user;
}
@@ -101,7 +102,7 @@ class RemoteUserProvider implements UserProvider
*/
public function retrieveByToken($identifier, $token): ?Authenticatable
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
Log::debug(sprintf('Now at %s', __METHOD__));
throw new FireflyException(sprintf('A) Did not implement %s', __METHOD__));
}
@@ -115,7 +116,7 @@ class RemoteUserProvider implements UserProvider
*/
public function updateRememberToken(Authenticatable $user, $token): void
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
Log::debug(sprintf('Now at %s', __METHOD__));
throw new FireflyException(sprintf('B) Did not implement %s', __METHOD__));
}
@@ -127,7 +128,7 @@ class RemoteUserProvider implements UserProvider
*/
public function validateCredentials(Authenticatable $user, array $credentials): bool
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
Log::debug(sprintf('Now at %s', __METHOD__));
throw new FireflyException(sprintf('C) Did not implement %s', __METHOD__));
}

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Binder;
use Illuminate\Support\Facades\Log;
use FireflyIII\Enums\AccountTypeEnum;
use Illuminate\Routing\Route;
use Illuminate\Support\Collection;
@@ -50,7 +51,7 @@ class AccountList implements BinderInterface
;
}
if ('allAssetAccounts' !== $value) {
$incoming = array_map('\intval', explode(',', $value));
$incoming = array_map(\intval(...), explode(',', $value));
$list = array_merge(array_unique($incoming), [0]);
/** @var Collection $collection */
@@ -66,7 +67,7 @@ class AccountList implements BinderInterface
return $collection;
}
}
app('log')->error(sprintf('Trying to show account list (%s), but user is not logged in or list is empty.', $route->uri));
Log::error(sprintf('Trying to show account list (%s), but user is not logged in or list is empty.', $route->uri));
throw new NotFoundHttpException();
}

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Binder;
use Illuminate\Support\Facades\Log;
use FireflyIII\Models\Budget;
use Illuminate\Routing\Route;
use Illuminate\Support\Collection;
@@ -47,10 +48,10 @@ class BudgetList implements BinderInterface
;
}
$list = array_unique(array_map('\intval', explode(',', $value)));
$list = array_unique(array_map(\intval(...), explode(',', $value)));
if (0 === count($list)) { // @phpstan-ignore-line
app('log')->warning('Budget list count is zero, return 404.');
Log::warning('Budget list count is zero, return 404.');
throw new NotFoundHttpException();
}
@@ -71,7 +72,7 @@ class BudgetList implements BinderInterface
return $collection;
}
}
app('log')->warning('BudgetList fallback to 404.');
Log::warning('BudgetList fallback to 404.');
throw new NotFoundHttpException();
}

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Binder;
use Illuminate\Support\Facades\Log;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Routing\Route;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
@@ -33,10 +34,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
*/
class CLIToken implements BinderInterface
{
/**
* @return mixed
*/
public static function routeBinder(string $value, Route $route)
public static function routeBinder(string $value, Route $route): string
{
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
@@ -50,12 +48,12 @@ class CLIToken implements BinderInterface
foreach ($users as $user) {
$accessToken = app('preferences')->getForUser($user, 'access_token');
if (null !== $accessToken && $accessToken->data === $value) {
app('log')->info(sprintf('Recognized user #%d (%s) from his access token.', $user->id, $user->email));
Log::info(sprintf('Recognized user #%d (%s) from his access token.', $user->id, $user->email));
return $value;
}
}
app('log')->error(sprintf('Recognized no users by access token "%s"', $value));
Log::error(sprintf('Recognized no users by access token "%s"', $value));
throw new NotFoundHttpException();
}

View File

@@ -46,7 +46,7 @@ class CategoryList implements BinderInterface
;
}
$list = array_unique(array_map('\intval', explode(',', $value)));
$list = array_unique(array_map(\intval(...), explode(',', $value)));
if (0 === count($list)) { // @phpstan-ignore-line
throw new NotFoundHttpException();
}

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Binder;
use Illuminate\Support\Facades\Log;
use Carbon\Carbon;
use Carbon\Exceptions\InvalidDateException;
use Carbon\Exceptions\InvalidFormatException;
@@ -61,7 +62,7 @@ class Date implements BinderInterface
];
if (array_key_exists($value, $magicWords)) {
$return = $magicWords[$value];
app('log')->debug(sprintf('User requests "%s", so will return "%s"', $value, $return));
Log::debug(sprintf('User requests "%s", so will return "%s"', $value, $return));
return $return;
}
@@ -70,7 +71,7 @@ class Date implements BinderInterface
$result = new Carbon($value);
} catch (InvalidDateException|InvalidFormatException $e) { // @phpstan-ignore-line
$message = sprintf('Could not parse date "%s" for user #%d: %s', $value, auth()->user()->id, $e->getMessage());
app('log')->error($message);
Log::error($message);
throw new NotFoundHttpException('Could not parse value', $e);
}

View File

@@ -60,7 +60,7 @@ class JournalList implements BinderInterface
protected static function parseList(string $value): array
{
$list = array_unique(array_map('\intval', explode(',', $value)));
$list = array_unique(array_map(\intval(...), explode(',', $value)));
if (0 === count($list)) { // @phpstan-ignore-line
throw new NotFoundHttpException();
}

View File

@@ -47,11 +47,11 @@ class TagList implements BinderInterface
->get()
;
}
$list = array_unique(array_map('\strtolower', explode(',', $value)));
app('log')->debug('List of tags is', $list);
$list = array_unique(array_map(\strtolower(...), explode(',', $value)));
Log::debug('List of tags is', $list);
if (0 === count($list)) { // @phpstan-ignore-line
app('log')->error('Tag list is empty.');
Log::error('Tag list is empty.');
throw new NotFoundHttpException();
}
@@ -62,7 +62,7 @@ class TagList implements BinderInterface
$allTags = $repository->get();
$collection = $allTags->filter(
static function (Tag $tag) use ($list) {
static function (Tag $tag) use ($list): bool {
if (in_array(strtolower($tag->tag), $list, true)) {
Log::debug(sprintf('TagList: (string) found tag #%d ("%s") in list.', $tag->id, $tag->tag));
@@ -82,7 +82,7 @@ class TagList implements BinderInterface
return $collection;
}
}
app('log')->error('TagList: user is not logged in.');
Log::error('TagList: user is not logged in.');
throw new NotFoundHttpException();
}

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Binder;
use Illuminate\Support\Facades\Log;
use FireflyIII\Models\Tag;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use Illuminate\Routing\Route;
@@ -47,11 +48,11 @@ class TagOrId implements BinderInterface
if (null !== $result) {
return $result;
}
app('log')->error('TagOrId: tag not found.');
Log::error('TagOrId: tag not found.');
throw new NotFoundHttpException();
}
app('log')->error('TagOrId: user is not logged in.');
Log::error('TagOrId: user is not logged in.');
throw new NotFoundHttpException();
}

View File

@@ -37,12 +37,12 @@ class Calculator
private static ?SplObjectStorage $intervalMap = null; // @phpstan-ignore-line
private static array $intervals = [];
private static function containsInterval(Periodicity $periodicity): bool
private function containsInterval(Periodicity $periodicity): bool
{
return self::loadIntervalMap()->contains($periodicity);
return $this->loadIntervalMap()->contains($periodicity);
}
private static function loadIntervalMap(): SplObjectStorage
private function loadIntervalMap(): SplObjectStorage
{
if (self::$intervalMap instanceof SplObjectStorage) {
return self::$intervalMap;
@@ -59,7 +59,7 @@ class Calculator
public function isAvailablePeriodicity(Periodicity $periodicity): bool
{
return self::containsInterval($periodicity);
return $this->containsInterval($periodicity);
}
/**

View File

@@ -45,7 +45,7 @@ class FrontpageChartGenerator
private readonly BudgetLimitRepositoryInterface $blRepository;
private readonly BudgetRepositoryInterface $budgetRepository;
private Carbon $end;
private string $monthAndDayFormat;
private string $monthAndDayFormat = '';
private Carbon $start;
/**
@@ -56,7 +56,6 @@ class FrontpageChartGenerator
$this->budgetRepository = app(BudgetRepositoryInterface::class);
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
$this->opsRepository = app(OperationsRepositoryInterface::class);
$this->monthAndDayFormat = '';
}
/**
@@ -192,7 +191,7 @@ class FrontpageChartGenerator
Log::debug(sprintf('Process spent row (%s)', $entry['currency_code']));
$data = $this->processRow($data, $budget, $limit, $entry);
}
if (!($entry['currency_id'] === $limit->transaction_currency_id || $usePrimary)) {
if ($entry['currency_id'] !== $limit->transaction_currency_id && !$usePrimary) {
Log::debug(sprintf('Skipping spent row (%s).', $entry['currency_code']));
}
}

View File

@@ -45,7 +45,7 @@ class FrontpageChartGenerator
public bool $convertToPrimary = false;
public TransactionCurrency $primaryCurrency;
private AccountRepositoryInterface $accountRepos;
private array $currencies;
private array $currencies = [];
private NoCategoryRepositoryInterface $noCatRepos;
private OperationsRepositoryInterface $opsRepos;
private CategoryRepositoryInterface $repository;
@@ -55,7 +55,6 @@ class FrontpageChartGenerator
*/
public function __construct(private Carbon $start, private Carbon $end)
{
$this->currencies = [];
$this->repository = app(CategoryRepositoryInterface::class);
$this->accountRepos = app(AccountRepositoryInterface::class);
$this->opsRepos = app(OperationsRepositoryInterface::class);

View File

@@ -31,12 +31,7 @@ use FireflyIII\Exceptions\FireflyException;
*/
class ChartData
{
private array $series;
public function __construct()
{
$this->series = [];
}
private array $series = [];
/**
* @throws FireflyException

View File

@@ -31,25 +31,20 @@ use Carbon\Carbon;
*/
abstract class AbstractCronjob
{
public bool $jobErrored;
public bool $jobFired;
public bool $jobSucceeded;
public ?string $message;
public bool $jobErrored = false;
public bool $jobFired = false;
public bool $jobSucceeded = false;
public ?string $message = null;
public int $timeBetweenRuns = 43200;
protected Carbon $date;
protected bool $force;
protected bool $force = false;
/**
* AbstractCronjob constructor.
*/
public function __construct()
{
$this->force = false;
$this->date = today(config('app.timezone'));
$this->jobErrored = false;
$this->jobSucceeded = false;
$this->jobFired = false;
$this->message = null;
}
abstract public function fire(): void;

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Support;
use Illuminate\Support\Facades\Log;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Support\Form\FormSupport;
use Illuminate\Database\Eloquent\Model;
@@ -56,9 +57,9 @@ class ExpandedForm
// $value = round((float)$value, 8);
// }
try {
$html = view('form.amount-no-currency', compact('classes', 'name', 'label', 'value', 'options'))->render();
$html = view('form.amount-no-currency', ['classes' => $classes, 'name' => $name, 'label' => $label, 'value' => $value, 'options' => $options])->render();
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render amountNoCurrency(): %s', $e->getMessage()));
Log::error(sprintf('Could not render amountNoCurrency(): %s', $e->getMessage()));
$html = 'Could not render amountNoCurrency.';
throw new FireflyException($html, 0, $e);
@@ -91,9 +92,9 @@ class ExpandedForm
unset($options['placeholder'], $options['autocomplete'], $options['class']);
try {
$html = view('form.checkbox', compact('classes', 'name', 'label', 'value', 'options'))->render();
$html = view('form.checkbox', ['classes' => $classes, 'name' => $name, 'label' => $label, 'value' => $value, 'options' => $options])->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render checkbox(): %s', $e->getMessage()));
Log::debug(sprintf('Could not render checkbox(): %s', $e->getMessage()));
$html = 'Could not render checkbox.';
throw new FireflyException($html, 0, $e);
@@ -116,9 +117,9 @@ class ExpandedForm
unset($options['placeholder']);
try {
$html = view('form.date', compact('classes', 'name', 'label', 'value', 'options'))->render();
$html = view('form.date', ['classes' => $classes, 'name' => $name, 'label' => $label, 'value' => $value, 'options' => $options])->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render date(): %s', $e->getMessage()));
Log::debug(sprintf('Could not render date(): %s', $e->getMessage()));
$html = 'Could not render date.';
throw new FireflyException($html, 0, $e);
@@ -138,9 +139,9 @@ class ExpandedForm
$classes = $this->getHolderClasses($name);
try {
$html = view('form.file', compact('classes', 'name', 'label', 'options'))->render();
$html = view('form.file', ['classes' => $classes, 'name' => $name, 'label' => $label, 'options' => $options])->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render file(): %s', $e->getMessage()));
Log::debug(sprintf('Could not render file(): %s', $e->getMessage()));
$html = 'Could not render file.';
throw new FireflyException($html, 0, $e);
@@ -164,9 +165,9 @@ class ExpandedForm
$options['step'] ??= '1';
try {
$html = view('form.integer', compact('classes', 'name', 'label', 'value', 'options'))->render();
$html = view('form.integer', ['classes' => $classes, 'name' => $name, 'label' => $label, 'value' => $value, 'options' => $options])->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render integer(): %s', $e->getMessage()));
Log::debug(sprintf('Could not render integer(): %s', $e->getMessage()));
$html = 'Could not render integer.';
throw new FireflyException($html, 0, $e);
@@ -189,9 +190,9 @@ class ExpandedForm
$value = $this->fillFieldValue($name, $value);
try {
$html = view('form.location', compact('classes', 'name', 'label', 'value', 'options'))->render();
$html = view('form.location', ['classes' => $classes, 'name' => $name, 'label' => $label, 'value' => $value, 'options' => $options])->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render location(): %s', $e->getMessage()));
Log::debug(sprintf('Could not render location(): %s', $e->getMessage()));
$html = 'Could not render location.';
throw new FireflyException($html, 0, $e);
@@ -224,8 +225,6 @@ class ExpandedForm
}
/**
* @param null $value
*
* @throws FireflyException
*/
public function objectGroup($value = null, ?array $options = null): string
@@ -242,9 +241,9 @@ class ExpandedForm
}
try {
$html = view('form.object_group', compact('classes', 'name', 'label', 'value', 'options'))->render();
$html = view('form.object_group', ['classes' => $classes, 'name' => $name, 'label' => $label, 'value' => $value, 'options' => $options])->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render objectGroup(): %s', $e->getMessage()));
Log::debug(sprintf('Could not render objectGroup(): %s', $e->getMessage()));
$html = 'Could not render objectGroup.';
throw new FireflyException($html, 0, $e);
@@ -259,9 +258,9 @@ class ExpandedForm
public function optionsList(string $type, string $name): string
{
try {
$html = view('form.options', compact('type', 'name'))->render();
$html = view('form.options', ['type' => $type, 'name' => $name])->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render select(): %s', $e->getMessage()));
Log::debug(sprintf('Could not render select(): %s', $e->getMessage()));
$html = 'Could not render optionsList.';
throw new FireflyException($html, 0, $e);
@@ -280,9 +279,9 @@ class ExpandedForm
$classes = $this->getHolderClasses($name);
try {
$html = view('form.password', compact('classes', 'name', 'label', 'options'))->render();
$html = view('form.password', ['classes' => $classes, 'name' => $name, 'label' => $label, 'options' => $options])->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render password(): %s', $e->getMessage()));
Log::debug(sprintf('Could not render password(): %s', $e->getMessage()));
$html = 'Could not render password.';
throw new FireflyException($html, 0, $e);
@@ -301,9 +300,9 @@ class ExpandedForm
$classes = $this->getHolderClasses($name);
try {
$html = view('form.password', compact('classes', 'value', 'name', 'label', 'options'))->render();
$html = view('form.password', ['classes' => $classes, 'value' => $value, 'name' => $name, 'label' => $label, 'options' => $options])->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render passwordWithValue(): %s', $e->getMessage()));
Log::debug(sprintf('Could not render passwordWithValue(): %s', $e->getMessage()));
$html = 'Could not render passwordWithValue.';
throw new FireflyException($html, 0, $e);
@@ -329,9 +328,9 @@ class ExpandedForm
unset($options['placeholder']);
try {
$html = view('form.percentage', compact('classes', 'name', 'label', 'value', 'options'))->render();
$html = view('form.percentage', ['classes' => $classes, 'name' => $name, 'label' => $label, 'value' => $value, 'options' => $options])->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render percentage(): %s', $e->getMessage()));
Log::debug(sprintf('Could not render percentage(): %s', $e->getMessage()));
$html = 'Could not render percentage.';
throw new FireflyException($html, 0, $e);
@@ -352,9 +351,9 @@ class ExpandedForm
$classes = $this->getHolderClasses($name);
try {
$html = view('form.static', compact('classes', 'name', 'label', 'value', 'options'))->render();
$html = view('form.static', ['classes' => $classes, 'name' => $name, 'label' => $label, 'value' => $value, 'options' => $options])->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render staticText(): %s', $e->getMessage()));
Log::debug(sprintf('Could not render staticText(): %s', $e->getMessage()));
$html = 'Could not render staticText.';
throw new FireflyException($html, 0, $e);
@@ -376,9 +375,9 @@ class ExpandedForm
$value = $this->fillFieldValue($name, $value);
try {
$html = view('form.text', compact('classes', 'name', 'label', 'value', 'options'))->render();
$html = view('form.text', ['classes' => $classes, 'name' => $name, 'label' => $label, 'value' => $value, 'options' => $options])->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render text(): %s', $e->getMessage()));
Log::debug(sprintf('Could not render text(): %s', $e->getMessage()));
$html = 'Could not render text.';
throw new FireflyException($html, 0, $e);
@@ -405,9 +404,9 @@ class ExpandedForm
}
try {
$html = view('form.textarea', compact('classes', 'name', 'label', 'value', 'options'))->render();
$html = view('form.textarea', ['classes' => $classes, 'name' => $name, 'label' => $label, 'value' => $value, 'options' => $options])->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render textarea(): %s', $e->getMessage()));
Log::debug(sprintf('Could not render textarea(): %s', $e->getMessage()));
$html = 'Could not render textarea.';
throw new FireflyException($html, 0, $e);

View File

@@ -76,15 +76,15 @@ class ExportDataGenerator
private const string EXPORT_ERR = 'Could not export to string: %s';
private Collection $accounts;
private Carbon $end;
private bool $exportAccounts;
private bool $exportBills;
private bool $exportBudgets;
private bool $exportCategories;
private bool $exportPiggies;
private bool $exportRecurring;
private bool $exportRules;
private bool $exportTags;
private bool $exportTransactions;
private bool $exportAccounts = false;
private bool $exportBills = false;
private bool $exportBudgets = false;
private bool $exportCategories = false;
private bool $exportPiggies = false;
private bool $exportRecurring = false;
private bool $exportRules = false;
private bool $exportTags = false;
private bool $exportTransactions = false;
private Carbon $start;
private User $user;
private UserGroup $userGroup; // @phpstan-ignore-line
@@ -95,15 +95,6 @@ class ExportDataGenerator
$this->start = today(config('app.timezone'));
$this->start->subYear();
$this->end = today(config('app.timezone'));
$this->exportTransactions = false;
$this->exportAccounts = false;
$this->exportBudgets = false;
$this->exportCategories = false;
$this->exportTags = false;
$this->exportRecurring = false;
$this->exportRules = false;
$this->exportBills = false;
$this->exportPiggies = false;
}
/**
@@ -306,7 +297,7 @@ class ExportDataGenerator
try {
$string = $csv->toString();
} catch (Exception $e) { // intentional generic exception
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e);
}
@@ -375,7 +366,7 @@ class ExportDataGenerator
try {
$string = $csv->toString();
} catch (Exception $e) { // intentional generic exception
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e);
}
@@ -444,7 +435,7 @@ class ExportDataGenerator
try {
$string = $csv->toString();
} catch (Exception $e) { // intentional generic exception
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e);
}
@@ -495,7 +486,7 @@ class ExportDataGenerator
try {
$string = $csv->toString();
} catch (Exception $e) { // intentional generic exception
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e);
}
@@ -575,7 +566,7 @@ class ExportDataGenerator
try {
$string = $csv->toString();
} catch (Exception $e) { // intentional generic exception
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e);
}
@@ -667,7 +658,7 @@ class ExportDataGenerator
try {
$string = $csv->toString();
} catch (Exception $e) { // intentional generic exception
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e);
}
@@ -744,7 +735,7 @@ class ExportDataGenerator
try {
$string = $csv->toString();
} catch (Exception $e) { // intentional generic exception
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e);
}
@@ -800,7 +791,7 @@ class ExportDataGenerator
try {
$string = $csv->toString();
} catch (Exception $e) { // intentional generic exception
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e);
}
@@ -901,7 +892,7 @@ class ExportDataGenerator
try {
$string = $csv->toString();
} catch (Exception $e) { // intentional generic exception
app('log')->error($e->getMessage());
Log::error($e->getMessage());
throw new FireflyException(sprintf(self::EXPORT_ERR, $e->getMessage()), 0, $e);
}

View File

@@ -23,13 +23,14 @@ declare(strict_types=1);
namespace FireflyIII\Support\Facades;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Facade;
class Preferences extends Facade
{
public function __construct()
{
app('log')->warning('Hi there');
Log::warning('Hi there');
}
/**

View File

@@ -133,7 +133,7 @@ class FireflyConfig
try {
$config = Configuration::whereName($name)->whereNull('deleted_at')->first();
} catch (QueryException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
$item = new Configuration();
$item->name = $name;
$item->data = $value;

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Form;
use Illuminate\Support\Facades\Log;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
@@ -93,9 +94,9 @@ class AccountForm
unset($options['class']);
try {
$html = view('form.assetAccountCheckList', compact('classes', 'selected', 'name', 'label', 'options', 'grouped'))->render();
$html = view('form.assetAccountCheckList', ['classes' => $classes, 'selected' => $selected, 'name' => $name, 'label' => $label, 'options' => $options, 'grouped' => $grouped])->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render assetAccountCheckList(): %s', $e->getMessage()));
Log::debug(sprintf('Could not render assetAccountCheckList(): %s', $e->getMessage()));
$html = 'Could not render assetAccountCheckList.';
throw new FireflyException($html, 0, $e);

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Form;
use Illuminate\Support\Facades\Log;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
@@ -135,13 +136,13 @@ class CurrencyForm
$key = 'amount_currency_id_'.$name;
$sentCurrencyId = array_key_exists($key, $preFilled) ? (int)$preFilled[$key] : $primaryCurrency->id;
app('log')->debug(sprintf('Sent currency ID is %d', $sentCurrencyId));
Log::debug(sprintf('Sent currency ID is %d', $sentCurrencyId));
// find this currency in set of currencies:
foreach ($currencies as $currency) {
if ($currency->id === $sentCurrencyId) {
$primaryCurrency = $currency;
app('log')->debug(sprintf('default currency is now %s', $primaryCurrency->code));
Log::debug(sprintf('default currency is now %s', $primaryCurrency->code));
break;
}
@@ -153,9 +154,9 @@ class CurrencyForm
}
try {
$html = view('form.'.$view, compact('primaryCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();
$html = view('form.'.$view, ['primaryCurrency' => $primaryCurrency, 'currencies' => $currencies, 'classes' => $classes, 'name' => $name, 'label' => $label, 'value' => $value, 'options' => $options])->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render currencyField(): %s', $e->getMessage()));
Log::debug(sprintf('Could not render currencyField(): %s', $e->getMessage()));
$html = 'Could not render currencyField.';
throw new FireflyException($html, 0, $e);
@@ -187,13 +188,13 @@ class CurrencyForm
$key = 'amount_currency_id_'.$name;
$sentCurrencyId = array_key_exists($key, $preFilled) ? (int)$preFilled[$key] : $primaryCurrency->id;
app('log')->debug(sprintf('Sent currency ID is %d', $sentCurrencyId));
Log::debug(sprintf('Sent currency ID is %d', $sentCurrencyId));
// find this currency in set of currencies:
foreach ($currencies as $currency) {
if ($currency->id === $sentCurrencyId) {
$primaryCurrency = $currency;
app('log')->debug(sprintf('default currency is now %s', $primaryCurrency->code));
Log::debug(sprintf('default currency is now %s', $primaryCurrency->code));
break;
}
@@ -205,9 +206,9 @@ class CurrencyForm
}
try {
$html = view('form.'.$view, compact('primaryCurrency', 'currencies', 'classes', 'name', 'label', 'value', 'options'))->render();
$html = view('form.'.$view, ['primaryCurrency' => $primaryCurrency, 'currencies' => $currencies, 'classes' => $classes, 'name' => $name, 'label' => $label, 'value' => $value, 'options' => $options])->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render currencyField(): %s', $e->getMessage()));
Log::debug(sprintf('Could not render currencyField(): %s', $e->getMessage()));
$html = 'Could not render currencyField.';
throw new FireflyException($html, 0, $e);

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Form;
use Illuminate\Support\Facades\Log;
use Carbon\Carbon;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Support\MessageBag;
@@ -45,9 +46,9 @@ trait FormSupport
unset($options['autocomplete'], $options['placeholder']);
try {
$html = view('form.multi-select', compact('classes', 'name', 'label', 'selected', 'options', 'list'))->render();
$html = view('form.multi-select', ['classes' => $classes, 'name' => $name, 'label' => $label, 'selected' => $selected, 'options' => $options, 'list' => $list])->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render multi-select(): %s', $e->getMessage()));
Log::debug(sprintf('Could not render multi-select(): %s', $e->getMessage()));
$html = 'Could not render multi-select.';
}
@@ -67,9 +68,9 @@ trait FormSupport
unset($options['autocomplete'], $options['placeholder']);
try {
$html = view('form.select', compact('classes', 'name', 'label', 'selected', 'options', 'list'))->render();
$html = view('form.select', ['classes' => $classes, 'name' => $name, 'label' => $label, 'selected' => $selected, 'options' => $options, 'list' => $list])->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Could not render select(): %s', $e->getMessage()));
Log::debug(sprintf('Could not render select(): %s', $e->getMessage()));
$html = 'Could not render select.';
}

View File

@@ -52,9 +52,6 @@ class RuleForm
return $this->select($name, $array, $value, $options);
}
/**
* @param null $value
*/
public function ruleGroupListWithEmpty(string $name, $value = null, ?array $options = null): string
{
$options ??= [];

View File

@@ -39,7 +39,7 @@ use Illuminate\Support\Facades\Log;
*/
class AccountBalanceGrouped
{
private array $accountIds;
private array $accountIds = [];
private string $carbonFormat;
private readonly ExchangeRateConverter $converter;
private array $currencies = [];
@@ -52,7 +52,6 @@ class AccountBalanceGrouped
public function __construct()
{
$this->accountIds = [];
$this->converter = app(ExchangeRateConverter::class);
}
@@ -258,7 +257,7 @@ class AccountBalanceGrouped
try {
$rate = $this->converter->getCurrencyRate($currency, $this->primary, $date);
} catch (FireflyException $e) {
app('log')->error($e->getMessage());
Log::error($e->getMessage());
$rate = '1';
}

View File

@@ -71,7 +71,7 @@ class ExchangeRateConverter
public function enabled(): bool
{
return false !== config('cer.enabled') || true === $this->ignoreSettings;
return false !== config('cer.enabled') || $this->ignoreSettings;
}
/**
@@ -147,24 +147,24 @@ class ExchangeRateConverter
$rate = $this->getFromDB($currency->id, $euroId, $date->format('Y-m-d'));
if (null !== $rate) {
// app('log')->debug(sprintf('Rate for %s to EUR is %s.', $currency->code, $rate));
// \Illuminate\Support\Facades\Log::debug(sprintf('Rate for %s to EUR is %s.', $currency->code, $rate));
return $rate;
}
$rate = $this->getFromDB($euroId, $currency->id, $date->format('Y-m-d'));
if (null !== $rate) {
return bcdiv('1', $rate);
// app('log')->debug(sprintf('Inverted rate for %s to EUR is %s.', $currency->code, $rate));
// \Illuminate\Support\Facades\Log::debug(sprintf('Inverted rate for %s to EUR is %s.', $currency->code, $rate));
// return $rate;
}
// grab backup values from config file:
$backup = config(sprintf('cer.rates.%s', $currency->code));
if (null !== $backup) {
return bcdiv('1', (string)$backup);
// app('log')->debug(sprintf('Backup rate for %s to EUR is %s.', $currency->code, $backup));
// \Illuminate\Support\Facades\Log::debug(sprintf('Backup rate for %s to EUR is %s.', $currency->code, $backup));
// return $backup;
}
// app('log')->debug(sprintf('No rate for %s to EUR.', $currency->code));
// \Illuminate\Support\Facades\Log::debug(sprintf('No rate for %s to EUR.', $currency->code));
return '0';
}
@@ -209,16 +209,16 @@ class ExchangeRateConverter
$rate = (string)$result?->rate;
if ('' === $rate) {
app('log')->debug(sprintf('ExchangeRateConverter: Found no rate for #%d->#%d (%s) in the DB.', $from, $to, $date));
Log::debug(sprintf('ExchangeRateConverter: Found no rate for #%d->#%d (%s) in the DB.', $from, $to, $date));
return null;
}
if (0 === bccomp('0', $rate)) {
app('log')->debug(sprintf('ExchangeRateConverter: Found rate for #%d->#%d (%s) in the DB, but it\'s zero.', $from, $to, $date));
Log::debug(sprintf('ExchangeRateConverter: Found rate for #%d->#%d (%s) in the DB, but it\'s zero.', $from, $to, $date));
return null;
}
app('log')->debug(sprintf('ExchangeRateConverter: Found rate for #%d->#%d (%s) in the DB: %s.', $from, $to, $date, $rate));
Log::debug(sprintf('ExchangeRateConverter: Found rate for #%d->#%d (%s) in the DB: %s.', $from, $to, $date, $rate));
$cache->store($rate);
// if the rate has not been cached during this particular run, save it

View File

@@ -33,15 +33,13 @@ class SummaryBalanceGrouped
{
private const string SUM = 'sum';
private array $amounts = [];
private array $currencies;
private array $currencies = [];
private readonly CurrencyRepositoryInterface $currencyRepository;
private TransactionCurrency $default;
private array $keys;
private array $keys = [self::SUM];
public function __construct()
{
$this->keys = [self::SUM];
$this->currencies = [];
$this->currencyRepository = app(CurrencyRepositoryInterface::class);
}

View File

@@ -70,7 +70,7 @@ trait GetConfigurationData
$steps[] = $currentStep;
}
}
app('log')->debug(sprintf('Total basic steps for %s is %d', $routeKey, count($steps)));
Log::debug(sprintf('Total basic steps for %s is %d', $routeKey, count($steps)));
return $steps;
}
@@ -199,7 +199,7 @@ trait GetConfigurationData
}
}
}
app('log')->debug(sprintf('Total specific steps for route "%s" and page "%s" (routeKey is "%s") is %d', $route, $specificPage, $routeKey, count($steps)));
Log::debug(sprintf('Total specific steps for route "%s" and page "%s" (routeKey is "%s") is %d', $route, $specificPage, $routeKey, count($steps)));
return $steps;
}
@@ -209,7 +209,7 @@ trait GetConfigurationData
$config = FireflyConfig::get('last_rt_job', 0);
$lastTime = (int)$config?->data;
$now = Carbon::now()->getTimestamp();
app('log')->debug(sprintf('verifyRecurringCronJob: last time is %d ("%s"), now is %d', $lastTime, $config?->data, $now));
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

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Http\Controllers;
use Illuminate\Support\Facades\Log;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\AccountType;
@@ -57,8 +58,8 @@ trait ModelInformation
]
)->render();
} catch (Throwable $e) {
app('log')->error(sprintf('Throwable was thrown in getActionsForBill(): %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
Log::error(sprintf('Throwable was thrown in getActionsForBill(): %s', $e->getMessage()));
Log::error($e->getTraceAsString());
$result = 'Could not render view. See log files.';
throw new FireflyException($result, 0, $e);
@@ -144,8 +145,8 @@ trait ModelInformation
]
)->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Throwable was thrown in getTriggersForBill(): %s', $e->getMessage()));
app('log')->debug($e->getTraceAsString());
Log::debug(sprintf('Throwable was thrown in getTriggersForBill(): %s', $e->getMessage()));
Log::debug($e->getTraceAsString());
throw new FireflyException(sprintf('Could not render trigger: %s', $e->getMessage()), 0, $e);
}
@@ -260,8 +261,8 @@ trait ModelInformation
];
$string = view('rules.partials.trigger', $renderInfo)->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Throwable was thrown in getTriggersForJournal(): %s', $e->getMessage()));
app('log')->debug($e->getTraceAsString());
Log::debug(sprintf('Throwable was thrown in getTriggersForJournal(): %s', $e->getMessage()));
Log::debug($e->getTraceAsString());
throw new FireflyException(sprintf('Could not render trigger: %s', $e->getMessage()), 0, $e);
}

View File

@@ -331,7 +331,7 @@ trait PeriodOverview
}
return $this->statistics->filter(
fn (PeriodStatistic $statistic) => $statistic->start->eq($start) && $statistic->end->eq($end) && $statistic->type === $type
fn (PeriodStatistic $statistic): bool => $statistic->start->eq($start) && $statistic->end->eq($end) && $statistic->type === $type
);
}
@@ -344,7 +344,7 @@ trait PeriodOverview
}
return $this->statistics->filter(
fn (PeriodStatistic $statistic) => $statistic->start->eq($start) && $statistic->end->eq($end) && str_starts_with($statistic->type, $prefix)
fn (PeriodStatistic $statistic): bool => $statistic->start->eq($start) && $statistic->end->eq($end) && str_starts_with($statistic->type, $prefix)
);
}
@@ -571,10 +571,6 @@ trait PeriodOverview
{
$result = [];
/**
* @var int $index
* @var array $item
*/
foreach ($this->transactions as $item) {
$date = Carbon::parse($item['date']);
$fits = $item['type'] === $type->value && $date >= $start && $date <= $end;
@@ -595,10 +591,6 @@ trait PeriodOverview
{
$result = [];
/**
* @var int $index
* @var array $item
*/
foreach ($this->transactions as $item) {
$date = Carbon::parse($item['date']);
if ($date >= $start && $date <= $end) {

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Http\Controllers;
use Illuminate\Support\Facades\Log;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Report\PopupReportInterface;
@@ -68,9 +69,9 @@ trait RenderPartialViews
$journals = $popupHelper->balanceForBudget($budget, $account, $attributes);
try {
$view = view('popup.report.balance-amount', compact('journals', 'budget', 'account'))->render();
$view = view('popup.report.balance-amount', ['journals' => $journals, 'budget' => $budget, 'account' => $account])->render();
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
Log::error(sprintf('Could not render: %s', $e->getMessage()));
$view = 'Firefly III could not render the view. Please see the log files.';
throw new FireflyException($view, 0, $e);
@@ -91,9 +92,9 @@ trait RenderPartialViews
$budgets = $repository->getActiveBudgets();
try {
$result = view('reports.options.budget', compact('budgets'))->render();
$result = view('reports.options.budget', ['budgets' => $budgets])->render();
} catch (Throwable $e) {
app('log')->error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
Log::error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
$result = 'Could not render view.';
throw new FireflyException($result, 0, $e);
@@ -123,9 +124,9 @@ trait RenderPartialViews
$journals = $popupHelper->byBudget($budget, $attributes);
try {
$view = view('popup.report.budget-spent-amount', compact('journals', 'budget'))->render();
$view = view('popup.report.budget-spent-amount', ['journals' => $journals, 'budget' => $budget])->render();
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
Log::error(sprintf('Could not render: %s', $e->getMessage()));
$view = 'Firefly III could not render the view. Please see the log files.';
throw new FireflyException($view, 0, $e);
@@ -150,9 +151,9 @@ trait RenderPartialViews
$journals = $popupHelper->byCategory($category, $attributes);
try {
$view = view('popup.report.category-entry', compact('journals', 'category'))->render();
$view = view('popup.report.category-entry', ['journals' => $journals, 'category' => $category])->render();
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
Log::error(sprintf('Could not render: %s', $e->getMessage()));
$view = 'Firefly III could not render the view. Please see the log files.';
throw new FireflyException($view, 0, $e);
@@ -173,9 +174,9 @@ trait RenderPartialViews
$categories = $repository->getCategories();
try {
$result = view('reports.options.category', compact('categories'))->render();
$result = view('reports.options.category', ['categories' => $categories])->render();
} catch (Throwable $e) {
app('log')->error(sprintf('Cannot render reports.options.category: %s', $e->getMessage()));
Log::error(sprintf('Cannot render reports.options.category: %s', $e->getMessage()));
$result = 'Could not render view.';
throw new FireflyException($result, 0, $e);
@@ -215,9 +216,9 @@ trait RenderPartialViews
}
try {
$result = view('reports.options.double', compact('set'))->render();
$result = view('reports.options.double', ['set' => $set])->render();
} catch (Throwable $e) {
app('log')->error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
Log::error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
$result = 'Could not render view.';
throw new FireflyException($result, 0, $e);
@@ -248,9 +249,9 @@ trait RenderPartialViews
$journals = $popupHelper->byExpenses($account, $attributes);
try {
$view = view('popup.report.expense-entry', compact('journals', 'account'))->render();
$view = view('popup.report.expense-entry', ['journals' => $journals, 'account' => $account])->render();
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
Log::error(sprintf('Could not render: %s', $e->getMessage()));
$view = 'Firefly III could not render the view. Please see the log files.';
throw new FireflyException($view, 0, $e);
@@ -286,8 +287,8 @@ trait RenderPartialViews
]
)->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Throwable was thrown in getCurrentActions(): %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
Log::debug(sprintf('Throwable was thrown in getCurrentActions(): %s', $e->getMessage()));
Log::error($e->getTraceAsString());
throw new FireflyException(sprintf('Could not render: %s', $e->getMessage()), 0, $e);
}
@@ -341,8 +342,8 @@ trait RenderPartialViews
]
)->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Throwable was thrown in getCurrentTriggers(): %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
Log::debug(sprintf('Throwable was thrown in getCurrentTriggers(): %s', $e->getMessage()));
Log::error($e->getTraceAsString());
throw new FireflyException(sprintf('Could not render: %s', $e->getMessage()), 0, $e);
}
@@ -375,9 +376,9 @@ trait RenderPartialViews
$journals = $popupHelper->byIncome($account, $attributes);
try {
$view = view('popup.report.income-entry', compact('journals', 'account'))->render();
$view = view('popup.report.income-entry', ['journals' => $journals, 'account' => $account])->render();
} catch (Throwable $e) {
app('log')->error(sprintf('Could not render: %s', $e->getMessage()));
Log::error(sprintf('Could not render: %s', $e->getMessage()));
$view = 'Firefly III could not render the view. Please see the log files.';
throw new FireflyException($view, 0, $e);
@@ -396,7 +397,7 @@ trait RenderPartialViews
try {
$result = view('reports.options.no-options')->render();
} catch (Throwable $e) {
app('log')->error(sprintf('Cannot render reports.options.no-options: %s', $e->getMessage()));
Log::error(sprintf('Cannot render reports.options.no-options: %s', $e->getMessage()));
$result = 'Could not render view.';
throw new FireflyException($result, 0, $e);
@@ -417,9 +418,9 @@ trait RenderPartialViews
$tags = $repository->get();
try {
$result = view('reports.options.tag', compact('tags'))->render();
$result = view('reports.options.tag', ['tags' => $tags])->render();
} catch (Throwable $e) {
app('log')->error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
Log::error(sprintf('Cannot render reports.options.tag: %s', $e->getMessage()));
$result = 'Could not render view.';
throw new FireflyException($result, 0, $e);

View File

@@ -133,11 +133,7 @@ trait RequestInformation
return true;
}
// start and end in the past? use $end
if ($start->lessThanOrEqualTo($date) && $end->lessThanOrEqualTo($date)) {
return true;
}
return false;
return $start->lessThanOrEqualTo($date) && $end->lessThanOrEqualTo($date);
}
/**

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Http\Controllers;
use Illuminate\Support\Facades\Log;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
use FireflyIII\Support\Search\OperatorQuerySearch;
@@ -56,8 +57,8 @@ trait RuleManagement
]
)->render();
} catch (Throwable $e) {
app('log')->error(sprintf('Throwable was thrown in getPreviousActions(): %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
Log::error(sprintf('Throwable was thrown in getPreviousActions(): %s', $e->getMessage()));
Log::error($e->getTraceAsString());
throw new FireflyException(sprintf('Could not render: %s', $e->getMessage()), 0, $e);
}
@@ -101,8 +102,8 @@ trait RuleManagement
]
)->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
Log::debug(sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage()));
Log::error($e->getTraceAsString());
throw new FireflyException(sprintf('Could not render: %s', $e->getMessage()), 0, $e);
}
@@ -147,8 +148,8 @@ trait RuleManagement
]
)->render();
} catch (Throwable $e) {
app('log')->debug(sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
Log::debug(sprintf('Throwable was thrown in getPreviousTriggers(): %s', $e->getMessage()));
Log::error($e->getTraceAsString());
throw new FireflyException(sprintf('Could not render: %s', $e->getMessage()), 0, $e);
}

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Http\Controllers;
use Illuminate\Support\Facades\Log;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
use FireflyIII\Models\Account;
@@ -48,9 +49,9 @@ trait UserNavigation
*/
final protected function getPreviousUrl(string $identifier): string
{
app('log')->debug(sprintf('Trying to retrieve URL stored under "%s"', $identifier));
Log::debug(sprintf('Trying to retrieve URL stored under "%s"', $identifier));
$url = (string)session($identifier);
app('log')->debug(sprintf('The URL is %s', $url));
Log::debug(sprintf('The URL is %s', $url));
return app('steam')->getSafeUrl($url, route('index'));
}
@@ -79,10 +80,7 @@ trait UserNavigation
return in_array($type, $editable, true);
}
/**
* @return Redirector|RedirectResponse
*/
final protected function redirectAccountToAccount(Account $account)
final protected function redirectAccountToAccount(Account $account): Redirector|RedirectResponse
{
$type = $account->accountType->type;
if (AccountTypeEnum::RECONCILIATION->value === $type || AccountTypeEnum::INITIAL_BALANCE->value === $type || AccountTypeEnum::LIABILITY_CREDIT->value === $type) {
@@ -91,7 +89,7 @@ trait UserNavigation
/** @var null|Transaction $transaction */
$transaction = $account->transactions()->first();
if (null === $transaction) {
app('log')->error(sprintf('Account #%d has no transactions. Dont know where it belongs.', $account->id));
Log::error(sprintf('Account #%d has no transactions. Dont know where it belongs.', $account->id));
session()->flash('error', trans('firefly.cant_find_redirect_account'));
return redirect(route('index'));
@@ -101,7 +99,7 @@ trait UserNavigation
/** @var null|Transaction $other */
$other = $journal->transactions()->where('id', '!=', $transaction->id)->first();
if (null === $other) {
app('log')->error(sprintf('Account #%d has no valid journals. Dont know where it belongs.', $account->id));
Log::error(sprintf('Account #%d has no valid journals. Dont know where it belongs.', $account->id));
session()->flash('error', trans('firefly.cant_find_redirect_account'));
return redirect(route('index'));
@@ -113,15 +111,12 @@ trait UserNavigation
return redirect(route('index'));
}
/**
* @return Redirector|RedirectResponse
*/
final protected function redirectGroupToAccount(TransactionGroup $group)
final protected function redirectGroupToAccount(TransactionGroup $group): Redirector|RedirectResponse
{
/** @var null|TransactionJournal $journal */
$journal = $group->transactionJournals()->first();
if (null === $journal) {
app('log')->error(sprintf('No journals in group #%d', $group->id));
Log::error(sprintf('No journals in group #%d', $group->id));
return redirect(route('index'));
}
@@ -145,7 +140,7 @@ trait UserNavigation
$return = app('steam')->getSafePreviousUrl();
session()->put($identifier, $return);
app('log')->debug(sprintf('rememberPreviousUrl: %s: "%s"', $identifier, $return));
Log::debug(sprintf('rememberPreviousUrl: %s: "%s"', $identifier, $return));
return $return;
}

View File

@@ -167,7 +167,7 @@ class AccountEnrichment implements EnrichmentInterface
private function appendCollectedData(): void
{
$this->collection = $this->collection->map(function (Account $item) {
$this->collection = $this->collection->map(function (Account $item): Account {
$id = (int)$item->id;
$item->full_account_type = $this->accountTypes[(int)$item->account_type_id] ?? null;
$meta = [

View File

@@ -52,8 +52,6 @@ class AvailableBudgetEnrichment implements EnrichmentInterface
private readonly BudgetRepositoryInterface $repository;
private array $spentInBudgets = [];
private array $spentOutsideBudgets = [];
private User $user;
private UserGroup $userGroup;
public function __construct()
{
@@ -91,14 +89,12 @@ class AvailableBudgetEnrichment implements EnrichmentInterface
#[Override]
public function setUser(User $user): void
{
$this->user = $user;
$this->setUserGroup($user->userGroup);
}
#[Override]
public function setUserGroup(UserGroup $userGroup): void
{
$this->userGroup = $userGroup;
$this->noBudgetRepository->setUserGroup($userGroup);
$this->opsRepository->setUserGroup($userGroup);
$this->repository->setUserGroup($userGroup);
@@ -106,7 +102,7 @@ class AvailableBudgetEnrichment implements EnrichmentInterface
private function appendCollectedData(): void
{
$this->collection = $this->collection->map(function (AvailableBudget $item) {
$this->collection = $this->collection->map(function (AvailableBudget $item): AvailableBudget {
$id = (int)$item->id;
$currencyId = $this->currencyIds[$id];
$currency = $this->currencies[$currencyId];
@@ -158,7 +154,7 @@ class AvailableBudgetEnrichment implements EnrichmentInterface
$this->spentInBudgets[$id] = array_values($filteredSpentInBudgets);
$this->spentOutsideBudgets[$id] = array_values($filteredSpentOutsideBudgets);
if (true === $this->convertToPrimary) {
if ($this->convertToPrimary) {
$pcFilteredSpentInBudgets = $this->opsRepository->sumCollectedExpenses($spentInBudgets, $availableBudget->start_date, $availableBudget->end_date, $currency, true);
$pcFilteredSpentOutsideBudgets = $this->opsRepository->sumCollectedExpenses($spentOutsideBudgets, $availableBudget->start_date, $availableBudget->end_date, $currency, true);
$this->pcSpentInBudgets[$id] = array_values($pcFilteredSpentInBudgets);

View File

@@ -54,8 +54,6 @@ class BudgetEnrichment implements EnrichmentInterface
private User $user;
private UserGroup $userGroup;
public function __construct() {}
public function enrich(Collection $collection): Collection
{
$this->collection = $collection;
@@ -102,7 +100,7 @@ class BudgetEnrichment implements EnrichmentInterface
private function appendCollectedData(): void
{
$this->collection = $this->collection->map(function (Budget $item) {
$this->collection = $this->collection->map(function (Budget $item): Budget {
$id = (int)$item->id;
$meta = [
'object_group_id' => null,

View File

@@ -41,7 +41,7 @@ use Illuminate\Support\Facades\Log;
class BudgetLimitEnrichment implements EnrichmentInterface
{
private Collection $collection;
private bool $convertToPrimary; // @phpstan-ignore-line
private readonly bool $convertToPrimary; // @phpstan-ignore-line
private array $currencies = [];
private array $currencyIds = [];
private Carbon $end;
@@ -52,7 +52,6 @@ class BudgetLimitEnrichment implements EnrichmentInterface
private readonly TransactionCurrency $primaryCurrency;
private Carbon $start;
private User $user;
private UserGroup $userGroup;
public function __construct()
{
@@ -85,17 +84,15 @@ class BudgetLimitEnrichment implements EnrichmentInterface
public function setUser(User $user): void
{
$this->user = $user;
$this->userGroup = $user->userGroup;
}
public function setUserGroup(UserGroup $userGroup): void
{
$this->userGroup = $userGroup;
}
private function appendCollectedData(): void
{
$this->collection = $this->collection->map(function (BudgetLimit $item) {
$this->collection = $this->collection->map(function (BudgetLimit $item): BudgetLimit {
$id = (int)$item->id;
$currencyId = (int)$item->transaction_currency_id;
if (0 === $currencyId) {
@@ -130,11 +127,11 @@ class BudgetLimitEnrichment implements EnrichmentInterface
$filteredExpenses = $repository->sumCollectedExpenses($filteredExpenses, $budgetLimit->start_date, $budgetLimit->end_date, $budgetLimit->transactionCurrency);
$this->expenses[$id] = array_values($filteredExpenses);
if (true === $this->convertToPrimary && $budgetLimit->transactionCurrency->id !== $this->primaryCurrency->id) {
if ($this->convertToPrimary && $budgetLimit->transactionCurrency->id !== $this->primaryCurrency->id) {
$pcFilteredExpenses = $repository->sumCollectedExpenses($expenses, $budgetLimit->start_date, $budgetLimit->end_date, $budgetLimit->transactionCurrency, true);
$this->pcExpenses[$id] = array_values($pcFilteredExpenses);
}
if (true === $this->convertToPrimary && $budgetLimit->transactionCurrency->id === $this->primaryCurrency->id) {
if ($this->convertToPrimary && $budgetLimit->transactionCurrency->id === $this->primaryCurrency->id) {
$this->pcExpenses[$id] = $this->expenses[$id] ?? [];
}
}
@@ -184,7 +181,7 @@ class BudgetLimitEnrichment implements EnrichmentInterface
private function filterToBudget(array $expenses, int $budget): array
{
$result = array_filter($expenses, fn (array $item) => (int)$item['budget_id'] === $budget);
$result = array_filter($expenses, fn (array $item): bool => (int)$item['budget_id'] === $budget);
Log::debug(sprintf('filterToBudget for budget #%d, from %d to %d items', $budget, count($expenses), count($result)));
return $result;
@@ -192,14 +189,14 @@ class BudgetLimitEnrichment implements EnrichmentInterface
private function stringifyIds(): void
{
$this->expenses = array_map(fn ($first) => array_map(function ($second) {
$this->expenses = array_map(fn ($first): array => array_map(function (array $second): array {
$second['currency_id'] = (string)($second['currency_id'] ?? 0);
return $second;
}, $first), $this->expenses);
$this->pcExpenses = array_map(fn ($first) => array_map(function ($second) {
$second['currency_id'] = (string)($second['currency_id'] ?? 0);
$this->pcExpenses = array_map(fn (array $first): array => array_map(function (array $second): array {
$second['currency_id'] ??= 0;
return $second;
}, $first), $this->expenses);

View File

@@ -94,7 +94,7 @@ class CategoryEnrichment implements EnrichmentInterface
private function appendCollectedData(): void
{
$this->collection = $this->collection->map(function (Category $item) {
$this->collection = $this->collection->map(function (Category $item): Category {
$id = (int)$item->id;
$meta = [
'notes' => $this->notes[$id] ?? null,

View File

@@ -55,8 +55,6 @@ class PiggyBankEnrichment implements EnrichmentInterface
private array $notes = [];
private array $objectGroups = [];
private readonly TransactionCurrency $primaryCurrency;
private User $user;
private UserGroup $userGroup;
private ?Carbon $date;
public function __construct()
@@ -89,18 +87,16 @@ class PiggyBankEnrichment implements EnrichmentInterface
public function setUser(User $user): void
{
$this->user = $user;
$this->setUserGroup($user->userGroup);
}
public function setUserGroup(UserGroup $userGroup): void
{
$this->userGroup = $userGroup;
}
private function appendCollectedData(): void
{
$this->collection = $this->collection->map(function (PiggyBank $item) {
$this->collection = $this->collection->map(function (PiggyBank $item): PiggyBank {
$id = (int)$item->id;
$currencyId = (int)$item->transaction_currency_id;
$currency = $this->currencies[$currencyId] ?? $this->primaryCurrency;

View File

@@ -46,8 +46,6 @@ class PiggyBankEventEnrichment implements EnrichmentInterface
private array $ids = [];
private array $journalIds = [];
private array $piggyBankIds = [];
private User $user;
private UserGroup $userGroup;
// private bool $convertToPrimary = false;
// private TransactionCurrency $primaryCurrency;
@@ -77,18 +75,16 @@ class PiggyBankEventEnrichment implements EnrichmentInterface
public function setUser(User $user): void
{
$this->user = $user;
$this->setUserGroup($user->userGroup);
}
public function setUserGroup(UserGroup $userGroup): void
{
$this->userGroup = $userGroup;
}
private function appendCollectedData(): void
{
$this->collection = $this->collection->map(function (PiggyBankEvent $item) {
$this->collection = $this->collection->map(function (PiggyBankEvent $item): PiggyBankEvent {
$id = (int)$item->id;
$piggyId = (int)$item->piggy_bank_id;
$journalId = (int)$item->transaction_journal_id;

View File

@@ -60,7 +60,7 @@ class RecurringEnrichment implements EnrichmentInterface
private Collection $collection;
// private array $transactionTypeIds = [];
// private array $transactionTypes = [];
private bool $convertToPrimary;
private readonly bool $convertToPrimary;
private array $currencies = [];
private array $currencyIds = [];
private array $destinationAccountIds = [];
@@ -171,7 +171,7 @@ class RecurringEnrichment implements EnrichmentInterface
private function appendCollectedData(): void
{
$this->collection = $this->collection->map(function (Recurrence $item) {
$this->collection = $this->collection->map(function (Recurrence $item): Recurrence {
$id = (int)$item->id;
$meta = [
'notes' => $this->notes[$id] ?? null,
@@ -341,7 +341,7 @@ class RecurringEnrichment implements EnrichmentInterface
/** @var RecurrenceRepetition $repetition */
foreach ($set as $repetition) {
$recurrence = $this->collection->filter(fn (Recurrence $item) => (int)$item->id === (int)$repetition->recurrence_id)->first();
$recurrence = $this->collection->filter(fn (Recurrence $item): bool => (int)$item->id === (int)$repetition->recurrence_id)->first();
$fromDate = clone ($recurrence->latest_date ?? $recurrence->first_date);
$id = (int)$repetition->recurrence_id;
$repId = (int)$repetition->id;
@@ -549,11 +549,11 @@ class RecurringEnrichment implements EnrichmentInterface
$pcAmount = null;
$pcForeignAmount = null;
// set the same amount in the primary currency, if both are the same anyway.
if (true === $this->convertToPrimary && $currencyId === (int)$this->primaryCurrency->id) {
if ($this->convertToPrimary && $currencyId === (int)$this->primaryCurrency->id) {
$pcAmount = $transaction['amount'];
}
// convert the amount to the primary currency, if it is not the same.
if (true === $this->convertToPrimary && $currencyId !== (int)$this->primaryCurrency->id) {
if ($this->convertToPrimary && $currencyId !== (int)$this->primaryCurrency->id) {
$pcAmount = $converter->convert($this->currencies[$currencyId], $this->primaryCurrency, today(), $transaction['amount']);
}
if (null !== $transaction['foreign_amount'] && null !== $transaction['foreign_currency_id']) {

View File

@@ -59,7 +59,6 @@ class SubscriptionEnrichment implements EnrichmentInterface
private ?Carbon $start = null;
private array $subscriptionIds = [];
private User $user;
private UserGroup $userGroup;
public function __construct()
{
@@ -84,7 +83,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
$notes = $this->notes;
$paidDates = $this->paidDates;
$payDates = $this->payDates;
$this->collection = $this->collection->map(function (Bill $item) use ($notes, $paidDates, $payDates) {
$this->collection = $this->collection->map(function (Bill $item) use ($notes, $paidDates, $payDates): Bill {
$id = (int)$item->id;
$currency = $item->transactionCurrency;
$nem = $this->getNextExpectedMatch($payDates[$id] ?? []);
@@ -165,12 +164,10 @@ class SubscriptionEnrichment implements EnrichmentInterface
public function setUser(User $user): void
{
$this->user = $user;
$this->userGroup = $user->userGroup;
}
public function setUserGroup(UserGroup $userGroup): void
{
$this->userGroup = $userGroup;
}
/**
@@ -178,7 +175,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
*/
protected function lastPaidDate(Bill $subscription, Collection $dates, Carbon $default): Carbon
{
$filtered = $dates->filter(fn (TransactionJournal $journal) => (int)$journal->bill_id === (int)$subscription->id);
$filtered = $dates->filter(fn (TransactionJournal $journal): bool => (int)$journal->bill_id === (int)$subscription->id);
Log::debug(sprintf('Filtered down from %d to %d entries for bill #%d.', $dates->count(), $filtered->count(), $subscription->id));
if (0 === $filtered->count()) {
return $default;
@@ -299,7 +296,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
// At this point the "next match" is exactly after the last time the bill was paid.
$result = [];
$filtered = $set->filter(fn (TransactionJournal $journal) => (int)$journal->bill_id === (int)$subscription->id);
$filtered = $set->filter(fn (TransactionJournal $journal): bool => (int)$journal->bill_id === (int)$subscription->id);
foreach ($filtered as $entry) {
$array = [
'transaction_group_id' => (string)$entry->transaction_group_id,
@@ -390,7 +387,7 @@ class SubscriptionEnrichment implements EnrichmentInterface
private function filterPaidDates(array $entries): array
{
return array_map(function (array $entry) {
return array_map(function (array $entry): array {
unset($entry['date_object']);
return $entry;

View File

@@ -54,8 +54,6 @@ class TransactionGroupEnrichment implements EnrichmentInterface
private array $notes = [];
private readonly TransactionCurrency $primaryCurrency;
private array $tags = []; // @phpstan-ignore-line
private User $user;
private UserGroup $userGroup; // @phpstan-ignore-line
public function __construct()
{
@@ -98,13 +96,10 @@ class TransactionGroupEnrichment implements EnrichmentInterface
public function setUser(User $user): void
{
$this->user = $user;
$this->userGroup = $user->userGroup;
}
public function setUserGroup(UserGroup $userGroup): void
{
$this->userGroup = $userGroup;
}
private function appendCollectedData(): void
@@ -116,12 +111,12 @@ class TransactionGroupEnrichment implements EnrichmentInterface
$attachmentCount = $this->attachmentCount;
$primaryCurrency = $this->primaryCurrency;
$this->collection = $this->collection->map(function (array $item) use ($primaryCurrency, $notes, $tags, $metaData, $locations, $attachmentCount) {
$this->collection = $this->collection->map(function (array $item) use ($primaryCurrency, $notes, $tags, $metaData, $locations, $attachmentCount): array {
foreach ($item['transactions'] as $index => $transaction) {
$journalId = (int)$transaction['transaction_journal_id'];
// attach notes if they exist:
$item['transactions'][$index]['notes'] = array_key_exists($journalId, $notes) ? $notes[$journalId] : null;
$item['transactions'][$index]['notes'] = $notes[$journalId] ?? null;
// attach tags if they exist:
$item['transactions'][$index]['tags'] = array_key_exists($journalId, $tags) ? $tags[$journalId] : [];

View File

@@ -47,8 +47,6 @@ class WebhookEnrichment implements EnrichmentInterface
private array $ids = []; // @phpstan-ignore-line
private array $responses = [];
private array $triggers = [];
private User $user;
private UserGroup $userGroup;
private array $webhookDeliveries = [];
private array $webhookResponses = [];
private array $webhookTriggers = [];
@@ -77,17 +75,15 @@ class WebhookEnrichment implements EnrichmentInterface
public function setUser(User $user): void
{
$this->user = $user;
}
public function setUserGroup(UserGroup $userGroup): void
{
$this->userGroup = $userGroup;
}
private function appendCollectedInfo(): void
{
$this->collection = $this->collection->map(function (Webhook $item) {
$this->collection = $this->collection->map(function (Webhook $item): Webhook {
$meta = [
'deliveries' => $this->webhookDeliveries[$item->id] ?? [],
'responses' => $this->webhookResponses[$item->id] ?? [],

View File

@@ -39,7 +39,7 @@ trait ReturnsIntegerIdTrait
protected function id(): Attribute
{
return Attribute::make(
get: static fn ($value) => (int)$value,
get: static fn ($value): int => (int)$value,
);
}
}

View File

@@ -37,14 +37,14 @@ trait ReturnsIntegerUserIdTrait
protected function userGroupId(): Attribute
{
return Attribute::make(
get: static fn ($value) => (int)$value,
get: static fn ($value): int => (int)$value,
);
}
protected function userId(): Attribute
{
return Attribute::make(
get: static fn ($value) => (int)$value,
get: static fn ($value): int => (int)$value,
);
}
}

View File

@@ -65,11 +65,7 @@ class ParseDateString
return false;
}
// no x'es
if (!str_contains($date, 'xx') && !str_contains($date, 'xxxx')) {
return false;
}
return true;
return !(!str_contains($date, 'xx') && !str_contains($date, 'xxxx'));
}
/**

View File

@@ -49,7 +49,7 @@ class BudgetReportGenerator
private Carbon $end;
private readonly NoBudgetRepositoryInterface $nbRepository;
private readonly OperationsRepositoryInterface $opsRepository;
private array $report;
private array $report = [];
private readonly BudgetRepositoryInterface $repository;
private Carbon $start;
@@ -62,7 +62,6 @@ class BudgetReportGenerator
$this->blRepository = app(BudgetLimitRepositoryInterface::class);
$this->opsRepository = app(OperationsRepositoryInterface::class);
$this->nbRepository = app(NoBudgetRepositoryInterface::class);
$this->report = [];
}
/**

View File

@@ -120,7 +120,7 @@ class TransactionSummarizer
}
// then process foreign amount, if it exists.
if (0 !== $foreignCurrencyId && true === $includeForeign) {
if (0 !== $foreignCurrencyId && $includeForeign) {
$amount = (string)($journal['foreign_amount'] ?? '0');
$array[$foreignCurrencyId] ??= [
'sum' => '0',

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Repositories\Recurring;
use Illuminate\Support\Facades\Log;
use Carbon\Carbon;
/**
@@ -110,30 +111,30 @@ trait CalculateRangeOccurrences
{
$return = [];
$attempts = 0;
app('log')->debug('Rep is weekly.');
Log::debug('Rep is weekly.');
// monday = 1
// sunday = 7
$dayOfWeek = (int)$moment;
app('log')->debug(sprintf('DoW in repetition is %d, in mutator is %d', $dayOfWeek, $start->dayOfWeekIso));
Log::debug(sprintf('DoW in repetition is %d, in mutator is %d', $dayOfWeek, $start->dayOfWeekIso));
if ($start->dayOfWeekIso > $dayOfWeek) {
// day has already passed this week, add one week:
$start->addWeek();
app('log')->debug(sprintf('Jump to next week, so mutator is now: %s', $start->format('Y-m-d')));
Log::debug(sprintf('Jump to next week, so mutator is now: %s', $start->format('Y-m-d')));
}
// today is wednesday (3), expected is friday (5): add two days.
// today is friday (5), expected is monday (1), subtract four days.
app('log')->debug(sprintf('Mutator is now: %s', $start->format('Y-m-d')));
Log::debug(sprintf('Mutator is now: %s', $start->format('Y-m-d')));
$dayDifference = $dayOfWeek - $start->dayOfWeekIso;
$start->addDays($dayDifference);
app('log')->debug(sprintf('Mutator is now: %s', $start->format('Y-m-d')));
Log::debug(sprintf('Mutator is now: %s', $start->format('Y-m-d')));
while ($start <= $end) {
if (0 === $attempts % $skipMod && $start->lte($start) && $end->gte($start)) {
app('log')->debug('Date is in range of start+end, add to set.');
Log::debug('Date is in range of start+end, add to set.');
$return[] = clone $start;
}
++$attempts;
$start->addWeek();
app('log')->debug(sprintf('Mutator is now (end of loop): %s', $start->format('Y-m-d')));
Log::debug(sprintf('Mutator is now (end of loop): %s', $start->format('Y-m-d')));
}
return $return;

View File

@@ -74,7 +74,7 @@ trait CalculateXOccurrencesSince
Log::debug(sprintf('%d is after %d, add a month. Mutator is now...', $mutator->day, $dayOfMonth));
// day has passed already, add a month.
$mutator->addMonth();
Log::debug(sprintf('%s', $mutator->toAtomString()));
Log::debug($mutator->toAtomString());
}
while ($total < $count) {

View File

@@ -24,6 +24,8 @@ declare(strict_types=1);
namespace FireflyIII\Support\Request;
use Illuminate\Support\Facades\Log;
/**
* Trait AppendsLocationData
*/
@@ -33,8 +35,8 @@ trait AppendsLocationData
{
$return['store_location'] = false;
if (true === $information['store_location']) {
$long = array_key_exists('longitude', $information) ? $information['longitude'] : null;
$lat = array_key_exists('latitude', $information) ? $information['latitude'] : null;
$long = $information['longitude'] ?? null;
$lat = $information['latitude'] ?? null;
if (null !== $long && null !== $lat && $this->validLongitude($long) && $this->validLatitude($lat)) {
$return['store_location'] = true;
$return['longitude'] = $information['longitude'];
@@ -49,11 +51,9 @@ trait AppendsLocationData
/**
* Abstract method stolen from "InteractsWithInput".
*
* @param null $key
* @param bool $default
*
* @return mixed
*
* @SuppressWarnings("PHPMD.BooleanArgumentFlag")
*/
abstract public function boolean($key = null, $default = false);
@@ -88,7 +88,7 @@ trait AppendsLocationData
*/
protected function appendLocationData(array $data, ?string $prefix): array
{
app('log')->debug(sprintf('Now in appendLocationData("%s")', $prefix), $data);
Log::debug(sprintf('Now in appendLocationData("%s")', $prefix), $data);
$data['store_location'] = false;
$data['update_location'] = false;
$data['remove_location'] = false;
@@ -105,7 +105,7 @@ trait AppendsLocationData
// for a POST (store), all fields must be present and not NULL.
if ($isValidPOST) {
app('log')->debug('Method is POST and all fields present and not NULL.');
Log::debug('Method is POST and all fields present and not NULL.');
$data['store_location'] = true;
$data['longitude'] = $this->convertString($longitudeKey);
$data['latitude'] = $this->convertString($latitudeKey);
@@ -114,18 +114,18 @@ trait AppendsLocationData
// for a PUT (api update) or POST update (UI)
if ($isValidPUT) {
app('log')->debug('Method is PUT and all fields present and not NULL.');
Log::debug('Method is PUT and all fields present and not NULL.');
$data['update_location'] = true;
$data['longitude'] = $this->convertString($longitudeKey);
$data['latitude'] = $this->convertString($latitudeKey);
$data['zoom_level'] = $this->convertString($zoomLevelKey);
}
if ($isValidEmptyPUT) {
app('log')->debug('Method is PUT and all fields present and NULL.');
Log::debug('Method is PUT and all fields present and NULL.');
$data['remove_location'] = true;
}
app('log')->debug(sprintf('Returning longitude: "%s", latitude: "%s", zoom level: "%s"', $data['longitude'], $data['latitude'], $data['zoom_level']));
app('log')->debug(
Log::debug(sprintf('Returning longitude: "%s", latitude: "%s", zoom level: "%s"', $data['longitude'], $data['latitude'], $data['zoom_level']));
Log::debug(
sprintf(
'Returning actions: store: %s, update: %s, delete: %s',
var_export($data['store_location'], true),
@@ -168,74 +168,74 @@ trait AppendsLocationData
$latitudeKey = $this->getLocationKey($prefix, 'latitude');
$zoomLevelKey = $this->getLocationKey($prefix, 'zoom_level');
$hasLocationKey = $this->getLocationKey($prefix, 'has_location');
app('log')->debug('Now in isValidPUT()');
Log::debug('Now in isValidPUT()');
// all fields must be set:
if (null !== $this->get($longitudeKey) && null !== $this->get($latitudeKey) && null !== $this->get($zoomLevelKey)) {
app('log')->debug('All fields present.');
if (!in_array(null, [$this->get($longitudeKey), $this->get($latitudeKey), $this->get($zoomLevelKey)], true)) {
Log::debug('All fields present.');
// must be PUT and API route:
if ('PUT' === $this->method() && $this->routeIs('api.v1.*')) {
app('log')->debug('Is API location');
Log::debug('Is API location');
return true;
}
// if POST and not API route, must also have "has_location"
// if is POST and route does not contain API, must also have "has_location" = true
if ('POST' === $this->method() && $this->routeIs('*.update') && !$this->routeIs('api.v1.*') && '' !== $hasLocationKey) {
app('log')->debug('Is POST + store route.');
Log::debug('Is POST + store route.');
$hasLocation = $this->boolean($hasLocationKey);
if (true === $hasLocation) {
app('log')->debug('Has form location data + has_location');
Log::debug('Has form location data + has_location');
return true;
}
app('log')->debug('Does not have form location');
Log::debug('Does not have form location');
return false;
}
app('log')->debug('Is not POST API or POST form');
Log::debug('Is not POST API or POST form');
return false;
}
app('log')->debug('Fields not present');
Log::debug('Fields not present');
return false;
}
private function isValidPost(?string $prefix): bool
{
app('log')->debug('Now in isValidPost()');
Log::debug('Now in isValidPost()');
$longitudeKey = $this->getLocationKey($prefix, 'longitude');
$latitudeKey = $this->getLocationKey($prefix, 'latitude');
$zoomLevelKey = $this->getLocationKey($prefix, 'zoom_level');
$hasLocationKey = $this->getLocationKey($prefix, 'has_location');
// fields must not be null:
if (null !== $this->get($longitudeKey) && null !== $this->get($latitudeKey) && null !== $this->get($zoomLevelKey)) {
app('log')->debug('All fields present');
if (!in_array(null, [$this->get($longitudeKey), $this->get($latitudeKey), $this->get($zoomLevelKey)], true)) {
Log::debug('All fields present');
// if is POST and route contains API, this is enough:
if ('POST' === $this->method() && $this->routeIs('api.v1.*')) {
app('log')->debug('Is API location');
Log::debug('Is API location');
return true;
}
// if is POST and route does not contain API, must also have "has_location" = true
if ('POST' === $this->method() && $this->routeIs('*.store') && !$this->routeIs('api.v1.*') && '' !== $hasLocationKey) {
app('log')->debug('Is POST + store route.');
Log::debug('Is POST + store route.');
$hasLocation = $this->boolean($hasLocationKey);
if (true === $hasLocation) {
app('log')->debug('Has form form location');
Log::debug('Has form form location');
return true;
}
app('log')->debug('Does not have form location');
Log::debug('Does not have form location');
return false;
}
app('log')->debug('Is not POST API or POST form');
Log::debug('Is not POST API or POST form');
return false;
}
app('log')->debug('Fields not present');
Log::debug('Fields not present');
return false;
}

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Request;
use Illuminate\Support\Facades\Log;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
@@ -38,14 +39,14 @@ trait ChecksLogin
*/
public function authorize(): bool
{
app('log')->debug(sprintf('Now in %s', __METHOD__));
Log::debug(sprintf('Now in %s', __METHOD__));
// Only allow logged-in users
$check = auth()->check();
if (!$check) {
return false;
}
if (!property_exists($this, 'acceptedRoles')) { // @phpstan-ignore-line
app('log')->debug('Request class has no acceptedRoles array');
Log::debug('Request class has no acceptedRoles array');
return true; // check for false already took place.
}
@@ -54,7 +55,7 @@ trait ChecksLogin
$user = auth()->user();
$userGroup = $this->getUserGroup();
if (null === $userGroup) {
app('log')->error('User has no valid user group submitted or otherwise.');
Log::error('User has no valid user group submitted or otherwise.');
return false;
}
@@ -80,24 +81,24 @@ trait ChecksLogin
{
/** @var User $user */
$user = auth()->user();
app('log')->debug('Now in getUserGroup()');
Log::debug('Now in getUserGroup()');
/** @var null|UserGroup $userGroup */
$userGroup = $this->route()?->parameter('userGroup');
if (null === $userGroup) {
app('log')->debug('Request class has no userGroup parameter, but perhaps there is a parameter.');
Log::debug('Request class has no userGroup parameter, but perhaps there is a parameter.');
$userGroupId = (int)$this->get('user_group_id');
if (0 === $userGroupId) {
app('log')->debug(sprintf('Request class has no user_group_id parameter, grab default from user (group #%d).', $user->user_group_id));
Log::debug(sprintf('Request class has no user_group_id parameter, grab default from user (group #%d).', $user->user_group_id));
$userGroupId = (int)$user->user_group_id;
}
$userGroup = UserGroup::find($userGroupId);
if (null === $userGroup) {
app('log')->error(sprintf('Request class has user_group_id (#%d), but group does not exist.', $userGroupId));
Log::error(sprintf('Request class has user_group_id (#%d), but group does not exist.', $userGroupId));
return null;
}
app('log')->debug('Request class has valid user_group_id.');
Log::debug('Request class has valid user_group_id.');
}
return $userGroup;

View File

@@ -274,11 +274,7 @@ trait ConvertsDataTypes
if ('y' === $value) {
return true;
}
if ('1' === $value) {
return true;
}
return false;
return '1' === $value;
}
protected function convertDateTime(?string $string): ?Carbon

View File

@@ -25,10 +25,10 @@ declare(strict_types=1);
namespace FireflyIII\Support\Request;
use Illuminate\Contracts\Validation\Validator;
use FireflyIII\Enums\WebhookTrigger;
use FireflyIII\Models\Webhook;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\Validator;
trait ValidatesWebhooks
{

View File

@@ -36,30 +36,20 @@ use function Safe\json_encode;
*/
class AccountSearch implements GenericSearchInterface
{
/** @var string */
public const string SEARCH_ALL = 'all';
/** @var string */
public const string SEARCH_IBAN = 'iban';
/** @var string */
public const string SEARCH_ID = 'id';
/** @var string */
public const string SEARCH_NAME = 'name';
/** @var string */
public const string SEARCH_NUMBER = 'number';
private string $field;
private string $query;
private array $types;
private array $types = [];
private User $user;
public function __construct()
{
$this->types = [];
}
public function search(): Collection
{
$searchQuery = $this->user->accounts()

View File

@@ -66,19 +66,19 @@ class OperatorQuerySearch implements SearchInterface
private readonly CategoryRepositoryInterface $categoryRepository;
private GroupCollectorInterface $collector;
private readonly CurrencyRepositoryInterface $currencyRepository;
private array $excludeTags;
private array $includeAnyTags;
private array $excludeTags = [];
private array $includeAnyTags = [];
// added to fix #8632
private array $includeTags;
private array $invalidOperators;
private int $limit;
private array $includeTags = [];
private array $invalidOperators = [];
private int $limit = 25;
private readonly Collection $operators;
private int $page;
private array $prohibitedWords;
private int $page = 1;
private array $prohibitedWords = [];
private readonly float $startTime;
private readonly TagRepositoryInterface $tagRepository;
private readonly array $validOperators;
private array $words;
private array $words = [];
/**
* OperatorQuerySearch constructor.
@@ -87,14 +87,6 @@ class OperatorQuerySearch implements SearchInterface
{
Log::debug('Constructed OperatorQuerySearch');
$this->operators = new Collection();
$this->page = 1;
$this->words = [];
$this->excludeTags = [];
$this->includeAnyTags = [];
$this->includeTags = [];
$this->prohibitedWords = [];
$this->invalidOperators = [];
$this->limit = 25;
$this->validOperators = array_keys(config('search.operators'));
$this->startTime = microtime(true);
$this->accountRepository = app(AccountRepositoryInterface::class);
@@ -293,15 +285,13 @@ class OperatorQuerySearch implements SearchInterface
// must be valid operator:
$inArray = in_array($operator, $this->validOperators, true);
if ($inArray) {
if ($this->updateCollector($operator, $value, $prohibited)) {
$this->operators->push([
'type' => self::getRootOperator($operator),
'value' => $value,
'prohibited' => $prohibited,
]);
Log::debug(sprintf('Added operator type "%s"', $operator));
}
if ($inArray && $this->updateCollector($operator, $value, $prohibited)) {
$this->operators->push([
'type' => self::getRootOperator($operator),
'value' => $value,
'prohibited' => $prohibited,
]);
Log::debug(sprintf('Added operator type "%s"', $operator));
}
if (!$inArray) {
Log::debug(sprintf('Added INVALID operator type "%s"', $operator));
@@ -495,14 +485,14 @@ class OperatorQuerySearch implements SearchInterface
return;
}
if (0 === $accounts->count() && true === $prohibited) {
if (0 === $accounts->count() && $prohibited) {
Log::debug('Found zero accounts, but the search is negated, so effectively we ignore the search parameter.');
return;
}
Log::debug(sprintf('Found %d accounts, will filter.', $accounts->count()));
$filtered = $accounts->filter(
static fn (Account $account) => $stringMethod(strtolower($account->name), strtolower($value))
static fn (Account $account): bool => $stringMethod(strtolower($account->name), strtolower($value))
);
if (0 === $filtered->count()) {
@@ -530,7 +520,7 @@ class OperatorQuerySearch implements SearchInterface
// search direction (default): for source accounts
$searchTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::REVENUE->value];
$collectorMethod = 'setSourceAccounts';
if (true === $prohibited) {
if ($prohibited) {
$collectorMethod = 'excludeSourceAccounts';
}
@@ -539,7 +529,7 @@ class OperatorQuerySearch implements SearchInterface
// destination can be
$searchTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::EXPENSE->value];
$collectorMethod = 'setDestinationAccounts';
if (true === $prohibited) {
if ($prohibited) {
$collectorMethod = 'excludeDestinationAccounts';
}
}
@@ -548,7 +538,7 @@ class OperatorQuerySearch implements SearchInterface
if (SearchDirection::BOTH === $searchDirection) {
$searchTypes = [AccountTypeEnum::ASSET->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::EXPENSE->value, AccountTypeEnum::REVENUE->value];
$collectorMethod = 'setAccounts';
if (true === $prohibited) {
if ($prohibited) {
$collectorMethod = 'excludeAccounts';
}
}
@@ -580,7 +570,7 @@ class OperatorQuerySearch implements SearchInterface
// if found, do filter
Log::debug(sprintf('Found %d accounts, will filter.', $accounts->count()));
$filtered = $accounts->filter(
static function (Account $account) use ($value, $stringMethod) {
static function (Account $account) use ($value, $stringMethod): bool {
// either IBAN or account number
$ibanMatch = $stringMethod(strtolower((string)$account->iban), strtolower($value));
$accountNrMatch = false;

View File

@@ -54,15 +54,15 @@ class GdbotsQueryParser implements QueryParserInterface
try {
$result = $this->parser->parse($query);
$nodes = array_map(
fn (GdbotsNode\Node $node) => $this->convertNode($node),
$this->convertNode(...),
$result->getNodes()
);
return new NodeGroup($nodes);
} catch (LogicException|TypeError $e) {
fwrite(STDERR, "Setting up GdbotsQueryParserTest\n");
app('log')->error($e->getMessage());
app('log')->error(sprintf('Could not parse search: "%s".', $query));
Log::error($e->getMessage());
Log::error(sprintf('Could not parse search: "%s".', $query));
throw new FireflyException(sprintf('Invalid search value "%s". See the logs.', e($query)), 0, $e);
}
@@ -87,7 +87,7 @@ class GdbotsQueryParser implements QueryParserInterface
return new NodeGroup(
array_map(
fn (GdbotsNode\Node $subNode) => $this->convertNode($subNode),
$this->convertNode(...),
$node->getNodes()
)
);

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Support;
use Deprecated;
use Carbon\Carbon;
use Exception;
use FireflyIII\Exceptions\FireflyException;
@@ -78,7 +79,7 @@ class Steam
$currency = $currencies[$account->id];
// second array
$accountSums = array_filter($arrayOfSums, fn ($entry) => $entry['account_id'] === $account->id);
$accountSums = array_filter($arrayOfSums, fn (array $entry): bool => $entry['account_id'] === $account->id);
if (0 === count($accountSums)) {
$result[$account->id] = $return;
@@ -289,21 +290,21 @@ class Steam
return str_replace($search, '', $string);
}
/**
* @deprecated
* By default this method returns "smaller than or equal to", so be careful with END OF DAY.
* If you need end of day balance, use "inclusive = false".
*
* Returns the balance of an account at exact moment given. Array with at least one value.
* Always returns:
* "balance": balance in the account's currency OR user's primary currency if the account has no currency
* "EUR": balance in EUR (or whatever currencies the account has balance in)
*
* If the user has $convertToPrimary:
* "balance": balance in the account's currency OR user's primary currency if the account has no currency
* --> "pc_balance": balance in the user's primary currency, with all amounts converted to the primary currency.
* "EUR": balance in EUR (or whatever currencies the account has balance in)
*/
#[Deprecated(message: <<<'TXT'
By default this method returns "smaller than or equal to", so be careful with END OF DAY.
If you need end of day balance, use "inclusive = false".
Returns the balance of an account at exact moment given. Array with at least one value.
Always returns:
"balance": balance in the account's currency OR user's primary currency if the account has no currency
"EUR": balance in EUR (or whatever currencies the account has balance in)
If the user has $convertToPrimary:
"balance": balance in the account's currency OR user's primary currency if the account has no currency
--> "pc_balance": balance in the user's primary currency, with all amounts converted to the primary currency.
"EUR": balance in EUR (or whatever currencies the account has balance in)
TXT)]
public function finalAccountBalance(Account $account, Carbon $date, ?TransactionCurrency $primary = null, ?bool $convertToPrimary = null, bool $inclusive = true): array
{

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\System;
use Illuminate\Support\Facades\Log;
use FireflyIII\Exceptions\FireflyException;
use Ramsey\Uuid\Uuid;
@@ -37,7 +38,7 @@ trait GeneratesInstallationId
try {
$config = app('fireflyconfig')->get('installation_id');
} catch (FireflyException) {
app('log')->info('Could not create or generate installation ID. Do not continue.');
Log::info('Could not create or generate installation ID. Do not continue.');
return;
}
@@ -50,7 +51,7 @@ trait GeneratesInstallationId
if (null === $config) {
$uuid4 = Uuid::uuid4();
$uniqueId = (string)$uuid4;
app('log')->info(sprintf('Created Firefly III installation ID %s', $uniqueId));
Log::info(sprintf('Created Firefly III installation ID %s', $uniqueId));
app('fireflyconfig')->set('installation_id', $uniqueId);
}
}

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\System;
use Illuminate\Support\Facades\Log;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Support\Facades\FireflyConfig;
use Illuminate\Contracts\Encryption\DecryptException;
@@ -69,15 +70,11 @@ class OAuthKeys
$privateKey = (string)FireflyConfig::get(self::PRIVATE_KEY)?->data;
$publicKey = (string)FireflyConfig::get(self::PUBLIC_KEY)?->data;
} catch (ContainerExceptionInterface|FireflyException|NotFoundExceptionInterface $e) {
app('log')->error(sprintf('Could not validate keysInDatabase(): %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());
Log::error(sprintf('Could not validate keysInDatabase(): %s', $e->getMessage()));
Log::error($e->getTraceAsString());
}
}
if ('' !== $privateKey && '' !== $publicKey) {
return true;
}
return false;
return '' !== $privateKey && '' !== $publicKey;
}
/**
@@ -95,8 +92,8 @@ class OAuthKeys
$privateContent = Crypt::decrypt($privateKey);
$publicContent = Crypt::decrypt($publicKey);
} catch (DecryptException $e) {
app('log')->error('Could not decrypt pub/private keypair.');
app('log')->error($e->getMessage());
Log::error('Could not decrypt pub/private keypair.');
Log::error($e->getMessage());
// delete config vars from DB:
FireflyConfig::delete(self::PRIVATE_KEY);

View File

@@ -104,7 +104,7 @@ class General extends AbstractExtension
{
return new TwigFunction(
'activeRoutePartialObjectType',
static function ($context): string {
static function (array $context): string {
[, $route, $objectType] = func_get_args();
$activeObjectType = $context['objectType'] ?? false;
@@ -292,11 +292,7 @@ class General extends AbstractExtension
'hasRole',
static function (string $role): bool {
$repository = app(UserRepositoryInterface::class);
if ($repository->hasRole(auth()->user(), $role)) {
return true;
}
return false;
return $repository->hasRole(auth()->user(), $role);
}
);
}

View File

@@ -37,7 +37,7 @@ class Rule extends AbstractExtension
{
return new TwigFunction(
'allRuleActions',
static function () {
static function (): array {
// array of valid values for actions
$ruleActions = array_keys(Config::get('firefly.rule-actions'));
$possibleActions = [];
@@ -56,7 +56,7 @@ class Rule extends AbstractExtension
{
return new TwigFunction(
'allJournalTriggers',
static fn () => [
static fn (): array => [
'store-journal' => (string)trans('firefly.rule_trigger_store_journal'),
'update-journal' => (string)trans('firefly.rule_trigger_update_journal'),
'manual-activation' => (string)trans('firefly.rule_trigger_manual'),
@@ -68,7 +68,7 @@ class Rule extends AbstractExtension
{
return new TwigFunction(
'allRuleTriggers',
static function () {
static function (): array {
$ruleTriggers = array_keys(config('search.operators'));
$possibleTriggers = [];
foreach ($ruleTriggers as $key) {

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Twig;
use Carbon\CarbonInterface;
use Carbon\Carbon;
use FireflyIII\Enums\AccountTypeEnum;
use FireflyIII\Enums\TransactionTypeEnum;
@@ -80,7 +81,7 @@ class TransactionGroupTwig extends AbstractExtension
{
return new TwigFunction(
'journalGetMetaDate',
static function (int $journalId, string $metaField) {
static function (int $journalId, string $metaField): CarbonInterface|Carbon {
/** @var null|TransactionJournalMeta $entry */
$entry = DB::table('journal_meta')
->where('name', $metaField)
@@ -122,7 +123,7 @@ class TransactionGroupTwig extends AbstractExtension
{
return new TwigFunction(
'journalHasMeta',
static function (int $journalId, string $metaField) {
static function (int $journalId, string $metaField): bool {
$count = DB::table('journal_meta')
->where('name', $metaField)
->where('transaction_journal_id', $journalId)

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Support\Twig;
use Illuminate\Contracts\Translation\Translator;
use Override;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
@@ -39,7 +40,7 @@ class Translation extends AbstractExtension
return [
new TwigFilter(
'_',
static fn ($name) => (string)trans(sprintf('firefly.%s', $name)),
static fn (string $name) => (string)trans(sprintf('firefly.%s', $name)),
['is_safe' => ['html']]
),
];
@@ -58,7 +59,7 @@ class Translation extends AbstractExtension
{
return new TwigFunction(
'journalLinkTranslation',
static function (string $direction, string $original) {
static function (string $direction, string $original): string|Translator|array {
$key = sprintf('firefly.%s_%s', $original, $direction);
$translation = trans($key);
if ($key === $translation) {
@@ -75,7 +76,7 @@ class Translation extends AbstractExtension
{
return new TwigFunction(
'__',
static function (string $key) {
static function (string $key): string|Translator|array {
$translation = trans($key);
if ($key === $translation) {
return $key;