Warn about expensive code in test environment.

This commit is contained in:
James Cole
2019-06-22 10:25:57 +02:00
parent 0f70cc5780
commit 2710a30a7c
15 changed files with 328 additions and 127 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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)