Skip to content

Commit

Permalink
Warn for missing composer json file
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Dec 26, 2024
1 parent d4ed882 commit 7721815
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion includes/Checker/Checks/Plugin_Repo/File_Type_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class File_Type_Check extends Abstract_File_Check {
const TYPE_APPLICATION = 16;
const TYPE_BADLY_NAMED = 32;
const TYPE_LIBRARY_CORE = 64;
const TYPE_ALL = 127; // Same as all of the above with bitwise OR.
const TYPE_COMPOSER = 128;
const TYPE_ALL = 255; // Same as all of the above with bitwise OR.

/**
* Bitwise flags to control check behavior.
Expand Down Expand Up @@ -99,6 +100,9 @@ protected function check_files( Check_Result $result, array $files ) {
if ( $this->flags & self::TYPE_LIBRARY_CORE ) {
$this->look_for_library_core_files( $result, $files );
}
if ( $this->flags & self::TYPE_COMPOSER ) {
$this->look_for_composer_files( $result, $files );
}
}

/**
Expand Down Expand Up @@ -372,6 +376,44 @@ function ( $file ) use ( $plugin_path ) {
}
}

/**
* Looks for composer files.
*
* @since 1.4.0
*
* @param Check_Result $result The check result to amend, including the plugin context to check.
* @param array $files List of absolute file paths.
*/
protected function look_for_composer_files( Check_Result $result, array $files ) {
if ( $result->plugin()->is_single_file_plugin() ) {
return;
}

$plugin_path = $result->plugin()->path();

if (
is_dir( $plugin_path . 'vendor' ) &&
file_exists( $plugin_path . 'vendor/autoload.php' ) &&
! file_exists( $plugin_path . 'composer.json' )
) {
$this->add_result_warning_for_file(
$result,
sprintf(
/* translators: 1: directory, 2: filename */
esc_html__( 'The "%1$s" directory exists, but "%2$s" is missing.', 'plugin-check' ),
'/vendor',
'composer.json'
),
'missing_composer_json_file',
'composer.json',
0,
0,
'https://developer.wordpress.org/plugins/wordpress-org/common-issues/#included-unneeded-folders',
6
);
}
}

/**
* Gets the description for the check.
*
Expand Down

0 comments on commit 7721815

Please sign in to comment.