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 / Traits / Amend_Check_Result.php

Amend_Check_Result.php in Plugin Check (PCP) 1.5.0, at includes/Traits/Amend_Check_Result.php

89 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Trait WordPress\Plugin_Check\Traits\Amend_Check_Result
4 *
5 * @package plugin-check
6 */
7
8 namespace WordPress\Plugin_Check\Traits;
9
10 use WordPress\Plugin_Check\Checker\Check_Result;
11
12 /**
13 * Trait for amending check results.
14 *
15 * @since 1.0.0
16 */
17 trait Amend_Check_Result {
18
19 use File_Editor_URL;
20
21 /**
22 * Amends the given result with a message for the specified file, including error information.
23 *
24 * @since 1.0.0
25 *
26 * @param Check_Result $result The check result to amend, including the plugin context to check.
27 * @param bool $error Whether it is an error or notice.
28 * @param string $message Error message.
29 * @param string $code Error code.
30 * @param string $file Absolute path to the file where the issue was found.
31 * @param int $line The line on which the message occurred. Default is 0 (unknown line).
32 * @param int $column The column on which the message occurred. Default is 0 (unknown column).
33 * @param string $docs URL for further information about the message.
34 * @param int $severity Severity level. Default is 5.
35 */
36 protected function add_result_message_for_file( Check_Result $result, $error, $message, $code, $file, $line = 0, $column = 0, string $docs = '', $severity = 5 ) {
37
38 $result->add_message(
39 (bool) $error,
40 $message,
41 array(
42 'code' => $code,
43 'file' => str_replace( $result->plugin()->path(), '', $file ),
44 'line' => $line,
45 'column' => $column,
46 'link' => $this->get_file_editor_url( $result, $file, $line ),
47 'docs' => $docs,
48 'severity' => $severity,
49 )
50 );
51 }
52
53 /**
54 * Amends the given result with an error message for the specified file.
55 *
56 * @since 1.0.0
57 *
58 * @param Check_Result $result The check result to amend, including the plugin context to check.
59 * @param string $message Error message.
60 * @param string $code Error code.
61 * @param string $file Absolute path to the file where the error was found.
62 * @param int $line The line on which the error occurred. Default is 0 (unknown line).
63 * @param int $column The column on which the error occurred. Default is 0 (unknown column).
64 * @param string $docs URL for further information about the message.
65 * @param int $severity Severity level. Default is 5.
66 */
67 protected function add_result_error_for_file( Check_Result $result, $message, $code, $file, $line = 0, $column = 0, string $docs = '', $severity = 5 ) {
68 $this->add_result_message_for_file( $result, true, $message, $code, $file, $line, $column, $docs, $severity );
69 }
70
71 /**
72 * Amends the given result with a warning message for the specified file.
73 *
74 * @since 1.0.0
75 *
76 * @param Check_Result $result The check result to amend, including the plugin context to check.
77 * @param string $message Error message.
78 * @param string $code Error code.
79 * @param string $file Absolute path to the file where the warning was found.
80 * @param int $line The line on which the warning occurred. Default is 0 (unknown line).
81 * @param int $column The column on which the warning occurred. Default is 0 (unknown column).
82 * @param string $docs URL for further information about the message.
83 * @param int $severity Severity level. Default is 5.
84 */
85 protected function add_result_warning_for_file( Check_Result $result, $message, $code, $file, $line = 0, $column = 0, string $docs = '', $severity = 5 ) {
86 $this->add_result_message_for_file( $result, false, $message, $code, $file, $line, $column, $docs, $severity );
87 }
88 }
89