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

PHP-CS-Fixer / PHP-CS-Fixer / 15946544397

28 Jun 2025 05:30PM UTC coverage: 94.83% (-0.009%) from 94.839%
15946544397

push

github

web-flow
chore: handle saveXML failures explicitly (#8755)

10 of 13 new or added lines in 4 files covered. (76.92%)

28140 of 29674 relevant lines covered (94.83%)

45.33 hits per line

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

90.91
/src/Console/Report/FixReport/CheckstyleReporter.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of PHP CS Fixer.
7
 *
8
 * (c) Fabien Potencier <fabien@symfony.com>
9
 *     Dariusz Rumiński <dariusz.ruminski@gmail.com>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14

15
namespace PhpCsFixer\Console\Report\FixReport;
16

17
use PhpCsFixer\Console\Application;
18
use Symfony\Component\Console\Formatter\OutputFormatter;
19

20
/**
21
 * @author Kévin Gomez <contact@kevingomez.fr>
22
 *
23
 * @readonly
24
 *
25
 * @internal
26
 */
27
final class CheckstyleReporter implements ReporterInterface
28
{
29
    public function getFormat(): string
30
    {
31
        return 'checkstyle';
1✔
32
    }
33

34
    public function generate(ReportSummary $reportSummary): string
35
    {
36
        if (!\extension_loaded('dom')) {
6✔
37
            throw new \RuntimeException('Cannot generate report! `ext-dom` is not available!');
×
38
        }
39

40
        $dom = new \DOMDocument('1.0', 'UTF-8');
6✔
41

42
        /** @var \DOMElement $checkstyles */
43
        $checkstyles = $dom->appendChild($dom->createElement('checkstyle'));
6✔
44
        $checkstyles->setAttribute('version', Application::getAbout());
6✔
45

46
        foreach ($reportSummary->getChanged() as $filePath => $fixResult) {
6✔
47
            /** @var \DOMElement $file */
48
            $file = $checkstyles->appendChild($dom->createElement('file'));
5✔
49
            $file->setAttribute('name', $filePath);
5✔
50

51
            foreach ($fixResult['appliedFixers'] as $appliedFixer) {
5✔
52
                $error = $this->createError($dom, $appliedFixer);
5✔
53
                $file->appendChild($error);
5✔
54
            }
55
        }
56

57
        $dom->formatOutput = true;
6✔
58

59
        $result = $dom->saveXML();
6✔
60
        if (false === $result) {
6✔
NEW
61
            throw new \RuntimeException('Failed to generate XML output');
×
62
        }
63

64
        return $reportSummary->isDecoratedOutput() ? OutputFormatter::escape($result) : $result;
6✔
65
    }
66

67
    private function createError(\DOMDocument $dom, string $appliedFixer): \DOMElement
68
    {
69
        $error = $dom->createElement('error');
5✔
70
        $error->setAttribute('severity', 'warning');
5✔
71
        $error->setAttribute('source', 'PHP-CS-Fixer.'.$appliedFixer);
5✔
72
        $error->setAttribute('message', 'Found violation(s) of type: '.$appliedFixer);
5✔
73

74
        return $error;
5✔
75
    }
76
}
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