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

PHP-CS-Fixer / PHP-CS-Fixer / 3721300657

pending completion
3721300657

push

github

GitHub
minor: Follow PSR12 ordered imports in Symfony ruleset (#6712)

9 of 9 new or added lines in 2 files covered. (100.0%)

22674 of 24281 relevant lines covered (93.38%)

39.08 hits per line

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

64.0
/src/Console/Report/ListSetsReport/ReporterFactory.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\ListSetsReport;
16

17
use Symfony\Component\Finder\Finder as SymfonyFinder;
18

19
/**
20
 * @author Boris Gorbylev <ekho@ekho.name>
21
 *
22
 * @internal
23
 */
24
final class ReporterFactory
25
{
26
    /**
27
     * @var array<string, ReporterInterface>
28
     */
29
    private array $reporters = [];
30

31
    public function registerBuiltInReporters(): self
32
    {
33
        /** @var null|list<string> $builtInReporters */
34
        static $builtInReporters;
2✔
35

36
        if (null === $builtInReporters) {
2✔
37
            $builtInReporters = [];
×
38

39
            foreach (SymfonyFinder::create()->files()->name('*Reporter.php')->in(__DIR__) as $file) {
×
40
                $relativeNamespace = $file->getRelativePath();
×
41
                $builtInReporters[] = sprintf(
×
42
                    '%s\\%s%s',
×
43
                    __NAMESPACE__,
×
44
                    $relativeNamespace ? $relativeNamespace.'\\' : '',
×
45
                    $file->getBasename('.php')
×
46
                );
×
47
            }
48
        }
49

50
        foreach ($builtInReporters as $reporterClass) {
2✔
51
            $this->registerReporter(new $reporterClass());
2✔
52
        }
53

54
        return $this;
2✔
55
    }
56

57
    public function registerReporter(ReporterInterface $reporter): self
58
    {
59
        $format = $reporter->getFormat();
5✔
60

61
        if (isset($this->reporters[$format])) {
5✔
62
            throw new \UnexpectedValueException(sprintf('Reporter for format "%s" is already registered.', $format));
1✔
63
        }
64

65
        $this->reporters[$format] = $reporter;
5✔
66

67
        return $this;
5✔
68
    }
69

70
    /**
71
     * @return list<string>
72
     */
73
    public function getFormats(): array
74
    {
75
        $formats = array_keys($this->reporters);
2✔
76
        sort($formats);
2✔
77

78
        return $formats;
2✔
79
    }
80

81
    public function getReporter(string $format): ReporterInterface
82
    {
83
        if (!isset($this->reporters[$format])) {
2✔
84
            throw new \UnexpectedValueException(sprintf('Reporter for format "%s" is not registered.', $format));
1✔
85
        }
86

87
        return $this->reporters[$format];
1✔
88
    }
89
}
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