<commit_before><?php

namespace FireflyIII\Support\Twig;


use App;
use FireflyIII\Models\TransactionJournal;
use Twig_Extension;
use Twig_SimpleFilter;
use Twig_SimpleFunction;

/**
 * Class Journal
 *
 * @package FireflyIII\Support\Twig
 */
class Journal extends Twig_Extension
{

    /**
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
     * @return array
     */
    public function getFilters()
    {
        $filters = [];

        $filters[] = new Twig_SimpleFilter(
            'typeIcon', function (TransactionJournal $journal) {
            $type = $journal->transactionType->type;

            switch ($type) {
                case 'Withdrawal':
                    return '<span class="glyphicon glyphicon-arrow-left" title="' . trans('firefly.withdrawal') . '"></span>';
                    break;
                case 'Deposit':
                    return '<span class="glyphicon glyphicon-arrow-right" title="' . trans('firefly.deposit') . '"></span>';
                    break;
                case 'Transfer':
                    return '<i class="fa fa-fw fa-exchange" title="' . trans('firefly.transfer') . '"></i>';
                    break;
                case 'Opening balance':
                    return '<span class="glyphicon glyphicon-ban-circle" title="' . trans('firefly.openingBalance') . '"></span>';
                    break;
                default:
                    return '';
                    break;
            }


        }, ['is_safe' => ['html']]
        );

        return $filters;
    }

    /**
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
     *
     * @return array
     */
    public function getFunctions()
    {
        $functions = [];

        $functions[] = new Twig_SimpleFunction(
            'invalidJournal', function (TransactionJournal $journal) {
            if (!isset($journal->transactions[1]) || !isset($journal->transactions[0])) {
                return true;
            }

            return false;
        }
        );

        $functions[] = new Twig_SimpleFunction(
            'relevantTags', function (TransactionJournal $journal) {
            if ($journal->tags->count() == 0) {
                return App::make('amount')->formatJournal($journal);
            }


            foreach ($journal->tags as $tag) {
                if ($tag->tagMode == 'balancingAct') {
                    // return tag formatted for a "balancing act", even if other
                    // tags are present.
                    $amount = App::make('amount')->formatJournal($journal, false);
                    return '<a href="' . route('tags.show', $tag->id) . '" class="label label-success" title="' . $amount
                           . '"><i class="fa fa-fw fa-refresh"></i> ' . $tag->tag . '</a>';
                }

                /*
                 * AdvancePayment with a deposit will show the tag instead of the amount:
                 */
                if ($tag->tagMode == 'advancePayment' && $journal->transactionType->type == 'Deposit') {
                    $amount = App::make('amount')->formatJournal($journal, false);
                    return '<a href="' . route('tags.show', $tag->id) . '" class="label label-success" title="' . $amount
                           . '"><i class="fa fa-fw fa-refresh"></i> ' . $tag->tag . '</a>';
                }
                /*
                 * AdvancePayment with a withdrawal will show the amount with a link to
                 * the tag. The TransactionJournal should properly calculate the amount.
                 */
                if ($tag->tagMode == 'advancePayment' && $journal->transactionType->type == 'Withdrawal') {
                    $amount = App::make('amount')->formatJournal($journal);
                    return '<a href="' . route('tags.show', $tag->id) . '">' . $amount . '</a>';
                }


                if ($tag->tagMode == 'nothing') {
                    // return the amount:
                    return App::make('amount')->formatJournal($journal);
                }
            }


            return 'TODO: ' . $journal->amount;
        }
        );

        return $functions;
    }

    /**
     * Returns the name of the extension.
     *
     * @return string The extension name
     */
    public function getName()<commit_msg>Show correct icon. [skip ci]<commit_after><?php

namespace FireflyIII\Support\Twig;


use App;
use FireflyIII\Models\TransactionJournal;
use Twig_Extension;
use Twig_SimpleFilter;
use Twig_SimpleFunction;

/**
 * Class Journal
 *
 * @package FireflyIII\Support\Twig
 */
class Journal extends Twig_Extension
{

    /**
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
     * @return array
     */
    public function getFilters()
    {
        $filters = [];

        $filters[] = new Twig_SimpleFilter(
            'typeIcon', function (TransactionJournal $journal) {
            $type = $journal->transactionType->type;

            switch ($type) {
                case 'Withdrawal':
                    return '<span class="glyphicon glyphicon-arrow-left" title="' . trans('firefly.withdrawal') . '"></span>';
                    break;
                case 'Deposit':
                    return '<span class="glyphicon glyphicon-arrow-right" title="' . trans('firefly.deposit') . '"></span>';
                    break;
                case 'Transfer':
                    return '<i class="fa fa-fw fa-exchange" title="' . trans('firefly.transfer') . '"></i>';
                    break;
                case 'Opening balance':
                    return '<span class="glyphicon glyphicon-ban-circle" title="' . trans('firefly.openingBalance') . '"></span>';
                    break;
                default:
                    return '';
                    break;
            }


        }, ['is_safe' => ['html']]
        );

        return $filters;
    }

    /**
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
     *
     * @return array
     */
    public function getFunctions()
    {
        $functions = [];

        $functions[] = new Twig_SimpleFunction(
            'invalidJournal', function (TransactionJournal $journal) {
            if (!isset($journal->transactions[1]) || !isset($journal->transactions[0])) {
                return true;
            }

            return false;
        }
        );

        $functions[] = new Twig_SimpleFunction(
            'relevantTags', function (TransactionJournal $journal) {
            if ($journal->tags->count() == 0) {
                return App::make('amount')->formatJournal($journal);
            }


            foreach ($journal->tags as $tag) {
                if ($tag->tagMode == 'balancingAct') {
                    // return tag formatted for a "balancing act", even if other
                    // tags are present.
                    $amount = App::make('amount')->formatJournal($journal, false);
                    return '<a href="' . route('tags.show', $tag->id) . '" class="label label-success" title="' . $amount
                           . '"><i class="fa fa-fw fa-refresh"></i> ' . $tag->tag . '</a>';
                }

                /*
                 * AdvancePayment with a deposit will show the tag instead of the amount:
                 */
                if ($tag->tagMode == 'advancePayment' && $journal->transactionType->type == 'Deposit') {
                    $amount = App::make('amount')->formatJournal($journal, false);
                    return '<a href="' . route('tags.show', $tag->id) . '" class="label label-success" title="' . $amount
                           . '"><i class="fa fa-fw fa-sort-numeric-desc"></i> ' . $tag->tag . '</a>';
                }
                /*
                 * AdvancePayment with a withdrawal will show the amount with a link to
                 * the tag. The TransactionJournal should properly calculate the amount.
                 */
                if ($tag->tagMode == 'advancePayment' && $journal->transactionType->type == 'Withdrawal') {
                    $amount = App::make('amount')->formatJournal($journal);
                    return '<a href="' . route('tags.show', $tag->id) . '">' . $amount . '</a>';
                }


                if ($tag->tagMode == 'nothing') {
                    // return the amount:
                    return App::make('amount')->formatJournal($journal);
                }
            }


            return 'TODO: ' . $journal->amount;
        }
        );

        return $functions;
    }

    /**
     * Returns the name of the extension.
     *
     * @return string The extension name
     */
    public function getName()
{'fraction_non_alphanumeric': 0.14447395773183971, 'fraction_numerical': 0.0006929206605843631, 'mean_word_length': 1.5651658767772512, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 93, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2856977', 'n_tokens_mistral': 2297, 'n_tokens_neox': 2138, 'n_words': 515}