Completed
Push — extensions-support ( 5f703b...dc3ff8 )
by Guido
04:50
created

ExtensibleClassMetadata::getExtension()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 8
ccs 3
cts 3
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace LaravelDoctrine\Fluent\Extensions;
4
5
use Doctrine\ORM\Mapping\ClassMetadata;
6
7
class ExtensibleClassMetadata extends ClassMetadata
8
{
9
    /**
10
     * A dictionary of extension metadata mapped to this class.
11
     *
12
     * @var array
13
     */
14
    public $extensions = [];
15
16
    /**
17
     * Adds the extension configuration.
18
     *
19
     * @param string $name
20
     * @param array  $config
21
     *
22 177
     * @return void
23
     */
24 177
    public function addExtension($name, array $config)
25 177
    {
26
        $this->extensions[$name] = $config;
27
    }
28
29
    /**
30
     * @param string $name
31
     *
32 178
     * @return array
33
     */
34 178
    public function getExtension($name)
35 176
    {
36
        if (isset($this->extensions[$name])) {
37
            return $this->extensions[$name];
38 151
        }
39
40
        return [];
41
    }
42
43
    /**
44
     * Merge with current extension configuration, appending new values to old ones.
45 141
     *
46
     * @param string $name
47 141
     * @param array  $config
48 141
     */
49
    public function appendExtension($name, array $config = [])
50 141
    {
51
        $merged = array_merge_recursive(
52 141
            $this->getExtension($name),
53 141
            $config
54
        );
55
56
        $this->addExtension($name, $merged);
57
    }
58
59
    /**
60
     * Merge with current extension configuration, overwriting with new values.
61
     *
62
     * @param string $name
63
     * @param array  $config
64
     *
65
     * @return void
66
     */
67
    public function mergeExtension($name, array $config)
68
    {
69
        $this->addExtension($name, array_merge(
70
            $this->getExtension($name),
71
            $config
72
        ));
73
    }
74
}
75