@@ -22,6 +22,14 @@ final class Check_Result {
2222 */
2323 protected $ check_context ;
2424
25+ /**
26+ * List of types to filter.
27+ *
28+ * @since 1.7.0
29+ * @var array
30+ */
31+ protected $ check_types = array ();
32+
2533 /**
2634 * List of errors.
2735 *
@@ -57,12 +65,14 @@ final class Check_Result {
5765 /**
5866 * Sets the context for the plugin to check.
5967 *
60- * @since 1.0.0
61- *
6268 * @param Check_Context $check_context Check context instance for the plugin.
69+ * @param array $check_types An array of check types to filter.
70+ *
71+ * @since 1.0.0
6372 */
64- public function __construct ( Check_Context $ check_context ) {
73+ public function __construct ( Check_Context $ check_context, array $ check_types = array () ) {
6574 $ this ->check_context = $ check_context ;
75+ $ this ->check_types = $ check_types ;
6676 }
6777
6878 /**
@@ -118,29 +128,33 @@ public function add_message( $error, $message, $args = array() ) {
118128 unset( $ data ['line ' ], $ data ['column ' ], $ data ['file ' ] );
119129
120130 if ( $ error ) {
121- if ( ! isset ( $ this ->errors [ $ file ] ) ) {
122- $ this ->errors [ $ file ] = array ();
123- }
124- if ( ! isset ( $ this ->errors [ $ file ][ $ line ] ) ) {
125- $ this ->errors [ $ file ][ $ line ] = array ();
131+ if ( in_array ( 'error ' , $ this ->check_types , true ) ) {
132+ if ( ! isset ( $ this ->errors [ $ file ] ) ) {
133+ $ this ->errors [ $ file ] = array ();
134+ }
135+ if ( ! isset ( $ this ->errors [ $ file ][ $ line ] ) ) {
136+ $ this ->errors [ $ file ][ $ line ] = array ();
137+ }
138+ if ( ! isset ( $ this ->errors [ $ file ][ $ line ][ $ column ] ) ) {
139+ $ this ->errors [ $ file ][ $ line ][ $ column ] = array ();
140+ }
141+ $ this ->errors [ $ file ][ $ line ][ $ column ][] = $ data ;
142+ ++$ this ->error_count ;
126143 }
127- if ( ! isset ( $ this ->errors [ $ file ][ $ line ][ $ column ] ) ) {
128- $ this ->errors [ $ file ][ $ line ][ $ column ] = array ();
129- }
130- $ this ->errors [ $ file ][ $ line ][ $ column ][] = $ data ;
131- ++$ this ->error_count ;
132144 } else {
133- if ( ! isset ( $ this ->warnings [ $ file ] ) ) {
134- $ this ->warnings [ $ file ] = array ();
135- }
136- if ( ! isset ( $ this ->warnings [ $ file ][ $ line ] ) ) {
137- $ this ->warnings [ $ file ][ $ line ] = array ();
138- }
139- if ( ! isset ( $ this ->warnings [ $ file ][ $ line ][ $ column ] ) ) {
140- $ this ->warnings [ $ file ][ $ line ][ $ column ] = array ();
145+ if ( in_array ( 'warning ' , $ this ->check_types , true ) ) {
146+ if ( ! isset ( $ this ->warnings [ $ file ] ) ) {
147+ $ this ->warnings [ $ file ] = array ();
148+ }
149+ if ( ! isset ( $ this ->warnings [ $ file ][ $ line ] ) ) {
150+ $ this ->warnings [ $ file ][ $ line ] = array ();
151+ }
152+ if ( ! isset ( $ this ->warnings [ $ file ][ $ line ][ $ column ] ) ) {
153+ $ this ->warnings [ $ file ][ $ line ][ $ column ] = array ();
154+ }
155+ $ this ->warnings [ $ file ][ $ line ][ $ column ][] = $ data ;
156+ ++$ this ->warning_count ;
141157 }
142- $ this ->warnings [ $ file ][ $ line ][ $ column ][] = $ data ;
143- ++$ this ->warning_count ;
144158 }
145159 }
146160
0 commit comments