Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* Class Runtime_Fatal_Error_Prevention_Check.
*
* @package plugin-check
*/

namespace WordPress\Plugin_Check\Checker\Checks\Plugin_Repo;

use WordPress\Plugin_Check\Checker\Check_Categories;
use WordPress\Plugin_Check\Checker\Check_Result;
use WordPress\Plugin_Check\Checker\Checks\Abstract_PHP_CodeSniffer_Check;
use WordPress\Plugin_Check\Traits\Amend_Check_Result;
use WordPress\Plugin_Check\Traits\Stable_Check;

/**
* Check for detecting high-risk patterns that commonly cause runtime fatal errors.
*
* @since 2.1.0
*/
class Runtime_Fatal_Error_Prevention_Check extends Abstract_PHP_CodeSniffer_Check {

use Amend_Check_Result;
use Stable_Check;

/**
* Gets the categories for the check.
*
* Every check must have at least one category.
*
* @since 2.1.0
*
* @return array The categories for the check.
*/
public function get_categories() {
return array( Check_Categories::CATEGORY_PLUGIN_REPO );
}

/**
* Returns an associative array of arguments to pass to PHPCS.
*
* @since 2.1.0
*
* @param Check_Result $result The check result to amend, including the plugin context to check.
* @return array An associative array of PHPCS CLI arguments.
*/
protected function get_args( Check_Result $result ) {
return array(
'extensions' => 'php',
'standard' => 'PluginCheck',
'sniffs' => 'PluginCheck.CodeAnalysis.RuntimeFatalErrorPrevention',
);
}

/**
* Gets the description for the check.
*
* Every check must have a short description explaining what the check does.
*
* @since 2.1.0
*
* @return string Description.
*/
public function get_description(): string {
return __( 'Detects high-risk coding patterns that commonly cause runtime fatal errors or notices in plugins.', 'plugin-check' );
}

/**
* Gets the documentation URL for the check.
*
* Every check must have a URL with further information about the check.
*
* @since 2.1.0
*
* @return string The documentation URL.
*/
public function get_documentation_url(): string {
return __( 'https://developer.wordpress.org/plugins/wordpress-org/detailed-plugin-guidelines/', 'plugin-check' );
}
}
63 changes: 32 additions & 31 deletions includes/Checker/Default_Check_Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,37 +71,38 @@ private function register_default_checks() {
$checks = apply_filters(
'wp_plugin_check_checks',
array(
'i18n_usage' => new Checks\General\I18n_Usage_Check(),
'enqueued_scripts_size' => new Checks\Performance\Enqueued_Scripts_Size_Check(),
'enqueued_styles_size' => new Checks\Performance\Enqueued_Styles_Size_Check(),
'code_obfuscation' => new Checks\Plugin_Repo\Code_Obfuscation_Check(),
'plugin_content' => new Checks\Plugin_Repo\Plugin_Content_Check(),
'file_type' => new Checks\Plugin_Repo\File_Type_Check(),
'plugin_header_fields' => new Checks\Plugin_Repo\Plugin_Header_Fields_Check(),
'late_escaping' => new Checks\Security\Late_Escaping_Check(),
'safe_redirect' => new Checks\Security\Safe_Redirect_Check(),
'plugin_updater' => new Checks\Plugin_Repo\Plugin_Updater_Check(),
'plugin_uninstall' => new Checks\Plugin_Repo\Plugin_Uninstall_Check(),
'plugin_review_phpcs' => new Checks\Plugin_Repo\Plugin_Review_PHPCS_Check(),
'direct_db_queries' => new Checks\Security\Direct_DB_Queries_Check(),
'performant_wp_query_params' => new Checks\Performance\Performant_WP_Query_Params_Check(),
'enqueued_scripts_in_footer' => new Checks\Performance\Enqueued_Scripts_In_Footer_Check(),
'enqueued_resources' => new Checks\Performance\Enqueued_Resources_Check(),
'plugin_readme' => new Checks\Plugin_Repo\Plugin_Readme_Check(),
'enqueued_styles_scope' => new Checks\Performance\Enqueued_Styles_Scope_Check(),
'enqueued_scripts_scope' => new Checks\Performance\Enqueued_Scripts_Scope_Check(),
'localhost' => new Checks\Plugin_Repo\Localhost_Check(),
'no_unfiltered_uploads' => new Checks\Plugin_Repo\No_Unfiltered_Uploads_Check(),
'trademarks' => new Checks\Plugin_Repo\Trademarks_Check(),
'non_blocking_scripts' => new Checks\Performance\Non_Blocking_Scripts_Check(),
'offloading_files' => new Checks\Plugin_Repo\Offloading_Files_Check(),
'setting_sanitization' => new Checks\Plugin_Repo\Setting_Sanitization_Check(),
'prefixing' => new Checks\Plugin_Repo\Prefixing_Check(),
'direct_db' => new Checks\Security\Direct_DB_Check(),
'minified_files' => new Checks\Plugin_Repo\Minified_Files_Check(),
'direct_file_access' => new Checks\Plugin_Repo\Direct_File_Access_Check(),
'external_admin_menu_links' => new Checks\Plugin_Repo\External_Admin_Menu_Links_Check(),
'wp_functions_compatibility' => new Checks\Plugin_Repo\WP_Functions_Compatibility_Check(),
'i18n_usage' => new Checks\General\I18n_Usage_Check(),
'enqueued_scripts_size' => new Checks\Performance\Enqueued_Scripts_Size_Check(),
'enqueued_styles_size' => new Checks\Performance\Enqueued_Styles_Size_Check(),
'code_obfuscation' => new Checks\Plugin_Repo\Code_Obfuscation_Check(),
'plugin_content' => new Checks\Plugin_Repo\Plugin_Content_Check(),
'file_type' => new Checks\Plugin_Repo\File_Type_Check(),
'plugin_header_fields' => new Checks\Plugin_Repo\Plugin_Header_Fields_Check(),
'late_escaping' => new Checks\Security\Late_Escaping_Check(),
'safe_redirect' => new Checks\Security\Safe_Redirect_Check(),
'plugin_updater' => new Checks\Plugin_Repo\Plugin_Updater_Check(),
'plugin_uninstall' => new Checks\Plugin_Repo\Plugin_Uninstall_Check(),
'plugin_review_phpcs' => new Checks\Plugin_Repo\Plugin_Review_PHPCS_Check(),
'direct_db_queries' => new Checks\Security\Direct_DB_Queries_Check(),
'performant_wp_query_params' => new Checks\Performance\Performant_WP_Query_Params_Check(),
'enqueued_scripts_in_footer' => new Checks\Performance\Enqueued_Scripts_In_Footer_Check(),
'enqueued_resources' => new Checks\Performance\Enqueued_Resources_Check(),
'plugin_readme' => new Checks\Plugin_Repo\Plugin_Readme_Check(),
'enqueued_styles_scope' => new Checks\Performance\Enqueued_Styles_Scope_Check(),
'enqueued_scripts_scope' => new Checks\Performance\Enqueued_Scripts_Scope_Check(),
'localhost' => new Checks\Plugin_Repo\Localhost_Check(),
'no_unfiltered_uploads' => new Checks\Plugin_Repo\No_Unfiltered_Uploads_Check(),
'trademarks' => new Checks\Plugin_Repo\Trademarks_Check(),
'non_blocking_scripts' => new Checks\Performance\Non_Blocking_Scripts_Check(),
'offloading_files' => new Checks\Plugin_Repo\Offloading_Files_Check(),
'setting_sanitization' => new Checks\Plugin_Repo\Setting_Sanitization_Check(),
'prefixing' => new Checks\Plugin_Repo\Prefixing_Check(),
'direct_db' => new Checks\Security\Direct_DB_Check(),
'minified_files' => new Checks\Plugin_Repo\Minified_Files_Check(),
'direct_file_access' => new Checks\Plugin_Repo\Direct_File_Access_Check(),
'external_admin_menu_links' => new Checks\Plugin_Repo\External_Admin_Menu_Links_Check(),
'wp_functions_compatibility' => new Checks\Plugin_Repo\WP_Functions_Compatibility_Check(),
'runtime_fatal_error_prevention' => new Checks\Plugin_Repo\Runtime_Fatal_Error_Prevention_Check(),
)
);

Expand Down
3 changes: 3 additions & 0 deletions phpcs-rulesets/plugin-check.ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<severity>6</severity>
</rule>

<!-- Prevent runtime fatal errors. -->
<rule ref="PluginCheck.CodeAnalysis.RuntimeFatalErrorPrevention"/>

<!-- Prohibit the use of the `goto` PHP language construct. -->
<rule ref="Generic.PHP.DiscourageGoto.Found">
<type>error</type>
Expand Down
Loading