<commit_before><?php

namespace litepubl\plugins\faqmenu;
use litepubl\view\Filter;

class Filter
{

    public function convert($content) {
        $result = '';
        $content = str_replace(array(
            "\r\n",
            "\r"
        ) , "\n", trim($content));

        $lines = explode("\n", $content);
        $q = array();
        $a = array();

        $filter = Filter::i();
        foreach ($lines as $s) {
            $s = trim($s);
            if (Str::begin($s, 'q:') || Str::begin($s, 'Q:')) {
                $q[] = trim(substr($s, 2));
            } elseif (Str::begin($s, 'a:') || Str::begin($s, 'A:')) {
                $a[] = trim(substr($s, 2));
            } elseif ($s != '') {
                $result.= $this->createlist($q, $a);
                $q = array();
                $a = array();
                $result.= $filter->simplefilter($s);
            }
        }

        $result.= $this->createlist($q, $a);
        return $result;
    }

    private function createlist(array $questions, array $answers) {
        if (count($questions) == 0) {
 return '';
}

        $result = '';
        foreach ($questions as $i => $q) {
            $result.= sprintf('<li><a href="#" rel="faqitem">%s</a><p>%s</p></li>', $q, $answers[$i]);
        }
        return sprintf('<ul class="faqlist">%s</ul>', $result);
    }

}
<commit_msg>faq refactoried<commit_after><?php

namespace litepubl\plugins\faqmenu;
use litepubl\view\Filter as ViewFilter;

class Filter
{
public $templateItems = '<ul>$items</ul>';
public $template = '<li><a href="#answer-$id" id="question-$id" class="faq-question dashed" data-toggle="collapse" aria-expanded="false" aria-controls="answer-$id">$title</a>
<div id="answer-$id" class="collapse faq-answer" aria-labelledby="question-$id">$content</div></li>';

private $id = 0;

    public function convert($content) {
        $result = '';
        $content = str_replace(array(
            "\r\n",
            "\r"
        ) , "\n", trim($content));

        $lines = explode("\n", $content);
        $q = array();
        $a = array();

        $filter = ViewFilter::i();
        foreach ($lines as $s) {
            $s = trim($s);
            if (Str::begin($s, 'q:') || Str::begin($s, 'Q:')) {
                $q[] = trim(substr($s, 2));
            } elseif (Str::begin($s, 'a:') || Str::begin($s, 'A:')) {
                $a[] = trim(substr($s, 2));
            } elseif ($s) {
                $result.= $this->createlist($q, $a);
                $result.= $filter->simplefilter($s);
                $q = array();
                $a = array();
            }
        }

        $result.= $this->createlist($q, $a);
        return $result;
    }

    private function createlist(array $questions, array $answers) {
        if (!count($questions) {
 return '';
}

        $result = '';
        foreach ($questions as $i => $q) {
            $result.= strtr($this->template, [
'$id' => $this->id++,
'$title' => $q,
'$content' => $answers[$i],
]);
        }

        return str_replace('$items', $result, $this->templateItems);
    }

}

{'fraction_non_alphanumeric': 0.20863309352517986, 'fraction_numerical': 0.001876759461995621, 'mean_word_length': 1.7736339982653946, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 33, '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': '3919852', 'n_tokens_mistral': 1070, 'n_tokens_neox': 998, 'n_words': 205}