<commit_before><?php namespace Rolice\LangSync;

use Symfony\Component\Finder\Finder;

/**
 * Class Parser
 * @package Rolice\LangSync
 */
class Parser
{

    /**
     * @var array
     */
    protected $extraction = [];
    /**
     * @var LabelsCollection
     */
    protected $collection;

    /**
     * @param LabelsCollection $collection
     */
    public function __construct(LabelsCollection $collection)
    {
        $this->collection = $collection;
    }

    /**
     * Extract all localization labels from files
     */
    public function extract()
    {
        foreach ($this->getFiles() as $file) {
            /**
             * @TODO: make it work for such lines:
             * Lang::get('common.' . $_ENV['client_currency'] . '-sign')
             * Lang::get("common.{$currency}-sign")
             */
            preg_match_all('#(?:\@lang|Lang::get)\((?<quot>\'|")(?<match>.*?)\k{quot}.*?\)#ui',
                $file->getContents(), $buffer);

            if (1 >= count($buffer)) {
                continue;
            }

            array_shift($buffer);

            $nest = function ($key, &$extraction, $index = 0) use (&$nest, $file) {
                $parts = explode('.', $key);

                // Recursion terminator
                if (count($parts) < $index) {
                    return;
                }

                // Put the value on the last index<commit_msg>Updated parser to enhance translation detection support with @choice.<commit_after><?php namespace Rolice\LangSync;

use Symfony\Component\Finder\Finder;

/**
 * Class Parser
 * @package Rolice\LangSync
 */
class Parser
{

    /**
     * @var array
     */
    protected $extraction = [];
    /**
     * @var LabelsCollection
     */
    protected $collection;

    /**
     * @param LabelsCollection $collection
     */
    public function __construct(LabelsCollection $collection)
    {
        $this->collection = $collection;
    }

    /**
     * Extract all localization labels from files
     */
    public function extract()
    {
        foreach ($this->getFiles() as $file) {
            /**
             * @TODO: make it work for such lines:
             * Lang::get('common.' . $_ENV['client_currency'] . '-sign')
             * Lang::get("common.{$currency}-sign")
             */
            preg_match_all('#(?:\@lang|@choice|Lang::get)\((?<quot>\'|")(?<match>.*?)\k{quot}.*?\)#ui',
                $file->getContents(), $buffer);

            if (1 >= count($buffer)) {
                continue;
            }

            array_shift($buffer);

            $nest = function ($key, &$extraction, $index = 0) use (&$nest, $file) {
                $parts = explode('.', $key);

                // Recursion terminator
                if (count($parts) < $index) {
                    return;
                }

                // Put the value on the last index
{'fraction_non_alphanumeric': 0.1573111573111573, 'fraction_numerical': 0.001386001386001386, 'mean_word_length': 1.6781076066790352, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '3479986', 'n_tokens_mistral': 831, 'n_tokens_neox': 792, 'n_words': 177}