Completed
Push — 2.x ( dc834d...91b37b )
by
unknown
02:07
created

DoctrineCollector   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 203
Duplicated Lines 0 %

Coupling/Cohesion

Components 6
Dependencies 0

Importance

Changes 10
Bugs 4 Features 4
Metric Value
wmc 25
c 10
b 4
f 4
lcom 6
cbo 0
dl 0
loc 203
rs 9.0909

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getInstance() 0 8 2
A addDiscriminator() 0 10 3
A addDiscriminatorColumn() 0 6 2
A addInheritanceType() 0 6 2
A addAssociation() 0 12 3
A addIndex() 0 12 3
A addUnique() 0 12 3
A getAssociations() 0 4 1
A getDiscriminators() 0 4 1
A getDiscriminatorColumns() 0 4 1
A getInheritanceTypes() 0 4 1
A getIndexes() 0 4 1
A getUniques() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\EasyExtendsBundle\Mapper;
13
14
class DoctrineCollector
15
{
16
    /**
17
     * @var array
18
     */
19
    protected $associations;
20
21
    /**
22
     * @var array
23
     */
24
    protected $indexes;
25
26
    /**
27
     * @var array
28
     */
29
    protected $uniques;
30
31
    /**
32
     * @var array
33
     */
34
    protected $discriminators;
35
36
    /**
37
     * @var array
38
     */
39
    protected $discriminatorColumns;
40
41
    /**
42
     * @var array
43
     */
44
    protected $inheritanceTypes;
45
46
    /**
47
     * @var DoctrineCollector
48
     */
49
    private static $instance;
50
51
    public function __construct()
52
    {
53
        $this->associations = array();
54
        $this->indexes = array();
55
        $this->uniques = array();
56
        $this->discriminatorColumns = array();
57
        $this->inheritanceTypes = array();
58
        $this->discriminators = array();
59
    }
60
61
    /**
62
     * @return DoctrineCollector
63
     */
64
    public static function getInstance()
65
    {
66
        if (!self::$instance) {
67
            self::$instance = new self();
68
        }
69
70
        return self::$instance;
71
    }
72
73
    /**
74
     * Add a discriminator to a class.
75
     *
76
     * @param string $class              The Class
77
     * @param string $key                Key is the database value and values are the classes
78
     * @param string $discriminatorClass The mapped class
79
     */
80
    public function addDiscriminator($class, $key, $discriminatorClass)
81
    {
82
        if (!isset($this->discriminators[$class])) {
83
            $this->discriminators[$class] = array();
84
        }
85
86
        if (!isset($this->discriminators[$class][$key])) {
87
            $this->discriminators[$class][$key] = $discriminatorClass;
88
        }
89
    }
90
91
    /**
92
     * Add the Discriminator Column.
93
     *
94
     * @param string $class
95
     * @param array  $columnDef
96
     */
97
    public function addDiscriminatorColumn($class, array $columnDef)
98
    {
99
        if (!isset($this->discriminatorColumns[$class])) {
100
            $this->discriminatorColumns[$class] = $columnDef;
101
        }
102
    }
103
104
    /**
105
     * @param string $class
106
     * @param string $type
107
     */
108
    public function addInheritanceType($class, $type)
109
    {
110
        if (!isset($this->inheritanceTypes[$class])) {
111
            $this->inheritanceTypes[$class] = $type;
112
        }
113
    }
114
115
    /**
116
     * @param string $class
117
     * @param string $type
118
     * @param array  $options
119
     */
120
    public function addAssociation($class, $type, array $options)
121
    {
122
        if (!isset($this->associations[$class])) {
123
            $this->associations[$class] = array();
124
        }
125
126
        if (!isset($this->associations[$class][$type])) {
127
            $this->associations[$class][$type] = array();
128
        }
129
130
        $this->associations[$class][$type][] = $options;
131
    }
132
133
    /**
134
     * @param string $class
135
     * @param string $name
136
     * @param array  $columns
137
     */
138
    public function addIndex($class, $name, array $columns)
139
    {
140
        if (!isset($this->indexes[$class])) {
141
            $this->indexes[$class] = array();
142
        }
143
144
        if (isset($this->indexes[$class][$name])) {
145
            return;
146
        }
147
148
        $this->indexes[$class][$name] = $columns;
149
    }
150
151
    /**
152
     * @param string $class
153
     * @param string $name
154
     * @param array  $columns
155
     */
156
    public function addUnique($class, $name, array $columns)
157
    {
158
        if (!isset($this->indexes[$class])) {
159
            $this->uniques[$class] = array();
160
        }
161
162
        if (isset($this->uniques[$class][$name])) {
163
            return;
164
        }
165
166
        $this->uniques[$class][$name] = $columns;
167
    }
168
169
    /**
170
     * @return array
171
     */
172
    public function getAssociations()
173
    {
174
        return $this->associations;
175
    }
176
177
    /**
178
     * @return array
179
     */
180
    public function getDiscriminators()
181
    {
182
        return $this->discriminators;
183
    }
184
185
    /**
186
     * @return array
187
     */
188
    public function getDiscriminatorColumns()
189
    {
190
        return $this->discriminatorColumns;
191
    }
192
193
    /**
194
     * @return array
195
     */
196
    public function getInheritanceTypes()
197
    {
198
        return $this->inheritanceTypes;
199
    }
200
201
    /**
202
     * @return array
203
     */
204
    public function getIndexes()
205
    {
206
        return $this->indexes;
207
    }
208
209
    /**
210
     * @return array
211
     */
212
    public function getUniques()
213
    {
214
        return $this->uniques;
215
    }
216
}
217