Completed
Push — master ( 139fb8...7c9eb0 )
by Thomas
10s
created

DefaultsConfiguration::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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\Configuration\Model;
15
16
use Monolog\Handler\StreamHandler;
17
use Monolog\Logger;
18
19
class DefaultsConfiguration extends AbstractConfiguration
20
{
21
    /**
22
     * @var false|Logger|null
23
     */
24
    private $logger;
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 2
    public function __construct(array $processedConfiguration)
30
    {
31 2
        parent::__construct($processedConfiguration);
32
33 2
        $this->logger = false;
34 2
    }
35
36
    /**
37
     * @return string
38
     */
39 2
    public function getCacheDirectory(): string
40
    {
41 2
        return $this->processedConfiguration['cache_directory'];
42
    }
43
44
    /**
45
     * @return Logger|null
46
     */
47 2
    public function getLogger(): ?Logger
48
    {
49 2
        if (false === $this->logger) {
50 2
            $loggerProcessedConfiguration = $this->processedConfiguration['logger'];
51
52 2
            $this->logger = $loggerProcessedConfiguration['enabled'] ? new Logger($loggerProcessedConfiguration['channel'], array(
53 2
                new StreamHandler($loggerProcessedConfiguration['file_path']),
54
            )) : null;
55
        }
56
57 2
        return $this->logger;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->logger could return the type true which is incompatible with the type-hinted return Monolog\Logger|null. Consider adding an additional type-check to rule them out.
Loading history...
58
    }
59
60
    /**
61
     * @return string|null
62
     */
63 2
    public function getCharset(): ?string
64
    {
65 2
        return $this->processedConfiguration['charset'];
66
    }
67
68
    /**
69
     * @return string|null
70
     */
71 2
    public function getFileLinkFormat(): ?string
72
    {
73 2
        return $this->processedConfiguration['file_link_format'];
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79 2
    public function serialize(): ?string
80
    {
81 2
        return \serialize(array(
82 2
            $this->processedConfiguration,
83 2
            null === $this->logger ? null : false,
84
        ));
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function unserialize($serialized): void
91
    {
92
        list($this->processedConfiguration, $this->logger) = \unserialize($serialized);
93
    }
94
}
95