Configuration::getCache()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Flying\Struct;
4
5
use Doctrine\Common\Cache\ArrayCache;
6
use Doctrine\Common\Cache\Cache;
7
use Flying\Struct\Configuration\NamespacesMap;
8
use Flying\Struct\Metadata\AnnotationParser;
9
use Flying\Struct\Metadata\MetadataManager;
10
use Flying\Struct\Metadata\MetadataManagerInterface;
11
use Flying\Struct\Metadata\MetadataParserInterface;
12
use Flying\Struct\Storage\ArrayBackend;
13
use Flying\Struct\Storage\BackendInterface;
14
use Flying\Struct\Storage\Storage;
15
use Flying\Struct\Storage\StorageInterface;
16
17
/**
18
 * Structures configuration
19
 */
20
class Configuration
21
{
22
    /**
23
     * Cache for structures information
24
     *
25
     * @var Cache
26
     */
27
    private $cache;
28
    /**
29
     * Namespaces map for structure classes
30
     *
31
     * @var NamespacesMap
32
     */
33
    private $structNsMap;
34
    /**
35
     * Namespaces map for property classes
36
     *
37
     * @var NamespacesMap
38
     */
39
    private $propertyNsMap;
40
    /**
41
     * Structures metadata manager
42
     *
43
     * @var MetadataManagerInterface
44
     */
45
    private $metadataManager;
46
    /**
47
     * Structures metadata parser
48
     *
49
     * @var MetadataParserInterface
50
     */
51
    private $metadataParser;
52
    /**
53
     * Structures storage manager
54
     *
55
     * @var StorageInterface
56
     */
57
    private $storage;
58
    /**
59
     * Backend for structures storage
60
     *
61
     * @var BackendInterface
62
     */
63
    private $storageBackend;
64
65
    /**
66
     * Get cache for structures information
67
     *
68
     * @return Cache
69
     */
70 184
    public function getCache()
71
    {
72 184
        if (!$this->cache) {
73 184
            $this->cache = new ArrayCache();
74 184
        }
75 184
        return $this->cache;
76
    }
77
78
    /**
79
     * Set cache for structures information
80
     *
81
     * @param Cache $cache
82
     * @return $this
83
     */
84
    public function setCache(Cache $cache)
85
    {
86
        $this->cache = $cache;
87
        return $this;
88
    }
89
90
    /**
91
     * Get namespaces map for structure classes
92
     *
93
     * @return NamespacesMap
94
     * @throws \InvalidArgumentException
95
     */
96 198
    public function getStructNamespacesMap()
97
    {
98 198
        if (!$this->structNsMap) {
99 198
            $this->structNsMap = new NamespacesMap();
100 198
            $this->structNsMap->add('Flying\Struct', 'default');
101 198
        }
102 198
        return $this->structNsMap;
103
    }
104
105
    /**
106
     * Get namespaces map for property classes
107
     *
108
     * @return NamespacesMap
109
     * @throws \InvalidArgumentException
110
     */
111 194
    public function getPropertyNamespacesMap()
112
    {
113 194
        if (!$this->propertyNsMap) {
114 194
            $this->propertyNsMap = new NamespacesMap();
115 194
            $this->propertyNsMap->add('Flying\Struct\Property', 'default');
116 194
        }
117 194
        return $this->propertyNsMap;
118
    }
119
120
    /**
121
     * Get structures metadata manager
122
     *
123
     * @return MetadataManagerInterface
124
     */
125 176
    public function getMetadataManager()
126
    {
127 176
        if (!$this->metadataManager) {
128 175
            $this->metadataManager = new MetadataManager();
129 175
        }
130 176
        return $this->metadataManager;
131
    }
132
133
    /**
134
     * Set structures metadata manager
135
     *
136
     * @param MetadataManagerInterface $manager
137
     * @return $this
138
     */
139 1
    public function setMetadataManager(MetadataManagerInterface $manager)
140
    {
141 1
        $this->metadataManager = $manager;
142 1
        return $this;
143
    }
144
145
    /**
146
     * Get structures metadata parser
147
     *
148
     * @return MetadataParserInterface
149
     */
150 182
    public function getMetadataParser()
151
    {
152 182
        if (!$this->metadataParser) {
153 182
            $this->metadataParser = new AnnotationParser();
154 182
        }
155 182
        return $this->metadataParser;
156
    }
157
158
    /**
159
     * Set structures metadata parser
160
     *
161
     * @param MetadataParserInterface $parser
162
     * @return $this
163
     */
164
    public function setMetadataParser(MetadataParserInterface $parser)
165
    {
166
        $this->metadataParser = $parser;
167
        return $this;
168
    }
169
170
    /**
171
     * Get storage container
172
     *
173
     * @return StorageInterface
174
     */
175 78
    public function getStorage()
176
    {
177 78
        if (!$this->storage) {
178 77
            $this->storage = new Storage();
179 77
        }
180 78
        return $this->storage;
181
    }
182
183
    /**
184
     * Set storage container
185
     *
186
     * @param StorageInterface $storage
187
     * @return $this
188
     */
189 1
    public function setStorage(StorageInterface $storage)
190
    {
191 1
        $this->storage = $storage;
192 1
        return $this;
193
    }
194
195
    /**
196
     * Get backend for structures storage
197
     *
198
     * @return BackendInterface
199
     */
200 81
    public function getStorageBackend()
201
    {
202 81
        if (!$this->storageBackend) {
203 81
            $this->storageBackend = new ArrayBackend();
204 81
        }
205 81
        return $this->storageBackend;
206
    }
207
208
    /**
209
     * Set backend for structures storage
210
     *
211
     * @param BackendInterface $backend
212
     * @return $this
213
     */
214
    public function setStorageBackend(BackendInterface $backend)
215
    {
216
        $this->storageBackend = $backend;
217
        return $this;
218
    }
219
}
220