Skip to content

Commit 2a1e318

Browse files
committed
Merge branch 'master' into patch-2
2 parents f492746 + a98408c commit 2a1e318

21 files changed

Lines changed: 190 additions & 116 deletions

.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 & 7 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,22 +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": {
49-
"post-install-cmd": [
50-
"./utils/git-setup-pre-commit-hook"
51-
],
5250
"behat": "run-behat-tests",
5351
"behat-rerun": "rerun-behat-tests",
5452
"lint": "run-linter-tests",
5553
"phpcs": "run-phpcs-tests",
54+
"phpstan": "run-phpstan-tests",
5655
"phpunit": "run-php-unit-tests",
5756
"prepare-tests": "install-package-tests",
5857
"test": [
5958
"@lint",
6059
"@phpcs",
60+
"@phpstan",
6161
"@phpunit",
6262
"@behat"
6363
]

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: 10 additions & 6 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
}
@@ -108,9 +108,9 @@ static public function color($color) {
108108
* Colorize a string using helpful string formatters. If the `Streams::$out` points to a TTY coloring will be enabled,
109109
* otherwise disabled. You can control this check with the `$colored` parameter.
110110
*
111-
* @param string $string
111+
* @param string $string
112112
* @param boolean $colored Force enable or disable the colorized output. If left as `null` the TTY will control coloring.
113-
* @return string
113+
* @return string
114114
*/
115115
static public function colorize($string, $colored = null) {
116116
$passed = $string;
@@ -146,6 +146,8 @@ static public function colorize($string, $colored = null) {
146146
* @return string A string with color information removed.
147147
*/
148148
static public function decolorize( $string, $keep = 0 ) {
149+
$string = (string) $string;
150+
149151
if ( ! ( $keep & 1 ) ) {
150152
// Get rid of color tokens if they exist
151153
$string = str_replace('%%', '', $string);
@@ -182,7 +184,7 @@ static public function cacheString( $passed, $colorized, $deprecated = null ) {
182184
* Return the length of the string without color codes.
183185
*
184186
* @param string $string the string to measure
185-
* @return int
187+
* @return int
186188
*/
187189
static public function length($string) {
188190
return safe_strlen( self::decolorize( $string ) );
@@ -194,7 +196,7 @@ static public function length($string) {
194196
* @param string $string The string to measure.
195197
* @param bool $pre_colorized Optional. Set if the string is pre-colorized. Default false.
196198
* @param string|bool $encoding Optional. The encoding of the string. Default false.
197-
* @return int
199+
* @return int
198200
*/
199201
static public function width( $string, $pre_colorized = false, $encoding = false ) {
200202
return strwidth( $pre_colorized || self::shouldColorize() ? self::decolorize( $string, $pre_colorized ? 1 /*keep_tokens*/ : 0 ) : $string, $encoding );
@@ -208,9 +210,11 @@ static public function width( $string, $pre_colorized = false, $encoding = false
208210
* @param bool $pre_colorized Optional. Set if the string is pre-colorized. Default false.
209211
* @param string|bool $encoding Optional. The encoding of the string. Default false.
210212
* @param int $pad_type Optional. Can be STR_PAD_RIGHT, STR_PAD_LEFT, or STR_PAD_BOTH. If pad_type is not specified it is assumed to be STR_PAD_RIGHT.
211-
* @return string
213+
* @return string
212214
*/
213215
static public function pad( $string, $length, $pre_colorized = false, $encoding = false, $pad_type = STR_PAD_RIGHT ) {
216+
$string = (string) $string;
217+
214218
$real_length = self::width( $string, $pre_colorized, $encoding );
215219
$diff = strlen( $string ) - $real_length;
216220
$length += $diff;

lib/cli/Notify.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ abstract class Notify {
3030
protected $_message;
3131
protected $_start;
3232
protected $_timer;
33+
protected $_tick;
34+
protected $_iteration = 0;
35+
protected $_speed = 0;
3336

3437
/**
3538
* Instatiates a Notification object.
@@ -92,23 +95,21 @@ public function elapsed() {
9295
* @return int The number of ticks performed in 1 second.
9396
*/
9497
public function speed() {
95-
static $tick, $iteration = 0, $speed = 0;
96-
9798
if (!$this->_start) {
9899
return 0;
99-
} else if (!$tick) {
100-
$tick = $this->_start;
100+
} else if (!$this->_tick) {
101+
$this->_tick = $this->_start;
101102
}
102103

103104
$now = microtime(true);
104-
$span = $now - $tick;
105+
$span = $now - $this->_tick;
105106
if ($span > 1) {
106-
$iteration++;
107-
$tick = $now;
108-
$speed = ($this->_current / $iteration) / $span;
107+
$this->_iteration++;
108+
$this->_tick = $now;
109+
$this->_speed = ($this->_current / $this->_iteration) / $span;
109110
}
110111

111-
return $speed;
112+
return $this->_speed;
112113
}
113114

114115
/**

lib/cli/Streams.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public static function input( $format = null, $hide = false ) {
160160
* @return string The users input.
161161
* @see cli\input()
162162
*/
163-
public static function prompt( $question, $default = null, $marker = ': ', $hide = false ) {
163+
public static function prompt( $question, $default = false, $marker = ': ', $hide = false ) {
164164
if( $default && strpos( $question, '[' ) === false ) {
165165
$question .= ' [' . $default . ']';
166166
}

lib/cli/Table.php

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

lib/cli/arguments/HelpScreen.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
*/
2020
class HelpScreen {
2121
protected $_flags = array();
22-
protected $_maxFlag = 0;
22+
protected $_flagMax = 0;
2323
protected $_options = array();
24-
protected $_maxOption = 0;
24+
protected $_optionMax = 0;
2525

2626
public function __construct(Arguments $arguments) {
2727
$this->setArguments($arguments);

0 commit comments

Comments
 (0)