Skip to content

Commit 7721815

Browse files
committed
Warn for missing composer json file
1 parent d4ed882 commit 7721815

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

includes/Checker/Checks/Plugin_Repo/File_Type_Check.php

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class File_Type_Check extends Abstract_File_Check {
3131
const TYPE_APPLICATION = 16;
3232
const TYPE_BADLY_NAMED = 32;
3333
const TYPE_LIBRARY_CORE = 64;
34-
const TYPE_ALL = 127; // Same as all of the above with bitwise OR.
34+
const TYPE_COMPOSER = 128;
35+
const TYPE_ALL = 255; // Same as all of the above with bitwise OR.
3536

3637
/**
3738
* Bitwise flags to control check behavior.
@@ -99,6 +100,9 @@ protected function check_files( Check_Result $result, array $files ) {
99100
if ( $this->flags & self::TYPE_LIBRARY_CORE ) {
100101
$this->look_for_library_core_files( $result, $files );
101102
}
103+
if ( $this->flags & self::TYPE_COMPOSER ) {
104+
$this->look_for_composer_files( $result, $files );
105+
}
102106
}
103107

104108
/**
@@ -372,6 +376,44 @@ function ( $file ) use ( $plugin_path ) {
372376
}
373377
}
374378

379+
/**
380+
* Looks for composer files.
381+
*
382+
* @since 1.4.0
383+
*
384+
* @param Check_Result $result The check result to amend, including the plugin context to check.
385+
* @param array $files List of absolute file paths.
386+
*/
387+
protected function look_for_composer_files( Check_Result $result, array $files ) {
388+
if ( $result->plugin()->is_single_file_plugin() ) {
389+
return;
390+
}
391+
392+
$plugin_path = $result->plugin()->path();
393+
394+
if (
395+
is_dir( $plugin_path . 'vendor' ) &&
396+
file_exists( $plugin_path . 'vendor/autoload.php' ) &&
397+
! file_exists( $plugin_path . 'composer.json' )
398+
) {
399+
$this->add_result_warning_for_file(
400+
$result,
401+
sprintf(
402+
/* translators: 1: directory, 2: filename */
403+
esc_html__( 'The "%1$s" directory exists, but "%2$s" is missing.', 'plugin-check' ),
404+
'/vendor',
405+
'composer.json'
406+
),
407+
'missing_composer_json_file',
408+
'composer.json',
409+
0,
410+
0,
411+
'https://developer.wordpress.org/plugins/wordpress-org/common-issues/#included-unneeded-folders',
412+
6
413+
);
414+
}
415+
}
416+
375417
/**
376418
* Gets the description for the check.
377419
*

0 commit comments

Comments
 (0)