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

PHPCSStandards / PHP_CodeSniffer / 13887072476

16 Mar 2025 08:25PM UTC coverage: 78.682%. Remained the same
13887072476

Pull #882

github

web-flow
Merge 9fd6cc2aa into 384f8e824
Pull Request #882: Ruleset: add tests to document trimming behaviour

24832 of 31560 relevant lines covered (78.68%)

66.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Reports/Checkstyle.php
1
<?php
2
/**
3
 * Checkstyle 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 Checkstyle 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
        $out = new XMLWriter;
×
38
        $out->openMemory();
×
39
        $out->setIndent(true);
×
40

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

46
        $out->startElement('file');
×
47
        $out->writeAttribute('name', $report['filename']);
×
48

49
        foreach ($report['messages'] as $line => $lineErrors) {
×
50
            foreach ($lineErrors as $column => $colErrors) {
×
51
                foreach ($colErrors as $error) {
×
52
                    $error['type'] = strtolower($error['type']);
×
53
                    if ($phpcsFile->config->encoding !== 'utf-8') {
×
54
                        $error['message'] = iconv($phpcsFile->config->encoding, 'utf-8', $error['message']);
×
55
                    }
56

57
                    $out->startElement('error');
×
58
                    $out->writeAttribute('line', $line);
×
59
                    $out->writeAttribute('column', $column);
×
60
                    $out->writeAttribute('severity', $error['type']);
×
61
                    $out->writeAttribute('message', $error['message']);
×
62
                    $out->writeAttribute('source', $error['source']);
×
63
                    $out->endElement();
×
64
                }
65
            }
66
        }//end foreach
67

68
        $out->endElement();
×
69
        echo $out->flush();
×
70

71
        return true;
×
72

73
    }//end generateFileReport()
74

75

76
    /**
77
     * Prints all violations for processed files, in a Checkstyle format.
78
     *
79
     * @param string $cachedData    Any partial report data that was returned from
80
     *                              generateFileReport during the run.
81
     * @param int    $totalFiles    Total number of files processed during the run.
82
     * @param int    $totalErrors   Total number of errors found during the run.
83
     * @param int    $totalWarnings Total number of warnings found during the run.
84
     * @param int    $totalFixable  Total number of problems that can be fixed.
85
     * @param bool   $showSources   Show sources?
86
     * @param int    $width         Maximum allowed line width.
87
     * @param bool   $interactive   Are we running in interactive mode?
88
     * @param bool   $toScreen      Is the report being printed to screen?
89
     *
90
     * @return void
91
     */
92
    public function generate(
×
93
        $cachedData,
94
        $totalFiles,
95
        $totalErrors,
96
        $totalWarnings,
97
        $totalFixable,
98
        $showSources=false,
99
        $width=80,
100
        $interactive=false,
101
        $toScreen=true
102
    ) {
103
        echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
×
104
        echo '<checkstyle version="'.Config::VERSION.'">'.PHP_EOL;
×
105
        echo $cachedData;
×
106
        echo '</checkstyle>'.PHP_EOL;
×
107

108
    }//end generate()
109

110

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