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