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

PHPCSStandards / PHP_CodeSniffer / 15253296250

26 May 2025 11:55AM UTC coverage: 78.632% (+0.3%) from 78.375%
15253296250

Pull #1105

github

web-flow
Merge d9441d98f into caf806050
Pull Request #1105: Skip tests when 'git' command is not available

19665 of 25009 relevant lines covered (78.63%)

88.67 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\Timing;
14
use PHP_CodeSniffer\Util\Writers\StatusWriter;
15

16
class Diff implements Report
17
{
18

19

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

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

52
            $phpcsFile->parse();
×
53

54
            if (PHP_CODESNIFFER_VERBOSITY === 1) {
×
55
                StatusWriter::write('DONE in '.Timing::getHumanReadableDuration(Timing::getDurationSince($startTime)));
×
56
            }
57

58
            $phpcsFile->fixer->startFile($phpcsFile);
×
59
        }//end if
60

61
        if (PHP_CODESNIFFER_VERBOSITY > 1) {
×
62
            StatusWriter::write('*** START FILE FIXING ***', 1);
×
63
        }
64

65
        $fixed = $phpcsFile->fixer->fixFile();
×
66

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

71
        if ($fixed === false) {
×
72
            return false;
×
73
        }
74

75
        $diff = $phpcsFile->fixer->generateDiff();
×
76
        if ($diff === '') {
×
77
            // Nothing to print.
78
            return false;
×
79
        }
80

81
        echo $diff.PHP_EOL;
×
82
        return true;
×
83

84
    }//end generateFileReport()
85

86

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

119
    }//end generate()
120

121

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