@@ -61,6 +61,9 @@ public function run( $args, $assoc_args ) {
6161 // Combine the output into a single string
6262 $ output_content = implode ("\n" , $ output );
6363
64+ //make the output php editor clickable compatible
65+ $ output_content = $ this ->makePhpEditorCompatible ($ output_content );
66+
6467 // Clean the file (truncate) before writing new output
6568 if (file_put_contents ($ output_file , '' ) === false ) {
6669 \WP_CLI ::error ('Failed to clear the output file. ' );
@@ -73,4 +76,50 @@ public function run( $args, $assoc_args ) {
7376
7477 \WP_CLI ::success ("Plugin check output written to {$ output_file }" );
7578 } //end method run
79+
80+
81+ public function makePhpEditorCompatible ($ input ) {
82+ // Split the input string into chunks based on the FILE keyword
83+ $ chunks = preg_split ('/(?=FILE: )/ ' , $ input , -1 , PREG_SPLIT_NO_EMPTY );
84+ $ output = '' ;
85+
86+ foreach ($ chunks as $ chunk ) {
87+ // Check if the chunk corresponds to a .php file
88+ if (preg_match ('/FILE: (.+\.php)/ ' , $ chunk , $ matches )) {
89+ // Split the chunk into lines
90+ $ lines = explode ("\n" , trim ($ chunk ));
91+ $ shouldModify = false ;
92+
93+ // Check if any line starts with a non-zero number
94+ for ($ i = 1 ; $ i < count ($ lines ); $ i ++) {
95+ $ lineParts = preg_split ('/\s+/ ' , $ lines [$ i ]);
96+ if (isset ($ lineParts [0 ]) && is_numeric ($ lineParts [0 ]) && $ lineParts [0 ] != '0 ' ) {
97+ $ shouldModify = true ;
98+ break ;
99+ }
100+ }
101+
102+ // Modify the chunk if necessary
103+ if ($ shouldModify ) {
104+ $ output .= $ lines [0 ] . "\n" ;
105+ $ output .= "File line \tcolumn \ttype \tcode \tmessage \tdocs \n" ;
106+ for ($ i = 1 ; $ i < count ($ lines ); $ i ++) {
107+ $ lineParts = preg_split ('/\s+/ ' , $ lines [$ i ], 2 );
108+ if (isset ($ lineParts [0 ]) && is_numeric ($ lineParts [0 ]) && $ lineParts [0 ] != '0 ' ) {
109+ $ output .= $ lines [0 ] . " on line " . $ lineParts [0 ] . "\t" . $ lineParts [1 ] . "\n" ;
110+ }
111+ }
112+ $ output .= "\n" ; // Add an extra newline after each modified chunk
113+ } else {
114+ // If no modification needed, add the original chunk
115+ $ output .= $ chunk . "\n\n" ; // Add an extra newline after each unmodified chunk
116+ }
117+ } else {
118+ // If the chunk does not correspond to a .php file, add the original chunk
119+ $ output .= $ chunk . "\n\n" ; // Add an extra newline after each unmodified chunk
120+ }
121+ }
122+
123+ return trim ($ output );
124+ }//end method makePhpEditorCompatible
76125} //end class EasyPluginChecker
0 commit comments