<commit_before><?php
/**
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @since         1.2.0
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */
namespace Cake\Shell\Task;

use Cake\Console\Shell;
use Cake\Core\App;
use Cake\Core\Plugin;
use Cake\Filesystem\File;
use Cake\Filesystem\Folder;
use Cake\Utility\Inflector;

/**
 * Language string extractor
 *
 */
class ExtractTask extends Shell
{

    /**
     * Paths to use when looking for strings
     *
     * @var array
     */
    protected $_paths = [];

    /**
     * Files from where to extract
     *
     * @var array
     */
    protected $_files = [];

    /**
     * Merge all domain strings into the default.pot file
     *
     * @var bool
     */
    protected $_merge = false;

    /**
     * Current file being processed
     *
     * @var string
     */
    protected $_file = null;

    /**
     * Contains all content waiting to be write
     *
     * @var array
     */
    protected $_storage = [];

    /**
     * Extracted tokens
     *
     * @var array
     */
    protected $_tokens = [];

    /**
     * Extracted strings indexed by domain.
     *
     * @var array
     */
    protected $_translations = [];

    /**
     * Destination path
     *
     * @var string
     */
    protected $_output = null;

    /**
     * An array of directories to exclude.
     *
     * @var array
     */
    protected $_exclude = [];

    /**
     * Holds the validation string domain to use for validation messages when extracting
     *
     * @var bool
     */
    protected $_validationDomain = 'default';

    /**
     * Holds whether this call should extract the CakePHP Lib messages
     *
     * @var bool
     */
    protected $_extractCore = false;

    /**
     * No welcome message.
     *
     * @return void
     */
    protected function _welcome()
    {
    }

    /**
     * Method to interact with the User and get path selections.
     *
     * @return void
     */
    protected function _getPaths()
    {
        $defaultPath = APP;
        while (true) {
            $currentPaths = count($this->_paths) > 0 ? $this->_paths : ['None'];
            $message = sprintf(
                "Current paths: %s\nWhat is the path you would like to extract?\n[Q]uit [D]one",
                implode(', ', $currentPaths)
            );
            $response = $this->in($message, null, $defaultPath);
            if (strtoupper($response) === 'Q') {
                $this->err('Extract Aborted');
                $this->_stop();
                return;
            } elseif (strtoupper($response) === 'D' && count($this->_paths)) {
                $this->out();
                return;
            } elseif (strtoupper($response) === 'D') {
                $this->err('<warning>No directories selected.</warning> Please choose a directory.');
            } elseif (is_dir($response)) {
                $this->_paths[] = $response;
                $defaultPath = 'D';
            } else {
                $this->err('The directory path you supplied was not found. Please try again.');
            }
            $this->out();
        }
    }

    /**
     * Execution method always used for tasks
     *
     * @return void
     */
    public function main()
    {
        if (!empty($this->params['exclude'])) {
            $this->_exclude = explode(',', $this->params['exclude']);
        }
        if (isset($this->params['files']) && !is_array($this->params['files'])) {
            $this->_files = explode(',', $this->params['files']);
        }
        if (isset($this->params['paths'])) {
            $this->_paths = explode(',', $this->params['paths']);
        } elseif (isset($this->params['plugin'])) {
            $plugin = Inflector::camelize($this->params['plugin']);
            if (!Plugin::loaded($plugin)) {
                Plugin::load($plugin);
            }
            $this->_paths = [Plugin::classPath($plugin)];
            $this->params['plugin'] = $plugin;
        } else {
            $this->_getPaths();
        }

        if (isset($this->params['extract-core'])) {
            $this->_extractCore = !(strtolower($this->params['extract-core']) === 'no');
        } else {
            $response = $this->in('Would you like to extract the messages from the CakePHP core?', ['y', 'n'], 'n');
            $this->_extractCore = strtolower($response) === 'y';
        }

        if (!empty($this->params['exclude-plugins']) && $this->_isExtractingApp()) {
            $this->_exclude = array_merge($this->_exclude, App::path('Plugin'));
        }

        if (!empty($this->params['validation-domain'])) {
            $this->_validationDomain = $this->params['validation-domain'];
        }

        if ($this->_extractCore) {
            $this->_paths[] = CAKE;
        }

        if (isset($this->params['output'])) {
            $this->_output = $this->params['output'];
        } elseif (isset($this->params['plugin'])) {
            $this->_output = $this->_paths[0] . DS . 'Locale';
        } else {
            $message = "What is the path you would like to output?\n[Q]uit";
            while (true) {
                $response = $this->in($message, null, rtrim($this->_paths[0], DS) . DS . 'Locale');
                if (strtoupper($response) === 'Q') {
                    $this->err('Extract Aborted');
                    $this->_stop();
                    return;
                } elseif ($this->_isPathUsable($response)) {
                    $this->_output = $response . DS;
                    break;
                } else {
                    $this->err('');
                    $this->err(
                        '<error>The directory path you supplied was ' .
                        'not found. Please try again.</error>'
                    );
                }
                $this->out();
            }
        }

        if (isset($this->params['merge'])) {
            $this->_merge = !(strtolower($this->params['merge']) === 'no');
        } else {
            $this->out();
            $response = $this->in('Would you like to merge all domain strings into the default.pot file?', ['y', 'n'], 'n');<commit_msg>delete extra DS on plugin Path<commit_after><?php
/**
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE.txt
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @since         1.2.0
 * @license       http://www.opensource.org/licenses/mit-license.php MIT License
 */
namespace Cake\Shell\Task;

use Cake\Console\Shell;
use Cake\Core\App;
use Cake\Core\Plugin;
use Cake\Filesystem\File;
use Cake\Filesystem\Folder;
use Cake\Utility\Inflector;

/**
 * Language string extractor
 *
 */
class ExtractTask extends Shell
{

    /**
     * Paths to use when looking for strings
     *
     * @var array
     */
    protected $_paths = [];

    /**
     * Files from where to extract
     *
     * @var array
     */
    protected $_files = [];

    /**
     * Merge all domain strings into the default.pot file
     *
     * @var bool
     */
    protected $_merge = false;

    /**
     * Current file being processed
     *
     * @var string
     */
    protected $_file = null;

    /**
     * Contains all content waiting to be write
     *
     * @var array
     */
    protected $_storage = [];

    /**
     * Extracted tokens
     *
     * @var array
     */
    protected $_tokens = [];

    /**
     * Extracted strings indexed by domain.
     *
     * @var array
     */
    protected $_translations = [];

    /**
     * Destination path
     *
     * @var string
     */
    protected $_output = null;

    /**
     * An array of directories to exclude.
     *
     * @var array
     */
    protected $_exclude = [];

    /**
     * Holds the validation string domain to use for validation messages when extracting
     *
     * @var bool
     */
    protected $_validationDomain = 'default';

    /**
     * Holds whether this call should extract the CakePHP Lib messages
     *
     * @var bool
     */
    protected $_extractCore = false;

    /**
     * No welcome message.
     *
     * @return void
     */
    protected function _welcome()
    {
    }

    /**
     * Method to interact with the User and get path selections.
     *
     * @return void
     */
    protected function _getPaths()
    {
        $defaultPath = APP;
        while (true) {
            $currentPaths = count($this->_paths) > 0 ? $this->_paths : ['None'];
            $message = sprintf(
                "Current paths: %s\nWhat is the path you would like to extract?\n[Q]uit [D]one",
                implode(', ', $currentPaths)
            );
            $response = $this->in($message, null, $defaultPath);
            if (strtoupper($response) === 'Q') {
                $this->err('Extract Aborted');
                $this->_stop();
                return;
            } elseif (strtoupper($response) === 'D' && count($this->_paths)) {
                $this->out();
                return;
            } elseif (strtoupper($response) === 'D') {
                $this->err('<warning>No directories selected.</warning> Please choose a directory.');
            } elseif (is_dir($response)) {
                $this->_paths[] = $response;
                $defaultPath = 'D';
            } else {
                $this->err('The directory path you supplied was not found. Please try again.');
            }
            $this->out();
        }
    }

    /**
     * Execution method always used for tasks
     *
     * @return void
     */
    public function main()
    {
        if (!empty($this->params['exclude'])) {
            $this->_exclude = explode(',', $this->params['exclude']);
        }
        if (isset($this->params['files']) && !is_array($this->params['files'])) {
            $this->_files = explode(',', $this->params['files']);
        }
        if (isset($this->params['paths'])) {
            $this->_paths = explode(',', $this->params['paths']);
        } elseif (isset($this->params['plugin'])) {
            $plugin = Inflector::camelize($this->params['plugin']);
            if (!Plugin::loaded($plugin)) {
                Plugin::load($plugin);
            }
            $this->_paths = [Plugin::classPath($plugin)];
            $this->params['plugin'] = $plugin;
        } else {
            $this->_getPaths();
        }

        if (isset($this->params['extract-core'])) {
            $this->_extractCore = !(strtolower($this->params['extract-core']) === 'no');
        } else {
            $response = $this->in('Would you like to extract the messages from the CakePHP core?', ['y', 'n'], 'n');
            $this->_extractCore = strtolower($response) === 'y';
        }

        if (!empty($this->params['exclude-plugins']) && $this->_isExtractingApp()) {
            $this->_exclude = array_merge($this->_exclude, App::path('Plugin'));
        }

        if (!empty($this->params['validation-domain'])) {
            $this->_validationDomain = $this->params['validation-domain'];
        }

        if ($this->_extractCore) {
            $this->_paths[] = CAKE;
        }

        if (isset($this->params['output'])) {
            $this->_output = $this->params['output'];
        } elseif (isset($this->params['plugin'])) {
            $this->_output = $this->_paths[0] . 'Locale';
        } else {
            $message = "What is the path you would like to output?\n[Q]uit";
            while (true) {
                $response = $this->in($message, null, rtrim($this->_paths[0], DS) . DS . 'Locale');
                if (strtoupper($response) === 'Q') {
                    $this->err('Extract Aborted');
                    $this->_stop();
                    return;
                } elseif ($this->_isPathUsable($response)) {
                    $this->_output = $response . DS;
                    break;
                } else {
                    $this->err('');
                    $this->err(
                        '<error>The directory path you supplied was ' .
                        'not found. Please try again.</error>'
                    );
                }
                $this->out();
            }
        }

        if (isset($this->params['merge'])) {
            $this->_merge = !(strtolower($this->params['merge']) === 'no');
        } else {
            $this->out();
            $response = $this->in('Would you like to merge all domain strings into the default.pot file?', ['y', 'n'], 'n');
{'fraction_non_alphanumeric': 0.15708667372560883, 'fraction_numerical': 0.0009075782786265315, 'mean_word_length': 1.749636098981077, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 133, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3493055', 'n_tokens_mistral': 3716, 'n_tokens_neox': 3577, 'n_words': 895}