2424 * @license http://mit-license.org/ MIT Licence
2525 * @link http://github.com/morozov/diff-sniffer-core
2626 */
27- class PHP_CodeSniffer_Reports_Xml implements PHP_CodeSniffer_Report
27+ class PHP_CodeSniffer_Reports_DiffSniffer implements PHP_CodeSniffer_Report
2828{
2929 /**
3030 * Temporary diff file path.
@@ -40,6 +40,13 @@ class PHP_CodeSniffer_Reports_Xml implements PHP_CodeSniffer_Report
4040 */
4141 protected $ baseDir ;
4242
43+ /**
44+ * Requested report type
45+ *
46+ * @var string
47+ */
48+ protected $ reportType ;
49+
4350 /**
4451 * Constructor.
4552 */
@@ -60,84 +67,78 @@ public function __construct()
6067 );
6168 }
6269 $ this ->baseDir = $ baseDir ;
70+
71+ $ this ->reportType = $ this ->getEnv ('PHPCS_REPORT_TYPE ' );
6372 }
6473
6574 /**
66- * Retrieves the path specified by environment variable.
75+ * Retrieves the value of environment variable.
6776 *
6877 * @param string $varName Environment variable name
6978 *
7079 * @return string
7180 * @throws PHP_CodeSniffer_Exception
7281 */
73- protected function getPath ($ varName )
82+ protected function getEnv ($ varName )
7483 {
7584 if (!isset ($ _SERVER [$ varName ])) {
7685 throw new PHP_CodeSniffer_Exception (
7786 $ varName . ' environment variable is not set '
7887 );
7988 }
8089
81- $ path = realpath ($ _SERVER [$ varName ]);
90+ return $ _SERVER [$ varName ];
91+ }
92+
93+ /**
94+ * Retrieves the path specified by environment variable.
95+ *
96+ * @param string $varName Environment variable name
97+ *
98+ * @return string
99+ * @throws PHP_CodeSniffer_Exception
100+ */
101+ protected function getPath ($ varName )
102+ {
103+ $ value = $ this ->getEnv ($ varName );
104+ $ path = realpath ($ value );
82105
83106 if (false === $ path ) {
84107 throw new PHP_CodeSniffer_Exception (
85- $ _SERVER [ $ varName ] . ' path does not exist '
108+ $ value . ' path does not exist '
86109 );
87110 }
88111
89112 return $ path ;
90113 }
91114
92- /**
93- * Generate a partial report for a single processed file.
94- *
95- * Function should return TRUE if it printed or stored data about the file
96- * and FALSE if it ignored the file. Returning TRUE indicates that the file and
97- * its data should be counted in the grand totals.
98- *
99- * @param array $report Prepared report data.
100- * @param boolean $showSources Show sources?
101- * @param int $width Maximum allowed line width.
102- *
103- * @return boolean
104- */
115+ /** {@inheritDoc} */
105116 public function generateFileReport (
106117 $ report ,
107- $ showSources =false ,
108- $ width =80
118+ PHP_CodeSniffer_File $ phpcsFile ,
119+ $ showSources = false ,
120+ $ width = 80
109121 ) {
110122 $ diff = $ this ->getStagedDiff ();
111123 $ changes = $ this ->getChanges ($ diff );
112124
113125 $ report = $ this ->filterReport ($ report , $ changes );
114126
115- $ full = new PHP_CodeSniffer_Reports_Full ();
116- return $ full ->generateFileReport ($ report , $ showSources , $ width );
127+ $ reporting = new PHP_CodeSniffer_Reporting ();
128+ $ actual = $ reporting ->factory ($ this ->reportType );
129+ return $ actual ->generateFileReport ($ report , $ phpcsFile , $ showSources , $ width );
117130 }
118131
119- /**
120- * Prints all errors and warnings for each file processed.
121- *
122- * @param string $cachedData Any partial report data that was returned from
123- * generateFileReport during the run.
124- * @param int $totalFiles Total number of files processed during the run.
125- * @param int $totalErrors Total number of errors found during the run.
126- * @param int $totalWarnings Total number of warnings found during the run.
127- * @param boolean $showSources Show sources?
128- * @param int $width Maximum allowed line width.
129- * @param boolean $toScreen Is the report being printed to screen?
130- *
131- * @return void
132- */
132+ /** {@inheritDoc} */
133133 public function generate (
134134 $ cachedData ,
135135 $ totalFiles ,
136136 $ totalErrors ,
137137 $ totalWarnings ,
138- $ showSources =false ,
139- $ width =80 ,
140- $ toScreen =true
138+ $ totalFixable ,
139+ $ showSources = false ,
140+ $ width = 80 ,
141+ $ toScreen = true
141142 ) {
142143 echo $ cachedData ;
143144
@@ -233,23 +234,28 @@ protected function repairReport(array $report)
233234 $ repaired = array_merge ($ report , array (
234235 'errors ' => 0 ,
235236 'warnings ' => 0 ,
237+ 'fixable ' => 0 ,
236238 ));
237239
238240 foreach ($ report ['messages ' ] as $ columns ) {
239241 foreach ($ columns as $ messages ) {
240242 foreach ($ messages as $ message ) {
241243 switch ($ message ['type ' ]) {
242- case 'ERROR ' ;
244+ case 'ERROR ' :
243245 $ key = 'errors ' ;
244246 break ;
245- case 'WARNING ' ;
247+ case 'WARNING ' :
246248 $ key = 'warnings ' ;
247249 break ;
248- default ;
250+ default :
249251 $ key = null ;
250252 continue ;
251253 }
252254 $ repaired [$ key ]++;
255+
256+ if ($ message ['fixable ' ]) {
257+ $ repaired ['fixable ' ]++;
258+ }
253259 }
254260 }
255261 }
0 commit comments