<commit_before><?php namespace Arcanedev\LaravelLang\Commands;

use Arcanedev\LaravelLang\Bases\Command;
use Arcanedev\LaravelLang\Contracts\TransChecker;

/**
 * Class     CheckCommand
 *
 * @package  Arcanedev\LaravelLang\Commands
 * @author   ARCANEDEV <<EMAIL>>
 */
class CheckCommand extends Command
{
    /* ------------------------------------------------------------------------------------------------
     |  Properties
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature   = 'trans:check';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Check the missing translations.';

    /** @var \Arcanedev\LaravelLang\Contracts\TransChecker */
    private $checker;

    /* ------------------------------------------------------------------------------------------------
     |  Constructor
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Init the CheckCommand.
     *
     * @param  \Arcanedev\LaravelLang\Contracts\TransChecker  $checker
     */
    public function __construct(TransChecker $checker)
    {
        parent::__construct();

        $this->checker = $checker;
    }

    /* ------------------------------------------------------------------------------------------------
     |  Functions
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Execute the console command.
     */
    public function handle()
    {
        $this->copyright();

        $this->info('Checking the missing translation...');

        $missing = $this->checker->check();

        $this->table(
            ['locale', 'translations'],
            $this->prepareRows($missing)
        );
    }

    /* ------------------------------------------------------------------------------------------------
     |  Other Functions
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Prepare table rows.
     *
     * @param  array  $missing
     *
     * @return array
     */
    private function prepareRows(array $missing)
    {
        $rows  = [];
        $count = 0;

        foreach ($missing as $locale => $translations) {
            foreach ($translations as $translation) {
                $rows[] = [$locale, $translation];
                $count++;
            }
            $rows[] = $this->tableSeparator();
        }

        /** @var \Symfony\Component\Console\Helper\FormatterHelper $formatter */
        $formatter = $this->getHelper('formatter');

        $rows[] = [
            $formatter->formatSection('Total', '', 'info'),
            $formatter->formatSection($count . ' translations are missing.', '', $count == 0 ? 'info' : 'error'),
        ];

        return $rows;
    }<commit_msg>Refactoring CheckCommand<commit_after><?php namespace Arcanedev\LaravelLang\Commands;

use Arcanedev\LaravelLang\Bases\Command;
use Arcanedev\LaravelLang\Contracts\TransChecker;

/**
 * Class     CheckCommand
 *
 * @package  Arcanedev\LaravelLang\Commands
 * @author   ARCANEDEV <<EMAIL>>
 */
class CheckCommand extends Command
{
    /* ------------------------------------------------------------------------------------------------
     |  Properties
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature   = 'trans:check';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Check the missing translations.';

    /** @var \Arcanedev\LaravelLang\Contracts\TransChecker */
    private $checker;

    /**
     * Missing translations count.
     *
     * @var int
     */
    private $count = 0;

    /* ------------------------------------------------------------------------------------------------
     |  Constructor
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Init the CheckCommand.
     *
     * @param  \Arcanedev\LaravelLang\Contracts\TransChecker  $checker
     */
    public function __construct(TransChecker $checker)
    {
        parent::__construct();

        $this->checker = $checker;
        $this->count   = 0;
    }

    /* ------------------------------------------------------------------------------------------------
     |  Functions
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Execute the console command.
     */
    public function handle()
    {
        $this->copyright();

        $this->info('Checking the missing translation...');
        $this->line('');

        $missing = $this->checker->check();

        $this->table(['locale', 'translations'], $this->prepareRows($missing));

        $this->line('');
        $this->showMessage();
        $this->line('');
    }

    /* ------------------------------------------------------------------------------------------------
     |  Other Functions
     | ------------------------------------------------------------------------------------------------
     */
    /**
     * Prepare table rows.
     *
     * @param  array  $missing
     *
     * @return array
     */
    private function prepareRows(array $missing)
    {
        $rows        = [];

        foreach ($missing as $locale => $translations) {
            foreach ($translations as $translation) {
                $rows[] = [$locale, $translation];
                $this->count++;
            }
            $rows[] = $this->tableSeparator();
        }

        $rows[] = ['Total', $this->count . ' translations are missing.'];

        return $rows;
    }

    /**
     * Show the message.
     */
    private function showMessage()
    {
        if ($this->count > 0)
            $this->comment('Try to fix your translations and run again the `trans:check` command.');
        else
            $this->info('No missing translations, YOU ROCK !! (^_^)b');
    }
{'fraction_non_alphanumeric': 0.3490447854682117, 'fraction_numerical': 0.0007829627309740056, 'mean_word_length': 0.9514207149404217, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 39, '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': '494235', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1417, 'n_words': 291}