<commit_before><?php

namespace YiiMinifyClientScriptPackage;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class MinifyCommand extends Command
{

    protected function configure()
    {
        $cwd                = getcwd();
        $configMode         = Input\InputOption::VALUE_REQUIRED;
        $configDefault      = null;
        $appBasePathDefault = null;

        $configDir = $cwd.DIRECTORY_SEPARATOR.'protected'.DIRECTORY_SEPARATOR.'config';
        if (is_dir($configDir)) {
            $clientScript       = $configDir.DIRECTORY_SEPARATOR.'clientscript.php';
            $mainConfig         = $configDir.DIRECTORY_SEPARATOR.'main.php';
            $appBasePathDefault = $cwd;

            if (is_file($clientScript)) {
                $configMode    = Input\InputOption::VALUE_OPTIONAL;
                $configDefault = $clientScript;
            } elseif (is_file($mainConfig)) {
                $configMode    = Input\InputOption::VALUE_OPTIONAL;
                $configDefault = $mainConfig;
            }
        }

        $this
                ->setName('minify')
                ->setDescription('Minify client script packages for a Yii web application.')
                ->addOption('config', 'c', $configMode, 'Path to Yii config file. If you are using a separated file for "clientScript" component, use that file instead.', $configDefault)
                ->addOption('appBasePath', 'a', $configMode, 'Root path of the Yii web application.', $appBasePathDefault)
                ->addOption('rewriteCssUrl', 'r', Input\InputOption::VALUE_OPTIONAL, 'Whether to rewrite "url()" rules after relocating CSS files.', true)
                ->addOption('minFileSuffix', 'm', Input\InputOption::VALUE_OPTIONAL, 'The file name(without extension) suffix of minified files.', '.min')
                ->addOption('publishDir', 'p', Input\InputOption::VALUE_OPTIONAL, 'The path which is relative to "appBasePath" for publishing minified resources.', 'assets')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $options                = new \YiiMinifyClientScriptPackage\MinifyOptions();
        $options->appBasePath   = $input->getOption('appBasePath');
        $options->rewriteCssUrl = $input->getOption('rewriteCssUrl');
        $options->minFileSuffix = $input->getOption('minFileSuffix');
        $options->publishDir    = $input->getOption('publishDir');

        $configFile = $input->getOption('config');
        $config     = new \YiiMinifyClientScriptPackage\YiiConfig($configFile);

        if (false === rename($configFile, $configFile.'.bak')) {
            throw new Exception('Unable to create backup for file: '.$configFile);<commit_msg>Refractor with new understanding of PHP namespace.<commit_after><?php

namespace YiiMinifyClientScriptPackage;

use \Symfony\Component\Console\Command\Command;
use \Symfony\Component\Console\Input\InputOption;
use \Symfony\Component\Console\Input\InputInterface;
use \Symfony\Component\Console\Output\OutputInterface;

class MinifyCommand extends Command
{

    protected function configure()
    {
        $cwd                = getcwd();
        $configMode         = InputOption::VALUE_REQUIRED;
        $configDefault      = null;
        $appBasePathDefault = null;

        $configDir = $cwd.DIRECTORY_SEPARATOR.'protected'.DIRECTORY_SEPARATOR.'config';
        if (is_dir($configDir)) {
            $clientScript       = $configDir.DIRECTORY_SEPARATOR.'clientscript.php';
            $mainConfig         = $configDir.DIRECTORY_SEPARATOR.'main.php';
            $appBasePathDefault = $cwd;

            if (is_file($clientScript)) {
                $configMode    = InputOption::VALUE_OPTIONAL;
                $configDefault = $clientScript;
            } elseif (is_file($mainConfig)) {
                $configMode    = InputOption::VALUE_OPTIONAL;
                $configDefault = $mainConfig;
            }
        }

        $this
                ->setName('minify')
                ->setDescription('Minify client script packages for a Yii web application.')
                ->addOption('config', 'c', $configMode, 'Path to Yii config file. If you are using a separated file for "clientScript" component, use that file instead.', $configDefault)
                ->addOption('appBasePath', 'a', $configMode, 'Root path of the Yii web application.', $appBasePathDefault)
                ->addOption('rewriteCssUrl', 'r', InputOption::VALUE_OPTIONAL, 'Whether to rewrite "url()" rules after relocating CSS files.', true)
                ->addOption('minFileSuffix', 'm', InputOption::VALUE_OPTIONAL, 'The file name(without extension) suffix of minified files.', '.min')
                ->addOption('publishDir', 'p', InputOption::VALUE_OPTIONAL, 'The path which is relative to "appBasePath" for publishing minified resources.', 'assets')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $options                = new \YiiMinifyClientScriptPackage\MinifyOptions();
        $options->appBasePath   = $input->getOption('appBasePath');
        $options->rewriteCssUrl = $input->getOption('rewriteCssUrl');
        $options->minFileSuffix = $input->getOption('minFileSuffix');
        $options->publishDir    = $input->getOption('publishDir');

        $configFile = $input->getOption('config');
        $config     = new \YiiMinifyClientScriptPackage\YiiConfig($configFile);

        if (false === rename($configFile, $configFile.'.bak')) {
            throw new Exception('Unable to create backup for file: '.$configFile);
{'fraction_non_alphanumeric': 0.11946518492793888, 'fraction_numerical': 0.0, 'mean_word_length': 2.777049180327869, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '1267411', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1540, 'n_words': 341}