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

PHPCSStandards / PHP_CodeSniffer / 14434600573

14 Apr 2025 12:01AM UTC coverage: 78.902%. Remained the same
14434600573

Pull #967

github

web-flow
Merge e2f817c09 into 7925a214c
Pull Request #967: PrintProgressDotsTest: fix up param names in data sets

24963 of 31638 relevant lines covered (78.9%)

68.08 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

14
class Diff implements Report
15
{
16

17

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

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

50
            $phpcsFile->parse();
×
51

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

62
                echo PHP_EOL;
×
63
            }
64

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

68
        if (PHP_CODESNIFFER_VERBOSITY > 1) {
×
69
            ob_end_clean();
×
70
            echo "\t*** START FILE FIXING ***".PHP_EOL;
×
71
        }
72

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

75
        if (PHP_CODESNIFFER_VERBOSITY > 1) {
×
76
            echo "\t*** END FILE FIXING ***".PHP_EOL;
×
77
            ob_start();
×
78
        }
79

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

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

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

93
    }//end generateFileReport()
94

95

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

128
    }//end generate()
129

130

131
}//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

© 2025 Coveralls, Inc