Skip to content

Commit 3c67503

Browse files
committed
Merge branch 'master' into add-alignments
2 parents 375d811 + a98408c commit 3c67503

File tree

17 files changed

+167
-98
lines changed

17 files changed

+167
-98
lines changed

.github/workflows/testing.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Testing
22

33
on:
4+
workflow_dispatch:
45
pull_request:
56
push:
67
branches:

.travis.yml

Lines changed: 0 additions & 26 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
PHP Command Line Tools
22
======================
33

4-
[![Build Status](https://travis-ci.org/wp-cli/php-cli-tools.png?branch=master)](https://travis-ci.org/wp-cli/php-cli-tools)
5-
64
A collection of functions and classes to assist with command line development.
75

86
Requirements
97

10-
* PHP >= 5.3
8+
* PHP >= 5.6
119

1210
Suggested PHP extensions
1311

composer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
}
1919
],
2020
"require": {
21-
"php": ">= 5.3.0"
21+
"php": ">= 7.2.24"
2222
},
2323
"require-dev": {
2424
"roave/security-advisories": "dev-latest",
25-
"wp-cli/wp-cli-tests": "^4"
25+
"wp-cli/wp-cli-tests": "^5"
2626
},
2727
"extra": {
2828
"branch-alias": {
29-
"dev-master": "0.11.x-dev"
29+
"dev-master": "0.12.x-dev"
3030
}
3131
},
3232
"minimum-stability": "dev",
@@ -42,19 +42,22 @@
4242
"config": {
4343
"allow-plugins": {
4444
"dealerdirect/phpcodesniffer-composer-installer": true,
45-
"johnpbloch/wordpress-core-installer": true
45+
"johnpbloch/wordpress-core-installer": true,
46+
"phpstan/extension-installer": true
4647
}
4748
},
4849
"scripts": {
4950
"behat": "run-behat-tests",
5051
"behat-rerun": "rerun-behat-tests",
5152
"lint": "run-linter-tests",
5253
"phpcs": "run-phpcs-tests",
54+
"phpstan": "run-phpstan-tests",
5355
"phpunit": "run-php-unit-tests",
5456
"prepare-tests": "install-package-tests",
5557
"test": [
5658
"@lint",
5759
"@phpcs",
60+
"@phpstan",
5861
"@phpunit",
5962
"@behat"
6063
]

examples/common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
die('Must run from command line');
55
}
66

7-
error_reporting(E_ALL | E_STRICT);
7+
error_reporting(E_ALL);
88
ini_set('display_errors', 1);
99
ini_set('log_errors', 0);
1010
ini_set('html_errors', 0);

lib/cli/Colors.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static public function color($color) {
9292
$colors = array();
9393
foreach (array('color', 'style', 'background') as $type) {
9494
$code = $color[$type];
95-
if (isset(self::$_colors[$type][$code])) {
95+
if (isset($code) && isset(self::$_colors[$type][$code])) {
9696
$colors[] = self::$_colors[$type][$code];
9797
}
9898
}
@@ -147,7 +147,7 @@ static public function colorize($string, $colored = null) {
147147
*/
148148
static public function decolorize( $string, $keep = 0 ) {
149149
$string = (string) $string;
150-
150+
151151
if ( ! ( $keep & 1 ) ) {
152152
// Get rid of color tokens if they exist
153153
$string = str_replace('%%', '', $string);
@@ -214,7 +214,7 @@ static public function width( $string, $pre_colorized = false, $encoding = false
214214
*/
215215
static public function pad( $string, $length, $pre_colorized = false, $encoding = false, $pad_type = STR_PAD_RIGHT ) {
216216
$string = (string) $string;
217-
217+
218218
$real_length = self::width( $string, $pre_colorized, $encoding );
219219
$diff = strlen( $string ) - $real_length;
220220
$length += $diff;

lib/cli/Table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ class Table {
4646
* @param array $rows The rows of data for this table. Optional.
4747
* @param array $footers Footers used in this table. Optional.
4848
*/
49-
public function __construct(array $headers = null, array $rows = null, array $footers = null, $alignments = []) {
49+
public function __construct(array $headers = array(), array $rows = array(), array $footers = array(), $alignments = array()) {
5050
if (!empty($headers)) {
5151
// If all the rows is given in $headers we use the keys from the
5252
// first row for the header values
53-
if ($rows === null) {
53+
if ($rows === array()) {
5454
$rows = $headers;
5555
$keys = array_keys(array_shift($headers));
5656
$headers = array();

lib/cli/table/Ascii.php

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -141,31 +141,32 @@ public function row( array $row ) {
141141
if ( count( $row ) > 0 ) {
142142
$extra_rows = array_fill( 0, count( $row ), array() );
143143

144-
foreach( $row as $col => $value ) {
145-
146-
$value = str_replace( array( "\r\n", "\n" ), ' ', $value );
147-
148-
$col_width = $this->_widths[ $col ];
149-
$encoding = function_exists( 'mb_detect_encoding' ) ? mb_detect_encoding( $value, null, true /*strict*/ ) : false;
144+
foreach ( $row as $col => $value ) {
145+
$value = $value ?: '';
146+
$col_width = $this->_widths[ $col ];
147+
$encoding = function_exists( 'mb_detect_encoding' ) ? mb_detect_encoding( $value, null, true /*strict*/ ) : false;
150148
$original_val_width = Colors::width( $value, self::isPreColorized( $col ), $encoding );
151-
if ( $col_width && $original_val_width > $col_width ) {
152-
$row[ $col ] = \cli\safe_substr( $value, 0, $col_width, true /*is_width*/, $encoding );
153-
$value = \cli\safe_substr( $value, \cli\safe_strlen( $row[ $col ], $encoding ), null /*length*/, false /*is_width*/, $encoding );
154-
$i = 0;
155-
do {
156-
$extra_value = \cli\safe_substr( $value, 0, $col_width, true /*is_width*/, $encoding );
157-
$val_width = Colors::width( $extra_value, self::isPreColorized( $col ), $encoding );
158-
if ( $val_width ) {
159-
$extra_rows[ $col ][] = $extra_value;
160-
$value = \cli\safe_substr( $value, \cli\safe_strlen( $extra_value, $encoding ), null /*length*/, false /*is_width*/, $encoding );
161-
$i++;
162-
if ( $i > $extra_row_count ) {
163-
$extra_row_count = $i;
149+
if ( $col_width && ( $original_val_width > $col_width || strpos( $value, "\n" ) !== false ) ) {
150+
$split_lines = preg_split( '/\r\n|\n/', $value );
151+
152+
$wrapped_lines = [];
153+
foreach ( $split_lines as $line ) {
154+
do {
155+
$wrapped_value = \cli\safe_substr( $line, 0, $col_width, true /*is_width*/, $encoding );
156+
$val_width = Colors::width( $wrapped_value, self::isPreColorized( $col ), $encoding );
157+
if ( $val_width ) {
158+
$wrapped_lines[] = $wrapped_value;
159+
$line = \cli\safe_substr( $line, \cli\safe_strlen( $wrapped_value, $encoding ), null /*length*/, false /*is_width*/, $encoding );
164160
}
165-
}
166-
} while( $value );
167-
}
161+
} while ( $line );
162+
}
168163

164+
$row[ $col ] = array_shift( $wrapped_lines );
165+
foreach ( $wrapped_lines as $wrapped_line ) {
166+
$extra_rows[ $col ][] = $wrapped_line;
167+
++$extra_row_count;
168+
}
169+
}
169170
}
170171
}
171172

@@ -204,7 +205,7 @@ public function row( array $row ) {
204205
private function padColumn($content, $column) {
205206
$column_name = $this->_headers[$column];
206207
$alignment = array_key_exists($column_name, $this->_alignments) ? $this->_alignments[$column_name] : Column::ALIGN_LEFT;
207-
208+
$content = str_replace( "\t", ' ', (string) $content );
208209
return $this->_characters['padding'] . Colors::pad( $content, $this->_widths[ $column ], $this->isPreColorized( $column ), false, $alignment) . $this->_characters['padding'];
209210
}
210211

lib/cli/table/Tabular.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,30 @@ class Tabular extends Renderer {
2222
* @param array $row The table row.
2323
* @return string The formatted table row.
2424
*/
25-
public function row(array $row) {
26-
return implode("\t", array_values($row));
25+
public function row( array $row ) {
26+
$rows = [];
27+
$output = '';
28+
29+
foreach ( $row as $col => $value ) {
30+
$value = isset( $value ) ? (string) $value : '';
31+
$value = str_replace( "\t", ' ', $value );
32+
$split_lines = preg_split( '/\r\n|\n/', $value );
33+
// Keep anything before the first line break on the original line
34+
$row[ $col ] = array_shift( $split_lines );
35+
}
36+
37+
$rows[] = $row;
38+
39+
foreach ( $split_lines as $i => $line ) {
40+
if ( ! isset( $rows[ $i + 1 ] ) ) {
41+
$rows[ $i + 1 ] = array_fill_keys( array_keys( $row ), '' );
42+
}
43+
$rows[ $i + 1 ][ $col ] = $line;
44+
}
45+
46+
foreach ( $rows as $r ) {
47+
$output .= implode( "\t", array_values( $r ) ) . PHP_EOL;
48+
}
49+
return rtrim( $output, PHP_EOL );
2750
}
2851
}

phpunit.xml.dist

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
3-
bootstrap="tests/bootstrap.php"
4-
colors="always"
5-
beStrictAboutTestsThatDoNotTestAnything="true"
6-
beStrictAboutOutputDuringTests="true"
7-
beStrictAboutTestSize="true"
8-
beStrictAboutChangesToGlobalState="false">
9-
<testsuites>
10-
<testsuite>
11-
<directory prefix="spec-" suffix=".php">tests/</directory>
12-
<directory prefix="test-" suffix=".php">tests/</directory>
13-
<directory suffix="Test.php">tests/</directory>
14-
</testsuite>
15-
</testsuites>
2+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/4.8/phpunit.xsd"
3+
bootstrap="tests/bootstrap.php"
4+
backupGlobals="false"
5+
beStrictAboutCoversAnnotation="true"
6+
beStrictAboutOutputDuringTests="true"
7+
beStrictAboutTestsThatDoNotTestAnything="true"
8+
beStrictAboutTodoAnnotatedTests="true"
9+
convertErrorsToExceptions="true"
10+
convertWarningsToExceptions="true"
11+
convertNoticesToExceptions="true"
12+
convertDeprecationsToExceptions="true"
13+
colors="true"
14+
verbose="true">
15+
<testsuite name="wp-cli/php-cli-tools tests">
16+
<directory prefix="Test" suffix=".php">tests/</directory>
17+
</testsuite>
18+
19+
<filter>
20+
<whitelist processUncoveredFilesFromWhitelist="true">
21+
<directory suffix=".php">lib/</directory>
22+
</whitelist>
23+
</filter>
1624
</phpunit>

0 commit comments

Comments
 (0)