<commit_before><?php

/**
 * Manage users.
 *
 * @package wp-cli
 */
class User_Command extends \WP_CLI\CommandWithDBObject {

	protected $obj_type = 'user';

	private $fields = array(
		'ID',
		'user_login',
		'display_name',
		'user_email',
		'user_registered',
		'roles'
	);

	/**
	 * List users.
	 *
	 * @subcommand list
	 * @synopsis [--role=<role>] [--fields=<fields>] [--format=<format>]
	 */
	public function _list( $args, $assoc_args ) {

		$defaults = array(
			'blog_id'   => get_current_blog_id(),
			'fields'    => implode( ',', $this->fields ),
			'format'    => 'table',
		);
		$params = array_merge( $defaults, $assoc_args );

		$fields = $params['fields'];
		unset( $params['fields'] );

		if ( array_key_exists( 'role', $assoc_args ) ) {
			$params['role'] = $assoc_args['role'];
		}

		if ( 'ids' == $params['format'] )
			$params['fields'] = 'ids';
		else
			$params['fields'] = 'all_with_meta';

		$users = get_users( $params );

		if ( 'ids' != $params['format'] ) {
			foreach ( $users as $user ) {
				$user->roles = implode( ',', $user->roles );
			}
		}

		WP_CLI\Utils\format_items( $params['format'], $users, $fields );
	}

	/**
	 * Get a single user.
	 *
	 * @synopsis [--format=<format>] <user>
	 */
	public function get( $args, $assoc_args ) {
		$assoc_args = wp_parse_args( $assoc_args, array(
			'format' => 'table'
		) );

		$user = self::get_user( $args[0] )->to_array();

		switch ( $assoc_args['format'] ) {

		case 'table':
			$this->assoc_array_to_table( $user );
			break;

		case 'json':
			WP_CLI::print_value( $user, $assoc_args );
			break;

		default:
			\WP_CLI::error( "Invalid value for format: " . $format );
			break;

		}
	}

	/**<commit_msg>WP_User->to_array() doesn't exist in WP 3.4<commit_after><?php

/**
 * Manage users.
 *
 * @package wp-cli
 */
class User_Command extends \WP_CLI\CommandWithDBObject {

	protected $obj_type = 'user';

	private $fields = array(
		'ID',
		'user_login',
		'display_name',
		'user_email',
		'user_registered',
		'roles'
	);

	/**
	 * List users.
	 *
	 * @subcommand list
	 * @synopsis [--role=<role>] [--fields=<fields>] [--format=<format>]
	 */
	public function _list( $args, $assoc_args ) {

		$defaults = array(
			'blog_id'   => get_current_blog_id(),
			'fields'    => implode( ',', $this->fields ),
			'format'    => 'table',
		);
		$params = array_merge( $defaults, $assoc_args );

		$fields = $params['fields'];
		unset( $params['fields'] );

		if ( array_key_exists( 'role', $assoc_args ) ) {
			$params['role'] = $assoc_args['role'];
		}

		if ( 'ids' == $params['format'] )
			$params['fields'] = 'ids';
		else
			$params['fields'] = 'all_with_meta';

		$users = get_users( $params );

		if ( 'ids' != $params['format'] ) {
			foreach ( $users as $user ) {
				$user->roles = implode( ',', $user->roles );
			}
		}

		WP_CLI\Utils\format_items( $params['format'], $users, $fields );
	}

	/**
	 * Get a single user.
	 *
	 * @synopsis [--format=<format>] <user>
	 */
	public function get( $args, $assoc_args ) {
		$assoc_args = wp_parse_args( $assoc_args, array(
			'format' => 'table'
		) );

		$user = self::get_user( $args[0] );

		if ( method_exists( $user, 'to_array' ) ) {
			$user_data = $user->to_array();
		} else {
			// WP 3.4 compat
			$user_data = $user->data;
		}

		switch ( $assoc_args['format'] ) {

		case 'table':
			$this->assoc_array_to_table( $user_data );
			break;

		case 'json':
			WP_CLI::print_value( $user_data, $assoc_args );
			break;

		default:
			\WP_CLI::error( "Invalid value for format: " . $format );
			break;

		}
	}

	/**
{'fraction_non_alphanumeric': 0.2053370786516854, 'fraction_numerical': 0.0016853932584269663, 'mean_word_length': 3.2494033412887826, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 33, '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': '3910089', 'n_tokens_mistral': 1563, 'n_tokens_neox': 1369, 'n_words': 266}