@@ -194,13 +194,7 @@ public function package_readme( $args, $assoc_args ) {
194
194
195
195
list ( $ package_dir ) = $ args ;
196
196
197
- if ( ! is_dir ( $ package_dir ) ) {
198
- WP_CLI ::error ( 'Directory does not exist. ' );
199
- }
200
-
201
- if ( ! file_exists ( $ package_dir . '/composer.json ' ) ) {
202
- WP_CLI ::error ( 'Invalid package directory. composer.json file must be present. ' );
203
- }
197
+ self ::check_if_valid_package_dir ( $ package_dir );
204
198
205
199
$ composer_obj = json_decode ( file_get_contents ( $ package_dir . '/composer.json ' ), true );
206
200
if ( ! $ composer_obj ) {
@@ -405,13 +399,7 @@ public function package_github( $args, $assoc_args ) {
405
399
$ package_dir = rtrim ( $ package_dir , '/ ' );
406
400
}
407
401
408
- if ( ! is_dir ( $ package_dir ) ) {
409
- WP_CLI ::error ( 'Directory does not exist. ' );
410
- }
411
-
412
- if ( ! file_exists ( $ package_dir . '/composer.json ' ) ) {
413
- WP_CLI ::error ( 'Invalid package directory. composer.json file must be present. ' );
414
- }
402
+ self ::check_if_valid_package_dir ( $ package_dir );
415
403
416
404
$ force = Utils \get_flag_value ( $ assoc_args , 'force ' );
417
405
$ template_path = dirname ( dirname ( __FILE__ ) ) . '/templates ' ;
@@ -531,13 +519,7 @@ public function package_tests( $args, $assoc_args ) {
531
519
$ package_dir = rtrim ( $ package_dir , '/ ' );
532
520
}
533
521
534
- if ( ! is_dir ( $ package_dir ) ) {
535
- WP_CLI ::error ( 'Directory does not exist. ' );
536
- }
537
-
538
- if ( ! file_exists ( $ package_dir . '/composer.json ' ) ) {
539
- WP_CLI ::error ( 'Invalid package directory. composer.json file must be present. ' );
540
- }
522
+ self ::check_if_valid_package_dir ( $ package_dir );
541
523
542
524
$ package_dir .= '/ ' ;
543
525
$ bin_dir = $ package_dir . 'bin/ ' ;
@@ -677,4 +659,14 @@ private function create_files( $files_and_contents, $force ) {
677
659
return $ wrote_files ;
678
660
}
679
661
662
+ private static function check_if_valid_package_dir ( $ package_dir ) {
663
+ if ( ! is_dir ( $ package_dir ) ) {
664
+ WP_CLI ::error ( 'Directory does not exist. ' );
665
+ }
666
+
667
+ if ( ! file_exists ( $ package_dir . '/composer.json ' ) ) {
668
+ WP_CLI ::error ( 'Invalid package directory. composer.json file must be present. ' );
669
+ }
670
+ }
671
+
680
672
}
0 commit comments