• 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/FixReport/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\FixReport;
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
    /**
58
     * @return $this
59
     */
60
    public function registerReporter(ReporterInterface $reporter): self
61
    {
62
        $format = $reporter->getFormat();
5✔
63

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

68
        $this->reporters[$format] = $reporter;
5✔
69

70
        return $this;
5✔
71
    }
72

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

81
        return $formats;
2✔
82
    }
83

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

90
        return $this->reporters[$format];
1✔
91
    }
92
}
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