@@ -95,9 +95,9 @@ public function __invoke( $args, $assoc_args ) {
95
95
$ version = '' ;
96
96
foreach ( glob ( $ path . '/*.php ' ) as $ php_file ) {
97
97
$ 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 );
101
101
break ;
102
102
}
103
103
}
@@ -216,20 +216,18 @@ private function maybe_create_directory( $archive_file ) {
216
216
* @param string $code_str the source code string to look into
217
217
* @return null|string the version string
218
218
*/
219
-
220
- private static function get_version_in_code ($ code_str )
221
- {
219
+ private static function get_version_in_code ( $ code_str ) {
222
220
$ tokens = array_values (
223
221
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 ] ;
227
225
}
228
226
)
229
227
);
230
228
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 ] );
233
231
if ( null !== $ version ) {
234
232
return $ version ;
235
233
}
@@ -244,10 +242,9 @@ function ($token) {
244
242
* @param string $docblock
245
243
* @return null|string The content of the version tag
246
244
*/
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 ' ] ) ) {
251
248
return $ docblocktags ['version ' ];
252
249
}
253
250
return null ;
@@ -264,23 +261,24 @@ private static function get_version_in_docblock($docblock)
264
261
* @param string $docblock
265
262
* @return array
266
263
*/
267
- private static function parse_doc_block ($ docblock ): array
268
- {
264
+ private static function parse_doc_block ( $ docblock ) {
269
265
$ 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 ) ) {
277
273
continue ;
278
274
}
279
275
}
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 ;
283
281
}
284
282
return $ tags ;
285
- }
283
+ }
286
284
}
0 commit comments