forked from easy-coding-standard/ecs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutputFormatterCollector.php
More file actions
42 lines (34 loc) · 1.19 KB
/
OutputFormatterCollector.php
File metadata and controls
42 lines (34 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
declare(strict_types=1);
namespace Symplify\EasyCodingStandard\Console\Output;
use Symplify\EasyCodingStandard\Contract\Console\Output\OutputFormatterInterface;
use Symplify\EasyCodingStandard\Exception\Configuration\OutputFormatterNotFoundException;
final class OutputFormatterCollector
{
/**
* @var array<string, OutputFormatterInterface>
*/
private array $outputFormatters = [];
/**
* @param OutputFormatterInterface[] $outputFormatters
*/
public function __construct(array $outputFormatters)
{
foreach ($outputFormatters as $outputFormatter) {
$this->outputFormatters[$outputFormatter->getName()] = $outputFormatter;
}
}
public function getByName(string $name): OutputFormatterInterface
{
if (isset($this->outputFormatters[$name])) {
return $this->outputFormatters[$name];
}
$outputFormatterKeys = array_keys($this->outputFormatters);
$errorMessage = sprintf(
'Output formatter "%s" not found. Use one of: "%s".',
$name,
implode('", "', $outputFormatterKeys)
);
throw new OutputFormatterNotFoundException($errorMessage);
}
}