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

ExtensibleClassMetadata   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 5
c 5
b 0
f 0
lcom 1
cbo 1
dl 0
loc 68
ccs 18
cts 18
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addExtension() 0 4 1
A getExtension() 0 8 2
A appendExtension() 0 9 1
A mergeExtension() 0 7 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