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 / Localhost_Check.php

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

107 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class Localhost_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 for detecting localhost in plugin files.
18 *
19 * @since 1.0.0
20 */
21 class Localhost_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.0.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.3.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.Localhost',
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.1.0
61 *
62 * @return string Description.
63 */
64 public function get_description(): string {
65 return sprintf(
66 /* translators: %s: Localhost/127.0.0.1 */
67 __( 'Detects the usage of %s in the plugin.', 'plugin-check' ),
68 'Localhost/127.0.0.1'
69 );
70 }
71
72 /**
73 * Gets the documentation URL for the check.
74 *
75 * Every check must have a URL with further information about the check.
76 *
77 * @since 1.1.0
78 *
79 * @return string The documentation URL.
80 */
81 public function get_documentation_url(): string {
82 return __( 'https://make.wordpress.org/plugins/handbook/performing-reviews/review-checklist/', 'plugin-check' );
83 }
84
85 /**
86 * Amends the given result with a message for the specified file, including error information.
87 *
88 * @since 1.3.0
89 *
90 * @param Check_Result $result The check result to amend, including the plugin context to check.
91 * @param bool $error Whether it is an error or notice.
92 * @param string $message Error message.
93 * @param string $code Error code.
94 * @param string $file Absolute path to the file where the issue was found.
95 * @param int $line The line on which the message occurred. Default is 0 (unknown line).
96 * @param int $column The column on which the message occurred. Default is 0 (unknown column).
97 * @param string $docs URL for further information about the message.
98 * @param int $severity Severity level. Default is 5.
99 */
100 protected function add_result_message_for_file( Check_Result $result, $error, $message, $code, $file, $line = 0, $column = 0, string $docs = '', $severity = 5 ) {
101 // Override default severity.
102 $severity = 8;
103
104 parent::add_result_message_for_file( $result, $error, $message, $code, $file, $line, $column, $docs, $severity );
105 }
106 }
107