Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imrpove array syntax and visible method name #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
language: php

php:
- 5.6
- 7.0
- 7.1

- 7.2
- 7.3
- 7.4

before_script:
- composer self-update
- composer install --prefer-source --no-interaction --dev
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove --dev to avoid following message:

You are using the deprecated option "dev". Dev packages are installed by default now.

- composer install --prefer-source --no-interaction

script: vendor/bin/phpunit
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@
"php": ">=5.6.0"
},
"require-dev": {
"phpunit/phpunit": ">=5.5.0",
"mikey179/vfsStream": "~1"
"phpunit/phpunit": "^5.5",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • To avoid latest PHPUnit version installed and unexpected issues, it should let PHPUnit install with 5.5.x versions.

To fix following message, it should be mikey179/vfsstream.

Deprecation warning: require-dev.mikey179/vfsStream is invalid, it should not contain uppercase characters. Please use mikey179/vfsstream instead. Make sure you fix this as Composer 2.0 will error.

"mikey179/vfsstream": "~1"
},
"autoload": {
"psr-4": {
"TryLib\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"tests\\phpunit\\": "tests/"
}
}
}
10 changes: 5 additions & 5 deletions src/JenkinsRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function __construct(
$this->try_job_name = $try_job_name;
$this->cmd_runner = $cmd_runner;

$this->options = array();
$this->callbacks = array();
$this->options = [];
$this->callbacks = [];
$this->ssh_key_path = null;
$this->branch = null;
$this->try_status = '';
Expand Down Expand Up @@ -127,7 +127,7 @@ public function getCallbacks() {
* Build the Jenkins CLI command, based on all options
*/
function buildCLICommand($show_results, $show_progress) {
$command = array();
$command = [];

if (!is_null($this->getSsKey())) {
$command[] = '-i ' . $this->getSsKey();
Expand All @@ -153,8 +153,8 @@ function executeCallbacks() {

function executeCallback($callback) {
$callback = str_replace(
array('${status}', '${url}'),
array($this->try_status, $this->try_base_url),
['${status}', '${url}'],
[$this->try_status, $this->try_base_url],
$callback
);
$this->cmd_runner->run($callback, false, true);
Expand Down
2 changes: 1 addition & 1 deletion src/JenkinsRunner/FreeStyleProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function getBuildCommand() {
}

public function getBuildExtraArguments($show_results, $show_progress) {
$args = array();
$args = [];

if ($show_results || $show_progress) {
$args[] = '-s';
Expand Down
6 changes: 3 additions & 3 deletions src/JenkinsRunner/MasterProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public function __construct(
$cmd_runner
);

$this->jobs = array();
$this->excluded_jobs = array();
$this->jobs = [];
$this->excluded_jobs = [];

try {
$this->colors = new AnsiColor();
Expand Down Expand Up @@ -58,7 +58,7 @@ public function setExcludedSubJobs($jobs) {
}

public function getJobsList() {
$tryjobs = array();
$tryjobs = [];
foreach ($this->jobs as $job) {
if ( !in_array($job, $this->excluded_jobs)) {
$tryjobs[] = $this->try_job_prefix . '-' . $job;
Expand Down
4 changes: 2 additions & 2 deletions src/Precheck/GitWarnOnBlocklisted.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GitWarnOnBlocklisted implements Precheck {
protected $staged;

function __construct(array $blocklist, $safelist = null, $staged = false) {
$this->safelist = $safelist ?: array();
$this->safelist = $safelist ?: [];
$this->blocklist = array_diff($blocklist, $this->safelist);
$this->staged = $staged;
}
Expand All @@ -40,7 +40,7 @@ function check($cmd_runner, $repo_path, $upstream) {

$changed_files = $cmd_runner->getOutput();

$blocklisted_changed_files = array();
$blocklisted_changed_files = [];

foreach (explode(PHP_EOL, $changed_files) as $file) {
if (in_array($file, $this->blocklist)) {
Expand Down
4 changes: 2 additions & 2 deletions src/RepoManager/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ function getUpstream() {
function generateDiff($staged_only = false, $safelist = null, $lines_of_context = false) {
$patch = $this->repo_path . "/patch.diff";

$args = array(
$args = [
"--binary",
"--no-color",
$this->getUpstream(),
);
];

if ($staged_only) {
$args[] = "--staged";
Expand Down
6 changes: 3 additions & 3 deletions src/TryRunner/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public function __construct(
$this->repo_manager = self::requireArg($repo_manager);
$this->jenkins_runner = self::requireArg($jenkins_runner);
$this->jenkins_cli_jar_path = self::requireArg($jenkins_cli_jar_path);
$this->safelisted_files = $safelisted_files ?: array();
$this->safelisted_files = $safelisted_files ?: [];
$this->override_user = $override_user ?: getenv("USER");
$this->prechecks = $prechecks ?: array();
$this->prechecks = $prechecks ?: [];
$this->options_tuple = self::requireArg($options_tuple);
$this->ssh_key_path = $ssh_key_path;
$this->patch = null;
Expand Down Expand Up @@ -58,7 +58,7 @@ public function getPatchLocation() {
if ($options->safelist) {
$safelist = $options->safelist;
if (is_string($safelist)) {
$safelist = array($safelist);
$safelist = [$safelist];
}
} else {
$safelist = $this->safelisted_files;
Expand Down
8 changes: 4 additions & 4 deletions src/Util/AnsiColor.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct() {
}
}

private $color_opts = array(
private $color_opts = [
'black' => '30',
'red' => '31',
'green' => '32',
Expand All @@ -58,14 +58,14 @@ public function __construct() {
'ipurple' => '95',
'icyan' => '96',
'iwhite' => '97',
);
];

private $text_opts = array(
private $text_opts = [
'bold' => '1',
'underline' => '4',
'blink' => '5',
'reverse' => '7',
);
];

private $seq = '';

Expand Down
2 changes: 1 addition & 1 deletion src/Util/OptionsUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static function parseParam($param) {
* and return an array of key->value
*/
public static function parseExtraParameters($extra_param_option) {
$params = array();
$params = [];
if (is_string($extra_param_option)) {
$params[] = self::parseParam($extra_param_option);
} elseif (is_array($extra_param_option)) {
Expand Down
64 changes: 32 additions & 32 deletions src/Util/PHPOptions/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ function _endswith($haystack, $needle) {

function _remove_negative_kv($k, $v) {
if ( _startswith($k, 'no-') || _startswith($k, 'no_') )
return array(substr($k, 3), ! $v);
return array($k,$v);
return [substr($k, 3), ! $v];
return [$k,$v];
}


Expand All @@ -131,11 +131,11 @@ function _remove_negative_kv($k, $v) {
environment variable POSIXLY_CORRECT is set, then option
processing stops as soon as a non-option argument is encountered.
**/
function _gnu_getopt($args, $shortopts, $longopts=array()) {
$opts = array();
$prog_args = array();
function _gnu_getopt($args, $shortopts, $longopts=[]) {
$opts = [];
$prog_args = [];
if (is_string($longopts))
$longopts = array($longopts);
$longopts = [$longopts];

// Allow options after non-option arguments?
if (_startswith($shortopts, '+')) {
Expand Down Expand Up @@ -173,7 +173,7 @@ function _gnu_getopt($args, $shortopts, $longopts=array()) {
}
}

return array($opts, $prog_args);
return [$opts, $prog_args];
}

class GetoptError extends Exception { }
Expand All @@ -198,22 +198,22 @@ function _getopt_do_longs($opts, $opt, $longopts, $args) {
} elseif ($optarg !== Null) {
throw new GetoptError("option --$opt must not have an argument");
}
array_push($opts,array('--' . $opt, $optarg ? $optarg : ''));
return array($opts, $args);
array_push($opts,['--' . $opt, $optarg ? $optarg : '']);
return [$opts, $args];
}

function _getopt_long_has_args($opt, $longopts) {
$possibilities = array();
$possibilities = [];
foreach ($longopts as $o)
if (_startswith($o,$opt))
array_push($possibilities,$o);
if (! count($possibilities))
throw new GetoptError("option --$opt not recognized");
// Is there an exact match?
if (in_array($opt, $possibilities))
return array(False, $opt);
return [False, $opt];
elseif (in_array($opt . '=', $possibilities))
return array(True, $opt);
return [True, $opt];
// No exact match, so better be unique.
if (count($possibilities) > 1)
throw new GetoptError("option --$opt not a unique prefix");
Expand All @@ -222,7 +222,7 @@ function _getopt_long_has_args($opt, $longopts) {
$has_arg = _endswith($unique_match,'=');
if ($has_arg)
$unique_match = substr($unique_match,0,-1);
return array($has_arg, $unique_match);
return [$has_arg, $unique_match];
}

function _getopt_do_shorts($opts, $optstring, $shortopts, $args) {
Expand All @@ -241,9 +241,9 @@ function _getopt_do_shorts($opts, $optstring, $shortopts, $args) {
} else {
$optarg = '';
}
array_push($opts,array('-' . $opt, $optarg));
array_push($opts,['-' . $opt, $optarg]);
}
return array($opts, $args);
return [$opts, $args];
}

function _getopt_short_has_arg($opt, $shortopts) {
Expand All @@ -266,8 +266,8 @@ class OptDict extends ArrayObject {
private $_aliases;

public function __construct($aliases) {
parent::__construct(array(), ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
$this->_opts = array();
parent::__construct([], ArrayObject::STD_PROP_LIST | ArrayObject::ARRAY_AS_PROPS);
$this->_opts = [];
$this->_aliases = $aliases;
}

Expand All @@ -277,7 +277,7 @@ public function _unalias($k) {
if (! array_key_exists($k, $this->_aliases))
throw new Exception("KeyError: Option '$k' is unknown.");
list($k, $invert) = $this->_aliases[$k];
return array($k, $invert xor $reinvert);
return [$k, $invert xor $reinvert];
}

public function offsetSet($k, $v) {
Expand Down Expand Up @@ -361,16 +361,16 @@ public function __construct($optspec, $optfunc='TryLib\Util\PHPOptions\_gnu_geto
$this->optspec = $optspec;
$this->_onabort = $onabort;
$this->optfunc = $optfunc;
$this->_aliases = array();
$this->_aliases = [];
$this->_shortopts = 'h?';
$this->_longopts = array('help', 'usage');
$this->_hasparms = array();
$this->_defaults = array();
$this->_longopts = ['help', 'usage'];
$this->_hasparms = [];
$this->_defaults = [];
$this->_usagestr = $this->_gen_usage(); // this also parses the optspec
}

private function _gen_usage() {
$out = array();
$out = [];
$lines = explode("\n", trim($this->optspec));
$lines = array_reverse($lines);
$first_syn = True;
Expand Down Expand Up @@ -399,19 +399,19 @@ private function _gen_usage() {
} else {
$has_parm = 0;
}
$g = array();
$g = [];
$gr = preg_match('/\[([^\]]*)\]$/', $extra, $g);
if ($gr)
$defval = _intify($g[1]);
else
$defval = Null;
$flagl = explode(',', $flags);
$flagl_nice = array();
$flagl_nice = [];
list($flag_main, $invert_main) = _remove_negative_kv($flagl[0], False);
$this->_defaults[$flag_main] = _invert($defval, $invert_main);
foreach ($flagl as $_f) {
list($f,$invert) = _remove_negative_kv($_f, 0);
$this->_aliases[$f] = array($flag_main, $invert_main xor $invert);
$this->_aliases[$f] = [$flag_main, $invert_main xor $invert];
$this->_hasparms[$f] = $has_parm;
if ($f == '#') {
$this->_shortopts .= '0123456789';
Expand All @@ -421,8 +421,8 @@ private function _gen_usage() {
array_push($flagl_nice, '-' . $f);
} else {
$f_nice = preg_replace('/\W/', '_', $f);
$this->_aliases[$f_nice] = array($flag_main,
$invert_main xor $invert);
$this->_aliases[$f_nice] = [$flag_main,
$invert_main xor $invert];
array_push($this->_longopts, $f . ($has_parm ? '=' : ''));
array_push($this->_longopts, 'no-' . $f);
array_push($flagl_nice, '--' . $_f);
Expand Down Expand Up @@ -490,10 +490,10 @@ public function parse($args) {
foreach ($flags as $f) {
$k = ltrim($f[0],'-');
$v = $f[1];
if (in_array($k, array('h', '?', 'help', 'usage')))
if (in_array($k, ['h', '?', 'help', 'usage']))
$this->usage();
if (array_key_exists('#', $this->_aliases) &&
in_array($k, array('0','1','2','3','4','5','6','7','8','9'))) {
in_array($k, ['0','1','2','3','4','5','6','7','8','9'])) {
$v = _atoi($k); # guaranteed to be exactly one digit
list($k, $invert) = $this->_aliases['#'];
$opt['#'] = $v;
Expand All @@ -512,14 +512,14 @@ public function parse($args) {
$val = _invert($v, $invert);
if ( $opt[$k] != $this->_defaults[$k]) {
if (! is_array($opt[$k])) {
$opt[$k] = array($opt[$k], $val);
$opt[$k] = [$opt[$k], $val];
} else {
$opt[$k] = array_merge($opt[$k],[$val]);
}
} else {
$opt[$k] = $val;
}
}
return array($opt,$flags,$extra);
return [$opt,$flags,$extra];
}
}
Loading