• 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/Xml.php
1
<?php
2
/**
3
 * XML 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\Config;
13
use PHP_CodeSniffer\Files\File;
14
use XMLWriter;
15

16
class Xml 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
     */
UNCOV
35
    public function generateFileReport($report, File $phpcsFile, $showSources=false, $width=80)
×
36
    {
37
        $out = new XMLWriter;
×
38
        $out->openMemory();
×
39
        $out->setIndent(true);
×
40
        $out->setIndentString('    ');
×
UNCOV
41
        $out->startDocument('1.0', 'UTF-8');
×
42

UNCOV
43
        if ($report['errors'] === 0 && $report['warnings'] === 0) {
×
44
            // Nothing to print.
UNCOV
45
            return false;
×
46
        }
47

48
        $out->startElement('file');
×
49
        $out->writeAttribute('name', $report['filename']);
×
50
        $out->writeAttribute('errors', $report['errors']);
×
51
        $out->writeAttribute('warnings', $report['warnings']);
×
UNCOV
52
        $out->writeAttribute('fixable', $report['fixable']);
×
53

54
        foreach ($report['messages'] as $line => $lineErrors) {
×
55
            foreach ($lineErrors as $column => $colErrors) {
×
56
                foreach ($colErrors as $error) {
×
57
                    $error['type'] = strtolower($error['type']);
×
58
                    if ($phpcsFile->config->encoding !== 'utf-8') {
×
UNCOV
59
                        $error['message'] = iconv($phpcsFile->config->encoding, 'utf-8', $error['message']);
×
60
                    }
61

62
                    $out->startElement($error['type']);
×
63
                    $out->writeAttribute('line', $line);
×
64
                    $out->writeAttribute('column', $column);
×
65
                    $out->writeAttribute('source', $error['source']);
×
66
                    $out->writeAttribute('severity', $error['severity']);
×
67
                    $out->writeAttribute('fixable', (int) $error['fixable']);
×
68
                    $out->text($error['message']);
×
UNCOV
69
                    $out->endElement();
×
70
                }
71
            }
72
        }//end foreach
73

UNCOV
74
        $out->endElement();
×
75

76
        // Remove the start of the document because we will
77
        // add that manually later. We only have it in here to
78
        // properly set the encoding.
79
        $content = $out->flush();
×
80
        if (strpos($content, PHP_EOL) !== false) {
×
81
            $content = substr($content, (strpos($content, PHP_EOL) + strlen(PHP_EOL)));
×
82
        } else if (strpos($content, "\n") !== false) {
×
UNCOV
83
            $content = substr($content, (strpos($content, "\n") + 1));
×
84
        }
85

UNCOV
86
        echo $content;
×
87

UNCOV
88
        return true;
×
89

90
    }//end generateFileReport()
91

92

93
    /**
94
     * Prints all violations for processed files, in a proprietary XML format.
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
    ) {
120
        echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
×
121
        echo '<phpcs version="'.Config::VERSION.'">'.PHP_EOL;
×
122
        echo $cachedData;
×
UNCOV
123
        echo '</phpcs>'.PHP_EOL;
×
124

125
    }//end generate()
126

127

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