Config::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Bex\Behat\StepTimeLoggerExtension\ServiceContainer;
4
5
use Bex\Behat\StepTimeLoggerExtension\Service\OutputPrinter\OutputPrinterInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
8
class Config
9
{
10
    const CONFIG_KEY_ENABLED_ALWAYS = 'enabled_always';
11
    const CONFIG_KEY_OUTPUT_DIRECTORY = 'output_directory';
12
    const CONFIG_KEY_FORMAT = 'output';
13
14
    /**
15
     * @var ContainerBuilder
16
     */
17
    private $container;
18
19
    /**
20
     * @var bool
21
     */
22
    private $enabled;
23
24
    /**
25
     * @var string
26
     */
27
    private $outputDirectory;
28
29
    /**
30
     * @var array
31
     */
32
    private $outputFormats;
33
34
    /**
35
     * @param ContainerBuilder $container
36
     * @param array            $config
37
     */
38
    public function __construct(ContainerBuilder $container, $config)
39
    {
40
        $this->container = $container;
41
        $this->enabled = $config[self::CONFIG_KEY_ENABLED_ALWAYS];
42
        $this->outputDirectory = $config[self::CONFIG_KEY_OUTPUT_DIRECTORY];
43
        $this->outputFormats = $config[self::CONFIG_KEY_FORMAT];
44
    }
45
46
    /**
47
     * Activate the extension
48
     * 
49
     * @return void
50
     */
51
    public function enableLogging()
52
    {
53
        $this->enabled = true;
54
    }
55
56
    /**
57
     * @return boolean
58
     */
59
    public function isEnabled()
60
    {
61
        return $this->enabled;
62
    }
63
64
    /**
65
     * @return string
66
     */
67
    public function getOutputDirectory()
68
    {
69
        return $this->outputDirectory;
70
    }
71
72
    /**
73
     * @return OutputPrinterInterface[]
74
     */
75
    public function getOutputPrinters()
76
    {
77
        $printers = [];
78
79
        foreach ($this->outputFormats as $format) {
80
            $printer = $this->container->get(OutputPrinterInterface::SERVICE_ID_PREFIX . '.' . $format);
81
            $printer->configure($this);
82
            $printers[] = $printer;
83
        }
84
85
        return $printers;
86
    }
87
}