~ubuntu-branches/ubuntu/vivid/php-codesniffer/vivid

« back to all changes in this revision

Viewing changes to PHP_CodeSniffer-1.5.5/CodeSniffer/Reports/Full.php

  • Committer: Package Import Robot
  • Author(s): David Prévot, Greg Sherwood, Alexey, Emily, David Prévot
  • Date: 2014-09-26 13:44:35 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20140926134435-wvjq16miqq4d60y0
Tags: 1.5.5-1
[ Greg Sherwood ]
* Improved closure support in Generic ScopeIndentSniff
* Improved indented PHP tag support in Generic ScopeIndentSniff
* Standards can now be located within hidden directories
 (further fix for bug #20323)
* Fixed bug #20373 : Inline comment sniff tab handling way
* Fixed bug #20378 : Report appended to existing file if no errors
  found in run
* Fixed bug #20381 : Invalid "Comment closer must be on a new line"
* PHP tokenizer no longer converts class/function names to special
  tokens types
* Fixed bug #20386 : Squiz.Commenting.ClassComment.SpacingBefore
  thrown if first block comment
* Squiz and PEAR FunctionCommentSnif now support _()
* PEAR ValidFunctionNameSniff no longer throws an error for _()
* Fixed bug #248 : FunctionCommentSniff expects ampersand on param name
* Fixed bug #248 in Squiz sniff as well
* Fixed bug #265 : False positives with type hints in ForbiddenFunctionsSniff
* Prepare for 1.5.5 release

[ Alexey ]
* Allowed single undersored methods and functions

[ Emily ]
* Added var_dump to discouraged functions sniff

[ David Prévot ]
* Revert "Add XS-Testsuite still needed for ci.d.n"
* Add self to uploaders
* Bump standards version to 3.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Full 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
 * Full 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: 1.5.5
 
30
 * @link      http://pear.php.net/package/PHP_CodeSniffer
 
31
 */
 
32
class PHP_CodeSniffer_Reports_Full 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 boolean $showSources Show sources?
 
45
     * @param int     $width       Maximum allowed line width.
 
46
     *
 
47
     * @return boolean
 
48
     */
 
49
    public function generateFileReport(
 
50
        $report,
 
51
        $showSources=false,
 
52
        $width=80
 
53
    ) {
 
54
        if ($report['errors'] === 0 && $report['warnings'] === 0) {
 
55
            // Nothing to print.
 
56
            return false;
 
57
        }
 
58
 
 
59
        $width = max($width, 70);
 
60
        $file  = $report['filename'];
 
61
 
 
62
        echo PHP_EOL.'FILE: ';
 
63
        if (strlen($file) <= ($width - 9)) {
 
64
            echo $file;
 
65
        } else {
 
66
            echo '...'.substr($file, (strlen($file) - ($width - 9)));
 
67
        }
 
68
 
 
69
        echo PHP_EOL;
 
70
        echo str_repeat('-', $width).PHP_EOL;
 
71
 
 
72
        echo 'FOUND '.$report['errors'].' ERROR(S) ';
 
73
        if ($report['warnings'] > 0) {
 
74
            echo 'AND '.$report['warnings'].' WARNING(S) ';
 
75
        }
 
76
 
 
77
        echo 'AFFECTING '.count($report['messages']).' LINE(S)'.PHP_EOL;
 
78
        echo str_repeat('-', $width).PHP_EOL;
 
79
 
 
80
        // Work out the max line number for formatting.
 
81
        $maxLineLength = max(array_map('strlen', array_keys($report['messages'])));
 
82
 
 
83
        // The length of the word ERROR or WARNING; used for padding.
 
84
        if ($report['warnings'] > 0) {
 
85
            $typeLength = 7;
 
86
        } else {
 
87
            $typeLength = 5;
 
88
        }
 
89
 
 
90
        // The padding that all lines will require that are
 
91
        // printing an error message overflow.
 
92
        $paddingLine2  = str_repeat(' ', ($maxLineLength + 1));
 
93
        $paddingLine2 .= ' | ';
 
94
        $paddingLine2 .= str_repeat(' ', $typeLength);
 
95
        $paddingLine2 .= ' | ';
 
96
 
 
97
        // The maximum amount of space an error message can use.
 
98
        $maxErrorSpace = ($width - strlen($paddingLine2) - 1);
 
99
 
 
100
        foreach ($report['messages'] as $line => $lineErrors) {
 
101
            foreach ($lineErrors as $column => $colErrors) {
 
102
                foreach ($colErrors as $error) {
 
103
                    $message = $error['message'];
 
104
                    if ($showSources === true) {
 
105
                        $message .= ' ('.$error['source'].')';
 
106
                    }
 
107
 
 
108
                    // The padding that goes on the front of the line.
 
109
                    $padding  = ($maxLineLength - strlen($line));
 
110
                    $errorMsg = wordwrap(
 
111
                        $message,
 
112
                        $maxErrorSpace,
 
113
                        PHP_EOL.$paddingLine2
 
114
                    );
 
115
 
 
116
                    echo ' '.str_repeat(' ', $padding).$line.' | '.$error['type'];
 
117
                    if ($error['type'] === 'ERROR') {
 
118
                        if ($report['warnings'] > 0) {
 
119
                            echo '  ';
 
120
                        }
 
121
                    }
 
122
 
 
123
                    echo ' | '.$errorMsg.PHP_EOL;
 
124
                }//end foreach
 
125
            }//end foreach
 
126
        }//end foreach
 
127
 
 
128
        echo str_repeat('-', $width).PHP_EOL.PHP_EOL;
 
129
        return true;
 
130
 
 
131
    }//end generateFileReport()
 
132
 
 
133
 
 
134
    /**
 
135
     * Prints all errors and warnings for each file processed.
 
136
     *
 
137
     * @param string  $cachedData    Any partial report data that was returned from
 
138
     *                               generateFileReport during the run.
 
139
     * @param int     $totalFiles    Total number of files processed during the run.
 
140
     * @param int     $totalErrors   Total number of errors found during the run.
 
141
     * @param int     $totalWarnings Total number of warnings found during the run.
 
142
     * @param boolean $showSources   Show sources?
 
143
     * @param int     $width         Maximum allowed line width.
 
144
     * @param boolean $toScreen      Is the report being printed to screen?
 
145
     *
 
146
     * @return void
 
147
     */
 
148
    public function generate(
 
149
        $cachedData,
 
150
        $totalFiles,
 
151
        $totalErrors,
 
152
        $totalWarnings,
 
153
        $showSources=false,
 
154
        $width=80,
 
155
        $toScreen=true
 
156
    ) {
 
157
        if ($cachedData === '') {
 
158
            return;
 
159
        }
 
160
 
 
161
        echo $cachedData;
 
162
 
 
163
        if ($toScreen === true
 
164
            && PHP_CODESNIFFER_INTERACTIVE === false
 
165
            && class_exists('PHP_Timer', false) === true
 
166
        ) {
 
167
            echo PHP_Timer::resourceUsage().PHP_EOL.PHP_EOL;
 
168
        }
 
169
 
 
170
    }//end generate()
 
171
 
 
172
 
 
173
}//end class
 
174
 
 
175
?>