| @@ -2,16 +2,12 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Stream command for WP-CLI |
| 4 | 4 | * |
| 5 | 5 | * @see https://github.com/wp-cli/wp-cli |
| 6 | - * @package WP_Stream | |
| 7 | 6 | */ |
| 8 | 7 | |
| 9 | 8 | namespace WP_Stream; |
| 10 | 9 | |
| 11 | -/** | |
| 12 | - * Class - CLI | |
| 13 | - */ | |
| 14 | 10 | class CLI extends \WP_CLI_Command { |
| 15 | 11 | |
| 16 | 12 | /** |
| 17 | 13 | * Query a set of Stream records. |
| @@ -89,13 +85,10 @@ | ||
| 89 | 85 | * wp stream query --user_role__not_in=administrator --date_after=2015-01-01T12:00:00 |
| 90 | 86 | * wp stream query --user_id=1 --action=login --records_per_page=50 --fields=created |
| 91 | 87 | * |
| 92 | 88 | * @see WP_Stream_Query |
| 93 | - * @see https://github.com/xwp/stream/wiki/WP-CLI-Command | |
| 94 | - * @see https://github.com/xwp/stream/wiki/Query-Reference | |
| 95 | - * | |
| 96 | - * @param array $args Unused. | |
| 97 | - * @param array $assoc_args Fields to return data for. | |
| 89 | + * @see https://github.com/wp-stream/stream/wiki/WP-CLI-Command | |
| 90 | + * @see https://github.com/wp-stream/stream/wiki/Query-Reference | |
| 98 | 91 | */ |
| 99 | 92 | public function query( $args, $assoc_args ) { |
| 100 | 93 | unset( $args ); |
| 101 | 94 | |
| @@ -127,13 +120,13 @@ | ||
| 127 | 120 | $query_args['fields'] = implode( ',', $fields ); |
| 128 | 121 | |
| 129 | 122 | $records = wp_stream_get_instance()->db->query( $query_args ); |
| 130 | 123 | |
| 131 | - // Make structure Formatter compatible. | |
| 124 | + // Make structure Formatter compatible | |
| 132 | 125 | foreach ( (array) $records as $key => $record ) { |
| 133 | 126 | $formatted_records[ $key ] = array(); |
| 134 | 127 | |
| 135 | - // Catch any fields missing in records. | |
| 128 | + // Catch any fields missing in records | |
| 136 | 129 | foreach ( $fields as $field ) { |
| 137 | 130 | if ( ! array_key_exists( $field, $record ) ) { |
| 138 | 131 | $record->$field = null; |
| 139 | 132 | } |
| @@ -158,11 +151,11 @@ | ||
| 158 | 151 | } |
| 159 | 152 | |
| 160 | 153 | if ( 'json_pretty' === $assoc_args['format'] ) { |
| 161 | 154 | if ( version_compare( PHP_VERSION, '5.4', '<' ) ) { |
| 162 | - \WP_CLI::line( wp_stream_json_encode( $formatted_records ) ); // xss ok. | |
| 155 | + \WP_CLI::line( wp_stream_json_encode( $formatted_records ) ); // xss ok | |
| 163 | 156 | } else { |
| 164 | - \WP_CLI::line( wp_stream_json_encode( $formatted_records, JSON_PRETTY_PRINT ) ); // xss ok. | |
| 157 | + \WP_CLI::line( wp_stream_json_encode( $formatted_records, JSON_PRETTY_PRINT ) ); // xss ok | |
| 165 | 158 | } |
| 166 | 159 | } |
| 167 | 160 | |
| 168 | 161 | if ( 'csv' === $assoc_args['format'] ) { |
| @@ -182,10 +175,10 @@ | ||
| 182 | 175 | |
| 183 | 176 | /** |
| 184 | 177 | * Convert any field to a flat array. |
| 185 | 178 | * |
| 186 | - * @param string $name The output array element name. | |
| 187 | - * @param mixed $object Any value to be converted to an array. | |
| 179 | + * @param string $name The output array element name | |
| 180 | + * @param mixed $object Any value to be converted to an array | |
| 188 | 181 | * |
| 189 | 182 | * @return array The flat array |
| 190 | 183 | */ |
| 191 | 184 | private function format_field( $name, $object ) { |
| @@ -206,9 +199,11 @@ | ||
| 206 | 199 | |
| 207 | 200 | /** |
| 208 | 201 | * Convert an array of flat records to CSV |
| 209 | 202 | * |
| 210 | - * @param array $array The input array of records. | |
| 203 | + * @param array $array The input array of records | |
| 204 | + * | |
| 205 | + * @return string The CSV output | |
| 211 | 206 | */ |
| 212 | 207 | private function csv_format( $array ) { |
| 213 | 208 | $output = fopen( 'php://output', 'w' ); // @codingStandardsIgnoreLine Clever output for WP CLI using php://output |
| 214 | 209 | |