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

PHPCSStandards / PHP_CodeSniffer / 17662127818

12 Sep 2025 01:50AM UTC coverage: 78.786%. Remained the same
17662127818

push

github

web-flow
Merge pull request #1241 from PHPCSStandards/phpcs-4.x/feature/155-normalize-some-code-style-rules-3

CS: normalize code style rules [3]

343 of 705 new or added lines in 108 files covered. (48.65%)

3 existing lines in 3 files now uncovered.

19732 of 25045 relevant lines covered (78.79%)

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

43
        if ($report['errors'] === 0 && $report['warnings'] === 0) {
×
44
            // Nothing to print.
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']);
×
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') {
×
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']);
×
69
                    $out->endElement();
×
70
                }
71
            }
72
        }//end foreach
73

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) {
×
83
            $content = substr($content, (strpos($content, "\n") + 1));
×
84
        }
85

86
        echo $content;
×
87

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
     */
109
    public function generate(
×
110
        string $cachedData,
111
        int $totalFiles,
112
        int $totalErrors,
113
        int $totalWarnings,
114
        int $totalFixable,
115
        bool $showSources = false,
116
        int $width = 80,
117
        bool $interactive = false,
118
        bool $toScreen = true
119
    ) {
NEW
120
        echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
×
NEW
121
        echo '<phpcs version="' . Config::VERSION . '">' . PHP_EOL;
×
122
        echo $cachedData;
×
NEW
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