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

PHPCSStandards / PHP_CodeSniffer / 9756730629

02 Jul 2024 07:25AM UTC coverage: 73.743%. Remained the same
9756730629

push

github

jrfnl
CS/QA: remove unused `foreach` keys from report code

As the array format is now documented, these unused variables are no longer needed for documentation purposes.

Co-authored-by: Klaus Purer <klaus.purer@protonmail.ch>

0 of 9 new or added lines in 4 files covered. (0.0%)

495 existing lines in 17 files now uncovered.

17949 of 24340 relevant lines covered (73.74%)

70.96 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\Common;
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
     */
UNCOV
34
    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
×
35
    {
36
        $errors = $phpcsFile->getFixableCount();
×
37
        if ($errors === 0) {
×
UNCOV
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);
×
46
                Common::printStatusMessage('DIFF report is parsing '.basename($report['filename']).' ', 0, true);
×
47
            } else if (PHP_CODESNIFFER_VERBOSITY > 1) {
×
UNCOV
48
                Common::printStatusMessage('DIFF report is forcing parse of '.$report['filename']);
×
49
            }
50

UNCOV
51
            $phpcsFile->parse();
×
52

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

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

67
        if (PHP_CODESNIFFER_VERBOSITY > 1) {
×
UNCOV
68
            Common::printStatusMessage('*** START FILE FIXING ***', 1);
×
69
        }
70

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

73
        if (PHP_CODESNIFFER_VERBOSITY > 1) {
×
UNCOV
74
            Common::printStatusMessage('*** END FILE FIXING ***', 1);
×
75
        }
76

77
        if ($fixed === false) {
×
UNCOV
78
            return false;
×
79
        }
80

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

87
        echo $diff.PHP_EOL;
×
UNCOV
88
        return true;
×
89

90
    }//end generateFileReport()
91

92

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

122
    }//end generate()
123

124

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