• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PHPCSStandards / PHP_CodeSniffer / 14516416464

17 Apr 2025 01:09PM UTC coverage: 77.945% (+0.3%) from 77.666%
14516416464

push

github

web-flow
Merge pull request #1010 from PHPCSStandards/phpcs-4.0/feature/sq-1612-stdout-vs-stderr

(Nearly) All status, debug, and progress output is now sent to STDERR instead of STDOUT

63 of 457 new or added lines in 18 files covered. (13.79%)

1 existing line in 1 file now uncovered.

19455 of 24960 relevant lines covered (77.94%)

78.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Reports/Diff.php
1
<?php
2
/**
3
 * Diff report for PHP_CodeSniffer.
4
 *
5
 * @author    Greg Sherwood <gsherwood@squiz.net>
6
 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
7
 * @license   https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
8
 */
9

10
namespace PHP_CodeSniffer\Reports;
11

12
use PHP_CodeSniffer\Files\File;
13
use PHP_CodeSniffer\Util\Writers\StatusWriter;
14

15
class Diff implements Report
16
{
17

18

19
    /**
20
     * Generate a partial report for a single processed file.
21
     *
22
     * Function should return TRUE if it printed or stored data about the file
23
     * and FALSE if it ignored the file. Returning TRUE indicates that the file and
24
     * its data should be counted in the grand totals.
25
     *
26
     * @param array<string, string|int|array> $report      Prepared report data.
27
     *                                                     See the {@see Report} interface for a detailed specification.
28
     * @param \PHP_CodeSniffer\Files\File     $phpcsFile   The file being reported on.
29
     * @param bool                            $showSources Show sources?
30
     * @param int                             $width       Maximum allowed line width.
31
     *
32
     * @return bool
33
     */
34
    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
×
35
    {
36
        $errors = $phpcsFile->getFixableCount();
×
37
        if ($errors === 0) {
×
38
            return false;
×
39
        }
40

41
        $phpcsFile->disableCaching();
×
42
        $tokens = $phpcsFile->getTokens();
×
43
        if (empty($tokens) === true) {
×
44
            if (PHP_CODESNIFFER_VERBOSITY === 1) {
×
45
                $startTime = microtime(true);
×
NEW
46
                StatusWriter::write('DIFF report is parsing '.basename($report['filename']).' ', 0, 0);
×
47
            } else if (PHP_CODESNIFFER_VERBOSITY > 1) {
×
NEW
48
                StatusWriter::write('DIFF report is forcing parse of '.$report['filename']);
×
49
            }
50

51
            $phpcsFile->parse();
×
52

53
            if (PHP_CODESNIFFER_VERBOSITY === 1) {
×
54
                $timeTaken = ((microtime(true) - $startTime) * 1000);
×
55
                if ($timeTaken < 1000) {
×
56
                    $timeTaken = round($timeTaken);
×
NEW
57
                    StatusWriter::write("DONE in {$timeTaken}ms");
×
58
                } else {
59
                    $timeTaken = round(($timeTaken / 1000), 2);
×
NEW
60
                    StatusWriter::write("DONE in $timeTaken secs");
×
61
                }
62
            }
63

64
            $phpcsFile->fixer->startFile($phpcsFile);
×
65
        }//end if
66

67
        if (PHP_CODESNIFFER_VERBOSITY > 1) {
×
68
            ob_end_clean();
×
NEW
69
            StatusWriter::write('*** START FILE FIXING ***', 1);
×
70
        }
71

72
        $fixed = $phpcsFile->fixer->fixFile();
×
73

74
        if (PHP_CODESNIFFER_VERBOSITY > 1) {
×
NEW
75
            StatusWriter::write('*** END FILE FIXING ***', 1);
×
76
            ob_start();
×
77
        }
78

79
        if ($fixed === false) {
×
80
            return false;
×
81
        }
82

83
        $diff = $phpcsFile->fixer->generateDiff();
×
84
        if ($diff === '') {
×
85
            // Nothing to print.
86
            return false;
×
87
        }
88

89
        echo $diff.PHP_EOL;
×
90
        return true;
×
91

92
    }//end generateFileReport()
93

94

95
    /**
96
     * Prints all errors and warnings for each file processed.
97
     *
98
     * @param string $cachedData    Any partial report data that was returned from
99
     *                              generateFileReport during the run.
100
     * @param int    $totalFiles    Total number of files processed during the run.
101
     * @param int    $totalErrors   Total number of errors found during the run.
102
     * @param int    $totalWarnings Total number of warnings found during the run.
103
     * @param int    $totalFixable  Total number of problems that can be fixed.
104
     * @param bool   $showSources   Show sources?
105
     * @param int    $width         Maximum allowed line width.
106
     * @param bool   $interactive   Are we running in interactive mode?
107
     * @param bool   $toScreen      Is the report being printed to screen?
108
     *
109
     * @return void
110
     */
111
    public function generate(
×
112
        $cachedData,
113
        $totalFiles,
114
        $totalErrors,
115
        $totalWarnings,
116
        $totalFixable,
117
        $showSources=false,
118
        $width=80,
119
        $interactive=false,
120
        $toScreen=true
121
    ) {
122
        echo $cachedData;
×
123
        if ($toScreen === true && $cachedData !== '') {
×
124
            echo PHP_EOL;
×
125
        }
126

127
    }//end generate()
128

129

130
}//end class
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc