Completed
Pull Request — master (#77)
by Thomas
05:39
created

ThrowErrorsAsExceptionsOptions::addConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the ekino Drupal Debug project.
7
 *
8
 * (c) ekino
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Ekino\Drupal\Debug\Action\ThrowErrorsAsExceptions;
15
16
use Ekino\Drupal\Debug\Configuration\LoggerConfigurationTrait;
17
use Ekino\Drupal\Debug\Configuration\Model\ActionConfiguration;
18
use Ekino\Drupal\Debug\Configuration\Model\DefaultsConfiguration;
19
use Ekino\Drupal\Debug\Option\OptionsInterface;
20
use Psr\Log\LoggerInterface;
21
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
22
23
class ThrowErrorsAsExceptionsOptions implements OptionsInterface
24
{
25
    use LoggerConfigurationTrait;
26
27
    /**
28
     * @var int
29
     */
30
    private $levels;
31
32
    /**
33
     * @var LoggerInterface|null
34
     */
35
    private $logger;
36
37
    /**
38
     * @param int                  $levels
39
     * @param LoggerInterface|null $logger
40
     */
41 7
    public function __construct(int $levels, ?LoggerInterface $logger)
42
    {
43 7
        $this->levels = $levels;
44 7
        $this->logger = $logger;
45 7
    }
46
47
    /**
48
     * @return int
49
     */
50 3
    public function getLevels(): int
51
    {
52 3
        return $this->levels;
53
    }
54
55
    /**
56
     * @return LoggerInterface|null
57
     */
58 4
    public function getLogger(): ?LoggerInterface
59
    {
60 4
        return $this->logger;
61
    }
62
63 18
    public static function addConfiguration(NodeBuilder $nodeBuilder, DefaultsConfiguration $defaultsConfiguration): void
64
    {
65
        $nodeBuilder
66 18
            ->integerNode('levels')
67 18
                ->isRequired()
68 18
                ->defaultValue(E_ALL & ~E_WARNING & ~E_USER_WARNING)
69 18
            ->end();
70
71 18
        self::addLoggerConfigurationNodeFromDefaultsConfiguration($nodeBuilder, $defaultsConfiguration);
72 18
    }
73
74
    public static function getOptions(string $appRoot, ActionConfiguration $actionConfiguration): OptionsInterface
75
    {
76
        $processedConfiguration = $actionConfiguration->getProcessedConfiguration();
77
78
        //todo : evaluate les const E_* passé en string dans la conf ?
79
80
        return new self($processedConfiguration['levels'], self::getConfiguredLogger($actionConfiguration));
81
    }
82
}
83