Completed
Push — extensions-support ( cafd05...735378 )
by Guido
05:02
created

ExtensibleClassMetadata::addExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
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
     * @return void
23
     */
24 197
    public function addExtension($name, array $config)
25
    {
26 197
        $this->extensions[$name] = $config;
27 197
    }
28
29
    /**
30
     * @param string $name
31
     *
32
     * @return array
33
     */
34 198
    public function getExtension($name)
35
    {
36 198
        if (isset($this->extensions[$name])) {
37 195
            return $this->extensions[$name];
38
        }
39
40 169
        return [];
41
    }
42
43
    /**
44
     * Merge with current extension configuration, appending new values to old ones.
45
     *
46
     * @param string $name
47
     * @param array  $config
48
     */
49 108
    public function appendExtension($name, array $config = [])
50
    {
51 108
        $merged = array_merge_recursive(
52 108
            $this->getExtension($name),
53
            $config
54 108
        );
55
56 108
        $this->addExtension($name, $merged);
57 108
    }
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 53
    public function mergeExtension($name, array $config)
68
    {
69 53
        $this->addExtension($name, array_merge(
70 53
            $this->getExtension($name),
71
            $config
72 53
        ));
73 53
    }
74
}
75