Skip to content

Commit 7083b07

Browse files
committed
Fix remaining PHPCS issues
1 parent 1545f7d commit 7083b07

File tree

7 files changed

+65
-43
lines changed

7 files changed

+65
-43
lines changed

phpcs.xml.dist

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
2-
<ruleset name="WP-CLI-shell">
3-
<description>Custom ruleset for WP-CLI-shell-command</description>
2+
<ruleset name="WP-CLI-bundle">
3+
<description>Custom ruleset for WP-CLI-bundle</description>
44

55
<!--
66
#############################################################################
@@ -57,9 +57,15 @@
5757
#############################################################################
5858
-->
5959

60-
<!-- Exclude existing classes from the prefix rule as it would break BC to prefix them now. -->
61-
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound">
62-
<exclude-pattern>*/src/Shell_Command\.php$</exclude-pattern>
60+
<!-- This is a procedural stand-alone file that is never loaded in a WordPress context,
61+
so this file does not have to comply with WP naming conventions. -->
62+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
63+
<exclude-pattern>*/utils/get-package-require-from-composer\.php$</exclude-pattern>
64+
<exclude-pattern>*/utils/make-phar\.php$</exclude-pattern>
65+
</rule>
66+
<rule ref="WordPress.WP.GlobalVariablesOverride">
67+
<exclude-pattern>*/utils/get-package-require-from-composer\.php$</exclude-pattern>
68+
<exclude-pattern>*/utils/make-phar\.php$</exclude-pattern>
6369
</rule>
6470

6571
</ruleset>

utils/maintenance-bootstrap.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
22

3-
$autoloader = dirname( __DIR__ ) . '/vendor/autoload.php';
4-
require_once $autoloader;
3+
$wpcli_maintenance_autoloader = dirname( __DIR__ ) . '/vendor/autoload.php';
4+
if ( is_readable( $wpcli_maintenance_autoloader ) ) {
5+
require_once $wpcli_maintenance_autoloader;
6+
}
57

68
WP_CLI::add_command( 'contrib-list', 'WP_CLI\Maintenance\Contrib_list_Command' );
79
WP_CLI::add_command( 'milestones-after', 'WP_CLI\Maintenance\Milestones_After_Command' );

utils/maintenance/Contrib_List_Command.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ final class Contrib_List_Command {
2525
*/
2626
public function __invoke( $_, $assoc_args ) {
2727

28-
$contributors = array();
28+
$contributors = [];
2929
$pull_request_count = 0;
3030

3131
// Get the contributors to the current open large project milestones
32-
foreach ( array( 'wp-cli/wp-cli-bundle', 'wp-cli/wp-cli', 'wp-cli/handbook', 'wp-cli/wp-cli.github.com' ) as $repo ) {
32+
foreach ( [ 'wp-cli/wp-cli-bundle', 'wp-cli/wp-cli', 'wp-cli/handbook', 'wp-cli/wp-cli.github.com' ] as $repo ) {
3333
$milestones = GitHub::get_project_milestones( $repo );
3434
// Cheap way to get the latest milestone
3535
$milestone = array_shift( $milestones );
@@ -50,7 +50,7 @@ public function __invoke( $_, $assoc_args ) {
5050
// TODO: Bundle repo needs to be switched to `wp-cli/wp-cli-bundle` for next release.
5151
$bundle = 'wp-cli/wp-cli';
5252

53-
$milestones = GitHub::get_project_milestones( 'wp-cli/wp-cli', array( 'state' => 'closed' ) );
53+
$milestones = GitHub::get_project_milestones( 'wp-cli/wp-cli', [ 'state' => 'closed' ] );
5454
// Cheap way to get the latest closed milestone
5555
$milestone = array_shift( $milestones );
5656
$tag = is_object( $milestone ) ? "v{$milestone->title}" : 'master';
@@ -99,7 +99,7 @@ function ( $a, $b ) {
9999
continue;
100100
}
101101
// Closed milestones denote a tagged release
102-
$milestones = GitHub::get_project_milestones( $package_name, array( 'state' => 'closed' ) );
102+
$milestones = GitHub::get_project_milestones( $package_name, [ 'state' => 'closed' ] );
103103
$milestone_ids = array();
104104
$milestone_titles = array();
105105
foreach ( $milestones as $milestone ) {
@@ -129,7 +129,7 @@ function ( $a, $b ) {
129129

130130
// Sort and render the contributor list
131131
asort( $contributors, SORT_NATURAL | SORT_FLAG_CASE );
132-
if ( in_array( $assoc_args['format'], array( 'markdown', 'html' ) ) ) {
132+
if ( in_array( $assoc_args['format'], [ 'markdown', 'html' ], true ) ) {
133133
$contrib_list = '';
134134
foreach ( $contributors as $url => $login ) {
135135
if ( 'markdown' === $assoc_args['format'] ) {

utils/maintenance/GitHub.php

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class GitHub {
1616
*/
1717
public static function get_project_milestones(
1818
$project,
19-
$args = array()
19+
$args = []
2020
) {
2121
$request_url = sprintf(
2222
self::API_ROOT . 'repos/%s/milestones',
@@ -42,7 +42,7 @@ public static function get_project_milestones(
4242
public static function get_release_by_tag(
4343
$project,
4444
$tag,
45-
$args = array()
45+
$args = []
4646
) {
4747
$request_url = sprintf(
4848
self::API_ROOT . 'repos/%s/releases/tags/%s',
@@ -69,7 +69,7 @@ public static function get_release_by_tag(
6969
public static function get_issues_by_label(
7070
$project,
7171
$label,
72-
$args = array()
72+
$args = []
7373
) {
7474
$request_url = sprintf(
7575
self::API_ROOT . 'repos/%s/issues',
@@ -98,7 +98,7 @@ public static function remove_label(
9898
$project,
9999
$issue,
100100
$label,
101-
$args = array()
101+
$args = []
102102
) {
103103
$request_url = sprintf(
104104
self::API_ROOT . 'repos/%s/issues/%s/labels/%s',
@@ -132,7 +132,7 @@ public static function add_label(
132132
$project,
133133
$issue,
134134
$label,
135-
$args = array()
135+
$args = []
136136
) {
137137
$request_url = sprintf(
138138
self::API_ROOT . 'repos/%s/issues/%s/labels',
@@ -143,7 +143,7 @@ public static function add_label(
143143

144144
$headers['http_verb'] = 'POST';
145145

146-
$args = array( $label );
146+
$args = [ $label ];
147147

148148
list( $body, $headers ) = self::request(
149149
$request_url,
@@ -166,7 +166,7 @@ public static function add_label(
166166
public static function delete_label(
167167
$project,
168168
$label,
169-
$args = array()
169+
$args = []
170170
) {
171171
$request_url = sprintf(
172172
self::API_ROOT . 'repos/%s/labels/%s',
@@ -198,21 +198,21 @@ public static function get_project_milestone_pull_requests(
198198
$project
199199
);
200200

201-
$args = array(
201+
$args = [
202202
'per_page' => 100,
203203
'milestone' => $milestone_id,
204204
'state' => 'all',
205-
);
205+
];
206206

207-
$pull_requests = array();
207+
$pull_requests = [];
208208
do {
209209
list( $body, $headers ) = self::request( $request_url, $args );
210210
foreach ( $body as $issue ) {
211211
if ( ! empty( $issue->pull_request ) ) {
212212
$pull_requests[] = $issue;
213213
}
214214
}
215-
$args = array();
215+
$args = [];
216216
$request_url = false;
217217
// Set $request_url to 'rel="next" if present'
218218
if ( ! empty( $headers['Link'] ) ) {
@@ -240,7 +240,7 @@ public static function get_project_milestone_pull_requests(
240240
public static function parse_contributors_from_pull_requests(
241241
$pull_requests
242242
) {
243-
$contributors = array();
243+
$contributors = [];
244244
foreach ( $pull_requests as $pull_request ) {
245245
if ( ! empty( $pull_request->user ) ) {
246246
$contributors[ $pull_request->user->html_url ] = $pull_request->user->login;
@@ -261,17 +261,19 @@ public static function parse_contributors_from_pull_requests(
261261
*/
262262
public static function request(
263263
$url,
264-
$args = array(),
265-
$headers = array()
264+
$args = [],
265+
$headers = []
266266
) {
267267
$headers = array_merge(
268268
$headers,
269-
array(
269+
[
270270
'Accept' => 'application/vnd.github.v3+json',
271271
'User-Agent' => 'WP-CLI',
272-
)
272+
]
273273
);
274-
if ( $token = getenv( 'GITHUB_TOKEN' ) ) {
274+
275+
$token = getenv( 'GITHUB_TOKEN' );
276+
if ( $token ) {
275277
$headers['Authorization'] = 'token ' . $token;
276278
}
277279

@@ -287,7 +289,7 @@ public static function request(
287289

288290
$response = Utils\http_request( $verb, $url, $args, $headers );
289291

290-
if ( 20 != substr( $response->status_code, 0, 2 ) ) {
292+
if ( 20 !== absint( substr( $response->status_code, 0, 2 ) ) ) {
291293
if ( isset( $args['throw_errors'] ) && false === $args['throw_errors'] ) {
292294
return false;
293295
}
@@ -301,6 +303,6 @@ public static function request(
301303
);
302304
}
303305

304-
return array( json_decode( $response->body ), $response->headers );
306+
return [ json_decode( $response->body ), $response->headers ];
305307
}
306308
}

utils/maintenance/Release_Date_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __invoke( $args, $assoc_args ) {
2828

2929
$release = GitHub::get_release_by_tag(
3030
$repo,
31-
0 === strpos( $milestone_name, 'v' )
31+
strpos( $milestone_name, 'v' ) === 0
3232
? $milestone_name
3333
: "v{$milestone_name}",
3434
array( 'state' => 'all' )

utils/maintenance/Release_Notes_Command.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ private function get_repo_release_notes(
248248
}
249249

250250
WP_CLI::warning( "Release notes not found for {$repo}@{$tag}, falling back to pull-request source" );
251+
// Fall-through is intentional here.
251252
case 'pull-request':
252253
$pull_requests = GitHub::get_project_milestone_pull_requests(
253254
$repo,
@@ -266,7 +267,7 @@ private function get_repo_release_notes(
266267
}
267268
}
268269

269-
$template = $format === 'html' ? '<ul>%s</ul>' : '%s';
270+
$template = 'html' === $format ? '<ul>%s</ul>' : '%s';
270271

271272
WP_CLI::log( sprintf( $template, implode( '', $entries ) ) );
272273
}
@@ -275,7 +276,7 @@ private function get_pull_request_reference(
275276
$pull_request,
276277
$format
277278
) {
278-
$template = $format === 'html' ?
279+
$template = 'html' === $format ?
279280
'<li>%1$s [<a href="%3$s">#%2$d</a>]</li>' :
280281
'- %1$s [[#%2$d](%3$s)]' . PHP_EOL;
281282

utils/make-phar.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,24 @@ function add_file( $phar, $path ) {
6363
static $strip_res = null;
6464
if ( null === $strip_res ) {
6565
if ( 'cli' === BUILD ) {
66-
$strips = array(
66+
$strips = [
6767
'\/(?:behat|composer|gherkin)\/src\/',
6868
'\/phpunit\/',
6969
'\/nb\/oxymel\/',
7070
'-command\/src\/',
7171
'\/wp-cli\/[^\n]+?-command\/',
7272
'\/symfony\/(?!finder|polyfill-mbstring|process)\'',
7373
'\/(?:dealerdirect|squizlabs|wimg)\/',
74-
);
74+
];
7575
} else {
76-
$strips = array(
76+
$strips = [
7777
'\/(?:behat|gherkin)\/src\/',
7878
'\/phpunit\/',
7979
'\/symfony\/(?!console|filesystem|finder|polyfill-mbstring|process)\'',
8080
'\/composer\/spdx-licenses\/',
8181
'\/Composer\/(?:Command\/|Compiler\.php|Console\/|Downloader\/Pear|Installer\/Pear|Question\/|Repository\/Pear|SelfUpdate\/)',
8282
'\/(?:dealerdirect|squizlabs|wimg)\/',
83-
);
83+
];
8484
}
8585
$strip_res = array_map(
8686
function ( $v ) {
@@ -107,19 +107,30 @@ function set_file_contents( $phar, $path, $content ) {
107107

108108
function get_composer_versions( $current_version ) {
109109
$composer_lock_path = WP_CLI_BUNDLE_ROOT . '/composer.lock';
110-
if ( ! ( $get_composer_lock = file_get_contents( $composer_lock_path ) ) || ! ( $composer_lock = json_decode( $get_composer_lock, true ) ) ) {
110+
$composer_lock_file = file_get_contents( $composer_lock_path );
111+
if ( ! $composer_lock_file ) {
111112
fwrite( STDERR, sprintf( "Warning: Failed to read '%s'." . PHP_EOL, $composer_lock_path ) );
112113
return '';
113114
}
115+
116+
$composer_lock = json_decode( $composer_lock_file, true );
117+
if ( ! $composer_lock ) {
118+
fwrite( STDERR, sprintf( "Warning: Could not decode '%s'." . PHP_EOL, $composer_lock_path ) );
119+
return '';
120+
}
121+
114122
if ( ! isset( $composer_lock['packages'] ) ) {
115123
fwrite( STDERR, sprintf( "Warning: No packages in '%s'." . PHP_EOL, $composer_lock_path ) );
116124
return '';
117125
}
118-
$vendor_versions = array( implode( ' ', array( 'wp-cli/wp-cli', $current_version, date( 'c' ) ) ) );
119-
$missing_names = $missing_versions = $missing_references = 0;
126+
127+
$vendor_versions = [ implode( ' ', [ 'wp-cli/wp-cli', $current_version, date( 'c' ) ] ) ];
128+
$missing_names = 0;
129+
$missing_versions = 0;
130+
$missing_references = 0;
120131
foreach ( $composer_lock['packages'] as $package ) {
121132
if ( isset( $package['name'] ) ) {
122-
$vendor_version = array( $package['name'] );
133+
$vendor_version = [ $package['name'] ];
123134
if ( isset( $package['version'] ) ) {
124135
$vendor_version[] = $package['version'];
125136
} else {
@@ -136,7 +147,7 @@ function get_composer_versions( $current_version ) {
136147
}
137148
$vendor_versions[] = implode( ' ', $vendor_version );
138149
} else {
139-
$vendor_versions[] = implode( ' ', array( 'unknown_package', 'unknown_version', 'unknown_reference' ) );
150+
$vendor_versions[] = implode( ' ', [ 'unknown_package', 'unknown_version', 'unknown_reference' ] );
140151
$missing_names++;
141152
}
142153
}

0 commit comments

Comments
 (0)