mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-22 20:16:22 +00:00
Warn about expensive code in test environment.
This commit is contained in:
@@ -26,6 +26,7 @@ use FireflyIII\Models\Account as AccountModel;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Log;
|
||||
use Twig_Extension;
|
||||
use Twig_SimpleFilter;
|
||||
use Twig_SimpleFunction;
|
||||
@@ -83,7 +84,12 @@ class AmountFormat extends Twig_Extension
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'formatAmountByAccount',
|
||||
function (AccountModel $account, string $amount, bool $coloured = null): string {
|
||||
static function (AccountModel $account, string $amount, bool $coloured = null): string {
|
||||
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||
}
|
||||
|
||||
$coloured = $coloured ?? true;
|
||||
/** @var AccountRepositoryInterface $accountRepos */
|
||||
$accountRepos = app(AccountRepositoryInterface::class);
|
||||
|
@@ -27,6 +27,7 @@ use FireflyIII\Models\Account;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use League\CommonMark\CommonMarkConverter;
|
||||
use Log;
|
||||
use Route;
|
||||
use Twig_Extension;
|
||||
use Twig_SimpleFilter;
|
||||
@@ -145,13 +146,17 @@ class General extends Twig_Extension
|
||||
{
|
||||
return new Twig_SimpleFilter(
|
||||
'balance',
|
||||
function (?Account $account): string {
|
||||
static function (?Account $account): string {
|
||||
if (null === $account) {
|
||||
return 'NULL';
|
||||
}
|
||||
/** @var Carbon $date */
|
||||
$date = session('end', Carbon::now()->endOfMonth());
|
||||
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||
}
|
||||
|
||||
return app('steam')->balance($account, $date);
|
||||
}
|
||||
);
|
||||
@@ -207,6 +212,10 @@ class General extends Twig_Extension
|
||||
return new Twig_SimpleFunction(
|
||||
'accountGetMetaField',
|
||||
static function (Account $account, string $field): string {
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||
}
|
||||
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
$result = $repository->getMetaValue($account, $field);
|
||||
@@ -228,7 +237,10 @@ class General extends Twig_Extension
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'hasRole',
|
||||
function (string $role): bool {
|
||||
static function (string $role): bool {
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||
}
|
||||
$repository = app(UserRepositoryInterface::class);
|
||||
if ($repository->hasRole(auth()->user(), $role)) {
|
||||
return true;
|
||||
|
@@ -38,7 +38,7 @@ class Rule extends Twig_Extension
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'allRuleActions',
|
||||
function () {
|
||||
static function () {
|
||||
// array of valid values for actions
|
||||
$ruleActions = array_keys(Config::get('firefly.rule-actions'));
|
||||
$possibleActions = [];
|
||||
@@ -60,7 +60,7 @@ class Rule extends Twig_Extension
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'allJournalTriggers',
|
||||
function () {
|
||||
static function () {
|
||||
return [
|
||||
'store-journal' => (string)trans('firefly.rule_trigger_store_journal'),
|
||||
'update-journal' => (string)trans('firefly.rule_trigger_update_journal'),
|
||||
@@ -76,7 +76,7 @@ class Rule extends Twig_Extension
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'allRuleTriggers',
|
||||
function () {
|
||||
static function () {
|
||||
$ruleTriggers = array_keys(Config::get('firefly.rule-triggers'));
|
||||
$possibleTriggers = [];
|
||||
foreach ($ruleTriggers as $key) {
|
||||
|
@@ -26,6 +26,7 @@ namespace FireflyIII\Support\Twig\Extension;
|
||||
use Carbon\Carbon;
|
||||
use DB;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use Log;
|
||||
use Twig_Extension;
|
||||
use Twig_SimpleFunction;
|
||||
|
||||
@@ -94,7 +95,9 @@ class TransactionGroupTwig extends Twig_Extension
|
||||
return new Twig_SimpleFunction(
|
||||
'journalGetMetaDate',
|
||||
static function (int $journalId, string $metaField) {
|
||||
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||
}
|
||||
$entry = DB::table('journal_meta')
|
||||
->where('name', $metaField)
|
||||
->where('transaction_journal_id', $journalId)
|
||||
@@ -117,7 +120,9 @@ class TransactionGroupTwig extends Twig_Extension
|
||||
return new Twig_SimpleFunction(
|
||||
'journalGetMetaField',
|
||||
static function (int $journalId, string $metaField) {
|
||||
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||
}
|
||||
$entry = DB::table('journal_meta')
|
||||
->where('name', $metaField)
|
||||
->where('transaction_journal_id', $journalId)
|
||||
@@ -140,6 +145,9 @@ class TransactionGroupTwig extends Twig_Extension
|
||||
return new Twig_SimpleFunction(
|
||||
'journalHasMeta',
|
||||
static function (int $journalId, string $metaField) {
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||
}
|
||||
$count = DB::table('journal_meta')
|
||||
->where('name', $metaField)
|
||||
->where('transaction_journal_id', $journalId)
|
||||
|
Reference in New Issue
Block a user