Completed
Push — master ( 52b242...112fdc )
by Thomas
17s queued 11s
created

SubstituteOriginalDrupalKernelConfiguration   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 20
c 1
b 0
f 1
dl 0
loc 75
ccs 24
cts 24
cp 1
rs 10
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 5 1
A unserialize() 0 3 1
A __construct() 0 5 1
A isEnabled() 0 3 1
A getCacheDirectoryPath() 0 7 2
A getClassLoader() 0 16 4
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 Composer\Autoload\ClassLoader;
17
18
class SubstituteOriginalDrupalKernelConfiguration extends AbstractConfiguration
19
{
20
    /**
21
     * @var ClassLoader|null
22
     */
23
    private $classLoader;
24
25
    /**
26
     * @param array $processedConfiguration
27
     */
28 28
    public function __construct(array $processedConfiguration)
29
    {
30 28
        parent::__construct($processedConfiguration);
31
32 28
        $this->classLoader = null;
33 28
    }
34
35
    /**
36
     * @return bool
37
     */
38 7
    public function isEnabled(): bool
39
    {
40 7
        return $this->processedConfiguration['enabled'];
41
    }
42
43
    /**
44
     * @return ClassLoader
45
     */
46 3
    public function getClassLoader(): ClassLoader
47
    {
48 3
        if (!$this->classLoader instanceof ClassLoader) {
49 3
            if (!$this->isEnabled()) {
50 1
                throw new \LogicException('The class loader getter should not be called if the original DrupalKernel substitution is disabled.');
51
            }
52
53 2
            $classLoader = require $this->processedConfiguration['composer_autoload_file_path'];
54 2
            if (!$classLoader instanceof ClassLoader) {
55 1
                throw new \RuntimeException(\sprintf('The composer autoload.php file did not return a "%s" instance.', ClassLoader::class));
56
            }
57
58 1
            $this->classLoader = $classLoader;
59
        }
60
61 1
        return $this->classLoader;
62
    }
63
64
    /**
65
     * @return string
66
     */
67 2
    public function getCacheDirectoryPath(): string
68
    {
69 2
        if (!$this->isEnabled()) {
70 1
            throw new \LogicException('The cache directory getter should not be called if the original DrupalKernel substitution is disabled.');
71
        }
72
73 1
        return $this->processedConfiguration['cache_directory_path'];
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79 20
    public function serialize(): ?string
80
    {
81 20
        return \serialize(array(
82 20
            $this->processedConfiguration,
83
            null,
84
        ));
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90 17
    public function unserialize($serialized): void
91
    {
92 17
        list($this->processedConfiguration, $this->classLoader) = \unserialize($serialized);
93 17
    }
94
}
95