~ubuntu-branches/ubuntu/trusty/php-codesniffer/trusty

« back to all changes in this revision

Viewing changes to PHP_CodeSniffer-1.3.4/CodeSniffer/Reports/Summary.php

  • Committer: Package Import Robot
  • Author(s): Thomas Goirand
  • Date: 2013-07-12 15:16:25 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20130712151625-4autdc0twzbueha9
Tags: 1.5.0~rc2-1
* New upstream release.
* Refreshed patch.
* Standards-Version is now 3.9.4.
* Canonical VCS URLs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/**
3
 
 * Summary 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 SQLI <www.sqli.com>
12
 
 * @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
13
 
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
14
 
 * @link      http://pear.php.net/package/PHP_CodeSniffer
15
 
 */
16
 
 
17
 
/**
18
 
 * Summary 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 SQLI <www.sqli.com>
27
 
 * @copyright 2006-2011 Squiz Pty Ltd (ABN 77 084 670 600)
28
 
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
29
 
 * @version   Release: 1.3.4
30
 
 * @link      http://pear.php.net/package/PHP_CodeSniffer
31
 
 */
32
 
class PHP_CodeSniffer_Reports_Summary implements PHP_CodeSniffer_Report
33
 
{
34
 
 
35
 
 
36
 
    /**
37
 
     * Generates a summary of errors and warnings for each file processed.
38
 
     * 
39
 
     * If verbose output is enabled, results are shown for all files, even if
40
 
     * they have no errors or warnings. If verbose output is disabled, we only
41
 
     * show files that have at least one warning or error.
42
 
     * 
43
 
     * @param array   $report      Prepared report.
44
 
     * @param boolean $showSources Show sources?
45
 
     * @param int     $width       Maximum allowed lne width.
46
 
     * @param boolean $toScreen    Is the report being printed to screen?
47
 
     *
48
 
     * @return string
49
 
     */
50
 
    public function generate(
51
 
        $report,
52
 
        $showSources=false,
53
 
        $width=80,
54
 
        $toScreen=true
55
 
    ) {
56
 
        $errorFiles = array();
57
 
        $width      = max($width, 70);
58
 
 
59
 
        foreach ($report['files'] as $filename => $file) {
60
 
            $numWarnings = $file['warnings'];
61
 
            $numErrors   = $file['errors'];
62
 
 
63
 
            // If verbose output is enabled, we show the results for all files,
64
 
            // but if not, we only show files that had errors or warnings.
65
 
            if (PHP_CODESNIFFER_VERBOSITY > 0
66
 
                || $numErrors > 0
67
 
                || $numWarnings > 0
68
 
            ) {
69
 
                $errorFiles[$filename] = array(
70
 
                                          'warnings' => $numWarnings,
71
 
                                          'errors'   => $numErrors,
72
 
                                         );
73
 
            }//end if
74
 
        }//end foreach
75
 
 
76
 
        if (empty($errorFiles) === true) {
77
 
            // Nothing to print.
78
 
            return 0;
79
 
        }
80
 
 
81
 
        echo PHP_EOL.'PHP CODE SNIFFER REPORT SUMMARY'.PHP_EOL;
82
 
        echo str_repeat('-', $width).PHP_EOL;
83
 
        echo 'FILE'.str_repeat(' ', ($width - 20)).'ERRORS  WARNINGS'.PHP_EOL;
84
 
        echo str_repeat('-', $width).PHP_EOL;
85
 
 
86
 
        $totalErrors   = 0;
87
 
        $totalWarnings = 0;
88
 
        $totalFiles    = 0;
89
 
 
90
 
        foreach ($errorFiles as $file => $errors) {
91
 
            $padding = ($width - 18 - strlen($file));
92
 
            if ($padding < 0) {
93
 
                $file    = '...'.substr($file, (($padding * -1) + 3));
94
 
                $padding = 0;
95
 
            }
96
 
 
97
 
            echo $file.str_repeat(' ', $padding).'  ';
98
 
            echo $errors['errors'];
99
 
            echo str_repeat(' ', (8 - strlen((string) $errors['errors'])));
100
 
            echo $errors['warnings'];
101
 
            echo PHP_EOL;
102
 
 
103
 
            $totalFiles++;
104
 
        }//end foreach
105
 
 
106
 
        echo str_repeat('-', $width).PHP_EOL;
107
 
        echo 'A TOTAL OF '.$report['totals']['errors'].' ERROR(S) ';
108
 
        echo 'AND '.$report['totals']['warnings'].' WARNING(S) ';
109
 
 
110
 
        echo 'WERE FOUND IN '.$totalFiles.' FILE(S)'.PHP_EOL;
111
 
        echo str_repeat('-', $width).PHP_EOL.PHP_EOL;
112
 
 
113
 
        if ($showSources === true) {
114
 
            $source = new PHP_CodeSniffer_Reports_Source();
115
 
            $source->generate($report, $showSources, $width);
116
 
        }
117
 
 
118
 
        if ($toScreen === true
119
 
            && PHP_CODESNIFFER_INTERACTIVE === false
120
 
            && class_exists('PHP_Timer', false) === true
121
 
        ) {
122
 
            echo PHP_Timer::resourceUsage().PHP_EOL.PHP_EOL;
123
 
        }
124
 
 
125
 
        return ($report['totals']['errors'] + $report['totals']['warnings']);
126
 
 
127
 
    }//end generate()
128
 
 
129
 
 
130
 
}//end class
131
 
 
132
 
?>