<commit_before><?php

/**
 * Base class for WP-CLI commands
 *
 * @package wp-cli
 * @author <NAME>
 */
abstract class WP_CLI_Command {
    /**
     * Construct for this class, transfers the cli arguments to the right class
     *
     * @param Array $args
     */
    function __construct($args = array()) {
        // The first command is the sub command
        $sub_command = array_shift($args);
        
        // If the method exists, try to load it
        if(method_exists($this, $sub_command)) {
            $this->$sub_command($args);
        }
        // If a dummy method exists, use it. This if for reserved keywords in php (like list, isset)
        elseif(method_exists($this, '_'.$sub_command)) {
            $sub_command = '_'.$sub_command;
            $this->$sub_command($args);
        }
        // Otherwise, show the help for this command
        else {
            $this->help($args);
        }
    }
    
    /**
     * General help function for this command
     *
     * @param Array $args 
     * @return void
     */
    public function help($args = array()) {
        // Get the cli arguments
        $arguments = $GLOBALS['argv'];
        
        // Remove the first entry
        array_shift($arguments);

        // Get the command
        $used_command = array_shift($arguments);
        
        // Show the list of sub-commands for this command
        WP_CLI::line('Example usage:');
        WP_CLI::out('    wp '.$used_command);
        $methods = WP_CLI_Command::getMethods($this);
        if(!empty($methods)) {
            WP_CLI::out(' ['.implode('|', $methods).']');
        }
        WP_CLI::line(' ...');
        WP_CLI::line();
        
        // Send a warning to the user because there is no custom help function defined in the command
        // Make usure there always is a help method in your command class
        WP_CLI::warning('The command has no dedicated help function, ask the creator to fix it.');
    }
    
    /**
     * Get the filtered list of methods for a class
     *
     * @param string $class
     * @return Array The list of methods
     */
    static function getMethods($class) {
        // Methods that don't need to be included in the method list
        $blacklist = array('__construct', 'getMethods');
        
        // Get all the methods of the class
        $methods = get_class_methods($class);
        
        // Remove the blacklisted methods
        foreach($blacklist as $method) {
            $in_array = array_search($method, $methods);
            if($in_array !== false) {
                unset($methods[$in_array]);
            }
        }
        
        // Fix dummy function names
        foreach($methods as $key => $method) {
            if(strpos($method, '_') === 0) {
                $methods[$key] = substr($method, 1, strlen($method));
            }
        }
        
        // Only return the values, to fill up the gaps
        return array_values($methods);
    }
}<commit_msg>pass assoc args to sub-command handlers<commit_after><?php

/**
 * Base class for WP-CLI commands
 *
 * @package wp-cli
 * @author <NAME>
 */
abstract class WP_CLI_Command {
    /**
     * Construct for this class, transfers the cli arguments to the right class
     *
     * @param Array $args
     */
    function __construct( $args, $assoc_args ) {
        // The first command is the sub command
        $sub_command = array_shift($args);

        // If the method exists, try to load it
        if(method_exists($this, $sub_command)) {
            $this->$sub_command($args, $assoc_args);
        }
        // If a dummy method exists, use it. This if for reserved keywords in php (like list, isset)
        elseif(method_exists($this, '_'.$sub_command)) {
            $sub_command = '_'.$sub_command;
            $this->$sub_command($args, $assoc_args);
        }
        // Otherwise, show the help for this command
        else {
            $this->help($args);
        }
    }

    /**
     * General help function for this command
     *
     * @param Array $args
     * @return void
     */
    public function help($args = array()) {
        // Get the cli arguments
        $arguments = $GLOBALS['argv'];

        // Remove the first entry
        array_shift($arguments);

        // Get the command
        $used_command = array_shift($arguments);

        // Show the list of sub-commands for this command
        WP_CLI::line('Example usage:');
        WP_CLI::out('    wp '.$used_command);
        $methods = WP_CLI_Command::getMethods($this);
        if(!empty($methods)) {
            WP_CLI::out(' ['.implode('|', $methods).']');
        }
        WP_CLI::line(' ...');
        WP_CLI::line();

        // Send a warning to the user because there is no custom help function defined in the command
        // Make usure there always is a help method in your command class
        WP_CLI::warning('The command has no dedicated help function, ask the creator to fix it.');
    }

    /**
     * Get the filtered list of methods for a class
     *
     * @param string $class
     * @return Array The list of methods
     */
    static function getMethods($class) {
        // Methods that don't need to be included in the method list
        $blacklist = array('__construct', 'getMethods');

        // Get all the methods of the class
        $methods = get_class_methods($class);

        // Remove the blacklisted methods
        foreach($blacklist as $method) {
            $in_array = array_search($method, $methods);
            if($in_array !== false) {
                unset($methods[$in_array]);
            }
        }

        // Fix dummy function names
        foreach($methods as $key => $method) {
            if(strpos($method, '_') === 0) {
                $methods[$key] = substr($method, 1, strlen($method));
            }
        }

        // Only return the values, to fill up the gaps
        return array_values($methods);
    }
}
{'fraction_non_alphanumeric': 0.12046979865771812, 'fraction_numerical': 0.0006711409395973154, 'mean_word_length': 1.897909577053962, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '7214321', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1624, 'n_words': 524}