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

DisplayPrettyExceptionsOptions::getOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 6
ccs 0
cts 5
cp 0
crap 2
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\DisplayPrettyExceptions;
15
16
use Ekino\Drupal\Debug\Configuration\CharsetConfigurationTrait;
17
use Ekino\Drupal\Debug\Configuration\FileLinkFormatConfigurationTrait;
18
use Ekino\Drupal\Debug\Configuration\LoggerConfigurationTrait;
19
use Ekino\Drupal\Debug\Configuration\Model\ActionConfiguration;
20
use Ekino\Drupal\Debug\Configuration\Model\DefaultsConfiguration;
21
use Ekino\Drupal\Debug\Option\OptionsInterface;
22
use Psr\Log\LoggerInterface;
23
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
24
25
class DisplayPrettyExceptionsOptions implements OptionsInterface
26
{
27
    use CharsetConfigurationTrait;
28
    use FileLinkFormatConfigurationTrait;
29
    use LoggerConfigurationTrait;
30
31
    /**
32
     * @var string|null
33
     */
34
    private $charset;
35
36
    /**
37
     * @var string|null
38
     */
39
    private $fileLinkFormat;
40
41
    /**
42
     * @var LoggerInterface|null
43
     */
44
    private $logger;
45
46
    /**
47
     * @param string|null          $charset
48
     * @param string|null          $fileLinkFormat
49
     * @param LoggerInterface|null $logger
50
     */
51 8
    public function __construct(?string $charset, ?string $fileLinkFormat, ?LoggerInterface $logger)
52
    {
53 8
        $this->charset = $charset;
54 8
        $this->fileLinkFormat = $fileLinkFormat;
55 8
        $this->logger = $logger;
56 8
    }
57
58
    /**
59
     * @return string|null
60
     */
61 2
    public function getCharset(): ?string
62
    {
63 2
        return $this->charset;
64
    }
65
66
    /**
67
     * @return string|null
68
     */
69 2
    public function getFileLinkFormat(): ?string
70
    {
71 2
        return $this->fileLinkFormat;
72
    }
73
74
    /**
75
     * @return LoggerInterface|null
76
     */
77 2
    public function getLogger(): ?LoggerInterface
78
    {
79 2
        return $this->logger;
80
    }
81
82 18
    public static function addConfiguration(NodeBuilder $nodeBuilder, DefaultsConfiguration $defaultsConfiguration): void
83
    {
84 18
        self::addCharsetConfigurationNodeFromDefaultsConfiguration($nodeBuilder, $defaultsConfiguration);
85 18
        self::addFileLinkFormatConfigurationNodeFromDefaultsConfiguration($nodeBuilder, $defaultsConfiguration);
86 18
        self::addLoggerConfigurationNodeFromDefaultsConfiguration($nodeBuilder, $defaultsConfiguration);
87 18
    }
88
89
    public static function getOptions(string $appRoot, ActionConfiguration $actionConfiguration): OptionsInterface
90
    {
91
        return new self(
92
            self::getConfiguredCharset($actionConfiguration),
93
            self::getConfiguredFileLinkFormat($actionConfiguration),
94
            self::getConfiguredLogger($actionConfiguration)
95
        );
96
    }
97
}
98