Completed
Push — 1.1 ( d166b0...e7f438 )
by Patrick
11:31 queued 07:46
created

ExtensibleClassMetadata::mergeExtension()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 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
     * @return void
23
     */
24
    public function addExtension($name, array $config)
25
    {
26
        $this->extensions[$name] = $config;
27
    }
28
29
    /**
30
     * @param string $name
31
     *
32
     * @return array
33
     */
34
    public function getExtension($name)
35
    {
36
        if (isset($this->extensions[$name])) {
37
            return $this->extensions[$name];
38
        }
39
40
        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
    public function appendExtension($name, array $config = [])
50
    {
51
        $merged = array_merge_recursive(
52
            $this->getExtension($name),
53
            $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