Skip to content

Commit a6427bf

Browse files
committed
Update testing
1 parent dd918b0 commit a6427bf

File tree

3 files changed

+35
-30
lines changed

3 files changed

+35
-30
lines changed

behat.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
default:
2+
suites:
3+
default:
4+
contexts:
5+
- WP_CLI\Tests\Context\FeatureContext
6+
paths:
7+
- features

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
"wp-cli/wp-cli": "^2"
1717
},
1818
"require-dev": {
19-
"behat/behat": "~2.5",
20-
"wp-cli/wp-cli-tests": "^2.1",
19+
"wp-cli/wp-cli-tests": "^3",
2120
"wp-cli/scaffold-command": "^2",
2221
"wp-cli/extension-command": "^2"
2322
},
@@ -40,6 +39,7 @@
4039
]
4140
},
4241
"minimum-stability": "dev",
42+
"prefer-stable": true,
4343
"scripts": {
4444
"behat": "run-behat-tests",
4545
"lint": "run-linter-tests",

src/Dist_Archive_Command.php

+26-28
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ public function __invoke( $args, $assoc_args ) {
9595
$version = '';
9696
foreach ( glob( $path . '/*.php' ) as $php_file ) {
9797
$contents = file_get_contents( $php_file, false, null, 0, 5000 );
98-
$version = $this->get_version_in_code($contents);
99-
if( ! empty( $version ) ) {
100-
$version = '.' . trim($version);
98+
$version = $this->get_version_in_code( $contents );
99+
if ( ! empty( $version ) ) {
100+
$version = '.' . trim( $version );
101101
break;
102102
}
103103
}
@@ -216,20 +216,18 @@ private function maybe_create_directory( $archive_file ) {
216216
* @param string $code_str the source code string to look into
217217
* @return null|string the version string
218218
*/
219-
220-
private static function get_version_in_code($code_str)
221-
{
219+
private static function get_version_in_code( $code_str ) {
222220
$tokens = array_values(
223221
array_filter(
224-
token_get_all($code_str),
225-
function ($token) {
226-
return !is_array($token) || $token[0] !== T_WHITESPACE;
222+
token_get_all( $code_str ),
223+
function ( $token ) {
224+
return ! is_array( $token ) || T_WHITESPACE !== $token[0];
227225
}
228226
)
229227
);
230228
foreach ( $tokens as $token ) {
231-
if ( $token[0] == T_DOC_COMMENT ) {
232-
$version = self::get_version_in_docblock($token[1]);
229+
if ( T_DOC_COMMENT === $token[0] ) {
230+
$version = self::get_version_in_docblock( $token[1] );
233231
if ( null !== $version ) {
234232
return $version;
235233
}
@@ -244,10 +242,9 @@ function ($token) {
244242
* @param string $docblock
245243
* @return null|string The content of the version tag
246244
*/
247-
private static function get_version_in_docblock($docblock)
248-
{
249-
$docblocktags = self::parse_doc_block($docblock);
250-
if ( isset($docblocktags['version'] ) ) {
245+
private static function get_version_in_docblock( $docblock ) {
246+
$docblocktags = self::parse_doc_block( $docblock );
247+
if ( isset( $docblocktags['version'] ) ) {
251248
return $docblocktags['version'];
252249
}
253250
return null;
@@ -264,23 +261,24 @@ private static function get_version_in_docblock($docblock)
264261
* @param string $docblock
265262
* @return array
266263
*/
267-
private static function parse_doc_block($docblock): array
268-
{
264+
private static function parse_doc_block( $docblock ) {
269265
$tag_documentor = '{@([a-zA-Z0-9-_\\\]+)\s*?(.*)?}';
270-
$tag_property = '{\s*\*?\s*(.*?)\:(.*)}';
271-
$lines = explode(PHP_EOL, $docblock);
272-
$tags = [];
273-
$prose = [];
274-
foreach ($lines as $line) {
275-
if (0 === preg_match($tag_documentor, $line, $matches)) {
276-
if (0 === preg_match($tag_property, $line, $matches)) {
266+
$tag_property = '{\s*\*?\s*(.*?):(.*)}';
267+
$lines = explode( PHP_EOL, $docblock );
268+
$tags = [];
269+
270+
foreach ( $lines as $line ) {
271+
if ( 0 === preg_match( $tag_documentor, $line, $matches ) ) {
272+
if ( 0 === preg_match( $tag_property, $line, $matches ) ) {
277273
continue;
278274
}
279275
}
280-
$tagName = strtolower($matches[1]);
281-
$metadata = trim($matches[2] ?? '');
282-
$tags[$tagName] = $metadata;
276+
277+
$tag_name = strtolower( $matches[1] );
278+
$metadata = trim( isset( $matches[2] ) ? $matches[2] : '' );
279+
280+
$tags[ $tag_name ] = $metadata;
283281
}
284282
return $tags;
285-
}
283+
}
286284
}

0 commit comments

Comments
 (0)