PluginProbe
Plugin Check (PCP) / 1.5.0
Plugin Check (PCP) v1.5.0
2.1.0 trunk 0.1 0.2.0 0.2.1 0.2.2 0.2.3 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.3.0 1.3.1 1.4.0 1.5.0 1.6.0 1.7.0 1.8.0 1.9.0 2.0.0 ci-artifacts
plugin-check / includes / Checker / Checks / Plugin_Repo / Setting_Sanitization_Check.php

Setting_Sanitization_Check.php in Plugin Check (PCP) 1.5.0, at includes/Checker/Checks/Plugin_Repo/Setting_Sanitization_Check.php

114 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class Setting_Sanitization_Check.
4 *
5 * @package plugin-check
6 */
7
8 namespace WordPress\Plugin_Check\Checker\Checks\Plugin_Repo;
9
10 use WordPress\Plugin_Check\Checker\Check_Categories;
11 use WordPress\Plugin_Check\Checker\Check_Result;
12 use WordPress\Plugin_Check\Checker\Checks\Abstract_PHP_CodeSniffer_Check;
13 use WordPress\Plugin_Check\Traits\Amend_Check_Result;
14 use WordPress\Plugin_Check\Traits\Stable_Check;
15
16 /**
17 * Check to detect sanitization in register_setting().
18 *
19 * @since 1.4.0
20 */
21 class Setting_Sanitization_Check extends Abstract_PHP_CodeSniffer_Check {
22
23 use Amend_Check_Result;
24 use Stable_Check;
25
26 /**
27 * Gets the categories for the check.
28 *
29 * Every check must have at least one category.
30 *
31 * @since 1.4.0
32 *
33 * @return array The categories for the check.
34 */
35 public function get_categories() {
36 return array( Check_Categories::CATEGORY_PLUGIN_REPO );
37 }
38
39 /**
40 * Returns an associative array of arguments to pass to PHPCS.
41 *
42 * @since 1.4.0
43 *
44 * @param Check_Result $result The check result to amend, including the plugin context to check.
45 * @return array An associative array of PHPCS CLI arguments.
46 */
47 protected function get_args( Check_Result $result ) {
48 return array(
49 'extensions' => 'php',
50 'standard' => 'PluginCheck',
51 'sniffs' => 'PluginCheck.CodeAnalysis.SettingSanitization',
52 );
53 }
54
55 /**
56 * Gets the description for the check.
57 *
58 * Every check must have a short description explaining what the check does.
59 *
60 * @since 1.4.0
61 *
62 * @return string Description.
63 */
64 public function get_description(): string {
65 return __( 'Ensures sanitization in register_setting().', 'plugin-check' );
66 }
67
68 /**
69 * Gets the documentation URL for the check.
70 *
71 * Every check must have a URL with further information about the check.
72 *
73 * @since 1.4.0
74 *
75 * @return string The documentation URL.
76 */
77 public function get_documentation_url(): string {
78 return __( 'https://developer.wordpress.org/reference/functions/register_setting/', 'plugin-check' );
79 }
80
81 /**
82 * Amends the given result with a message for the specified file, including error information.
83 *
84 * @since 1.4.0
85 *
86 * @param Check_Result $result The check result to amend, including the plugin context to check.
87 * @param bool $error Whether it is an error or notice.
88 * @param string $message Error message.
89 * @param string $code Error code.
90 * @param string $file Absolute path to the file where the issue was found.
91 * @param int $line The line on which the message occurred. Default is 0 (unknown line).
92 * @param int $column The column on which the message occurred. Default is 0 (unknown column).
93 * @param string $docs URL for further information about the message.
94 * @param int $severity Severity level. Default is 5.
95 */
96 protected function add_result_message_for_file( Check_Result $result, $error, $message, $code, $file, $line = 0, $column = 0, string $docs = '', $severity = 5 ) {
97 // Update severity.
98 switch ( $code ) {
99 case 'PluginCheck.CodeAnalysis.SettingSanitization.register_settingMissing':
100 case 'PluginCheck.CodeAnalysis.SettingSanitization.register_settingInvalid':
101 $severity = 7;
102 break;
103
104 default:
105 break;
106 }
107
108 // Add docs link.
109 $docs = __( 'https://developer.wordpress.org/reference/functions/register_setting/', 'plugin-check' );
110
111 parent::add_result_message_for_file( $result, $error, $message, $code, $file, $line, $column, $docs, $severity );
112 }
113 }
114