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

ThrowErrorsAsExceptionsOptions   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 16
c 1
b 0
f 1
dl 0
loc 58
ccs 15
cts 18
cp 0.8333
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addConfiguration() 0 9 1
A getLogger() 0 3 1
A __construct() 0 4 1
A getLevels() 0 3 1
A getOptions() 0 7 1
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