Various code cleanup.

This commit is contained in:
James Cole
2018-07-27 05:03:37 +02:00
parent 0312ba8ad7
commit e3e0e12fef
43 changed files with 167 additions and 145 deletions

View File

@@ -83,7 +83,8 @@ class AmountFormat extends Twig_Extension
{
return new Twig_SimpleFunction(
'formatAmountByAccount',
function (AccountModel $account, string $amount, bool $coloured = true): string {
function (AccountModel $account, string $amount, bool $coloured = null): string {
$coloured = $coloured ?? true;
/** @var AccountRepositoryInterface $accountRepos */
$accountRepos = app(AccountRepositoryInterface::class);
/** @var CurrencyRepositoryInterface $currencyRepos */
@@ -113,7 +114,9 @@ class AmountFormat extends Twig_Extension
{
return new Twig_SimpleFunction(
'formatAmountByCurrency',
function (TransactionCurrency $currency, string $amount, bool $coloured = true): string {
function (TransactionCurrency $currency, string $amount, bool $coloured = null): string {
$coloured = $coloured ?? true;
return app('amount')->formatAnything($currency, $amount, $coloured);
},
['is_safe' => ['html']]
@@ -129,7 +132,9 @@ class AmountFormat extends Twig_Extension
{
return new Twig_SimpleFunction(
'formatAmountBySymbol',
function (string $amount, string $symbol, int $decimalPlaces = 2, bool $coloured = true): string {
function (string $amount, string $symbol, int $decimalPlaces = null, bool $coloured = null): string {
$decimalPlaces = $decimalPlaces ?? 2;
$coloured = $coloured ?? true;
$currency = new TransactionCurrency;
$currency->symbol = $symbol;
$currency->decimal_places = $decimalPlaces;

View File

@@ -136,12 +136,12 @@ class Transaction extends Twig_Extension
}
// transaction has a budget
if (null !== $transaction->transaction_budget_id && $txt === '') {
if (null !== $transaction->transaction_budget_id && '' === $txt) {
$name = app('steam')->tryDecrypt($transaction->transaction_budget_name);
$txt = sprintf('<a href="%s" title="%s">%s</a>', route('budgets.show', [$transaction->transaction_budget_id]), $name, $name);
}
if ($txt === '') {
if ('' === $txt) {
// see if the transaction has a budget:
$budgets = $transaction->budgets()->get();
if (0 === $budgets->count()) {
@@ -174,12 +174,12 @@ class Transaction extends Twig_Extension
}
// transaction has a category:
if (null !== $transaction->transaction_category_id && $txt === '') {
if (null !== $transaction->transaction_category_id && '' === $txt) {
$name = app('steam')->tryDecrypt($transaction->transaction_category_name);
$txt = sprintf('<a href="%s" title="%s">%s</a>', route('categories.show', [$transaction->transaction_category_id]), $name, $name);
}
if ($txt === '') {
if ('' === $txt) {
// see if the transaction has a category:
$categories = $transaction->categories()->get();
if (0 === $categories->count()) {
@@ -229,14 +229,14 @@ class Transaction extends Twig_Extension
$type = $transaction->account_type;
// name is present in object, use that one:
if (bccomp($transaction->transaction_amount, '0') === -1 && null !== $transaction->opposing_account_id) {
if (null !== $transaction->opposing_account_id && bccomp($transaction->transaction_amount, '0') === -1) {
$name = $transaction->opposing_account_name;
$transactionId = (int)$transaction->opposing_account_id;
$type = $transaction->opposing_account_type;
}
// Find the opposing account and use that one:
if (bccomp($transaction->transaction_amount, '0') === -1 && null === $transaction->opposing_account_id) {
if (null === $transaction->opposing_account_id && bccomp($transaction->transaction_amount, '0') === -1) {
// if the amount is negative, find the opposing account and use that one:
$journalId = $transaction->journal_id;
/** @var TransactionModel $other */
@@ -259,7 +259,7 @@ class Transaction extends Twig_Extension
}
if (AccountType::CASH === $type) {
$txt = '<span class="text-success">(' . (string)trans('firefly.cash') . ')</span>';
$txt = '<span class="text-success">(' . trans('firefly.cash') . ')</span>';
return $txt;
}
@@ -285,7 +285,7 @@ class Transaction extends Twig_Extension
)
);
}
if ($transaction->attachmentCount === null) {
if (null === $transaction->attachmentCount) {
$journalId = (int)$transaction->journal_id;
$count = Attachment::whereNull('deleted_at')
->where('attachable_type', TransactionJournal::class)
@@ -355,11 +355,11 @@ class Transaction extends Twig_Extension
public function isSplit(TransactionModel $transaction): string
{
$res = '';
if ($transaction->is_split === true) {
if (true === $transaction->is_split) {
$res = '<i class="fa fa-fw fa-share-alt" aria-hidden="true"></i>';
}
if ($transaction->is_split === null) {
if (null === $transaction->is_split) {
$journalId = (int)$transaction->journal_id;
$count = TransactionModel::where('transaction_journal_id', $journalId)->whereNull('deleted_at')->count();
if ($count > 2) {
@@ -387,13 +387,13 @@ class Transaction extends Twig_Extension
$type = $transaction->account_type;
// name is present in object, use that one:
if (1 === bccomp($transaction->transaction_amount, '0') && null !== $transaction->opposing_account_id) {
if (null !== $transaction->opposing_account_id && 1 === bccomp($transaction->transaction_amount, '0')) {
$name = $transaction->opposing_account_name;
$transactionId = (int)$transaction->opposing_account_id;
$type = $transaction->opposing_account_type;
}
// Find the opposing account and use that one:
if (1 === bccomp($transaction->transaction_amount, '0') && null === $transaction->opposing_account_id) {
if (null === $transaction->opposing_account_id && 1 === bccomp($transaction->transaction_amount, '0')) {
$journalId = $transaction->journal_id;
/** @var TransactionModel $other */
$other = TransactionModel::where('transaction_journal_id', $journalId)->where('transactions.id', '!=', $transaction->id)
@@ -410,7 +410,7 @@ class Transaction extends Twig_Extension
}
if (AccountType::CASH === $type) {
$txt = '<span class="text-success">(' . (string)trans('firefly.cash') . ')</span>';
$txt = '<span class="text-success">(' . trans('firefly.cash') . ')</span>';
return $txt;
}

View File

@@ -83,7 +83,7 @@ class TransactionJournal extends Twig_Extension
if (null === $result) {
return false;
}
if (\strlen((string)$result) === 0) {
if ('' === (string)$result) {
return false;
}

View File

@@ -174,7 +174,7 @@ class General extends Twig_Extension
/**
* @return Twig_SimpleFunction
*/
protected function formatDate()
protected function formatDate(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'formatDate',
@@ -330,7 +330,7 @@ class General extends Twig_Extension
/**
* @return Twig_SimpleFunction
*/
protected function phpdate()
protected function phpdate(): Twig_SimpleFunction
{
return new Twig_SimpleFunction(
'phpdate',

View File

@@ -45,7 +45,7 @@ class Rule extends Twig_Extension
foreach ($ruleActions as $key) {
$possibleActions[$key] = (string)trans('firefly.rule_action_' . $key . '_choice');
}
unset($key, $ruleActions);
unset($ruleActions);
asort($possibleActions);
return $possibleActions;
@@ -84,7 +84,7 @@ class Rule extends Twig_Extension
$possibleTriggers[$key] = (string)trans('firefly.rule_trigger_' . $key . '_choice');
}
}
unset($key, $ruleTriggers);
unset($ruleTriggers);
asort($possibleTriggers);
return $possibleTriggers;