1<?php
2/**
3 * Emacs report for PHP_CodeSniffer.
4 *
5 * PHP version 5
6 *
7 * @category  PHP
8 * @package   PHP_CodeSniffer
9 * @author    Gabriele Santini <gsantini@sqli.com>
10 * @author    Greg Sherwood <gsherwood@squiz.net>
11 * @copyright 2009-2014 SQLI <www.sqli.com>
12 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
13 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
14 * @link      http://pear.php.net/package/PHP_CodeSniffer
15 */
16
17/**
18 * Emacs report for PHP_CodeSniffer.
19 *
20 * PHP version 5
21 *
22 * @category  PHP
23 * @package   PHP_CodeSniffer
24 * @author    Gabriele Santini <gsantini@sqli.com>
25 * @author    Greg Sherwood <gsherwood@squiz.net>
26 * @copyright 2009-2014 SQLI <www.sqli.com>
27 * @copyright 2006-2014 Squiz Pty Ltd (ABN 77 084 670 600)
28 * @license   https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
29 * @version   Release: @package_version@
30 * @link      http://pear.php.net/package/PHP_CodeSniffer
31 */
32class PHP_CodeSniffer_Reports_Emacs implements PHP_CodeSniffer_Report
33{
34
35
36    /**
37     * Generate a partial report for a single processed file.
38     *
39     * Function should return TRUE if it printed or stored data about the file
40     * and FALSE if it ignored the file. Returning TRUE indicates that the file and
41     * its data should be counted in the grand totals.
42     *
43     * @param array                $report      Prepared report data.
44     * @param PHP_CodeSniffer_File $phpcsFile   The file being reported on.
45     * @param boolean              $showSources Show sources?
46     * @param int                  $width       Maximum allowed line width.
47     *
48     * @return boolean
49     */
50    public function generateFileReport(
51        $report,
52        PHP_CodeSniffer_File $phpcsFile,
53        $showSources=false,
54        $width=80
55    ) {
56        if ($report['errors'] === 0 && $report['warnings'] === 0) {
57            // Nothing to print.
58            return false;
59        }
60
61        foreach ($report['messages'] as $line => $lineErrors) {
62            foreach ($lineErrors as $column => $colErrors) {
63                foreach ($colErrors as $error) {
64                    $message = $error['message'];
65                    if ($showSources === true) {
66                        $message .= ' ('.$error['source'].')';
67                    }
68
69                    $type = strtolower($error['type']);
70                    echo $report['filename'].':'.$line.':'.$column.': '.$type.' - '.$message.PHP_EOL;
71                }
72            }
73        }
74
75        return true;
76
77    }//end generateFileReport()
78
79
80    /**
81     * Generates an emacs report.
82     *
83     * @param string  $cachedData    Any partial report data that was returned from
84     *                               generateFileReport during the run.
85     * @param int     $totalFiles    Total number of files processed during the run.
86     * @param int     $totalErrors   Total number of errors found during the run.
87     * @param int     $totalWarnings Total number of warnings found during the run.
88     * @param int     $totalFixable  Total number of problems that can be fixed.
89     * @param boolean $showSources   Show sources?
90     * @param int     $width         Maximum allowed line width.
91     * @param boolean $toScreen      Is the report being printed to screen?
92     *
93     * @return void
94     */
95    public function generate(
96        $cachedData,
97        $totalFiles,
98        $totalErrors,
99        $totalWarnings,
100        $totalFixable,
101        $showSources=false,
102        $width=80,
103        $toScreen=true
104    ) {
105        echo $cachedData;
106
107    }//end generate()
108
109
110}//end class
111