Completed
Push — master ( 4dd8bf...5dcaed )
by Filipe
07:48
created

CollectionsMap::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
/**
4
 * This file is part of slick/orm package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Orm\Entity;
11
12
use Slick\Cache\Cache;
13
use Slick\Cache\CacheStorageInterface;
14
15
/**
16
 * Collections Map store
17
 *
18
 * @package Slick\Orm\Entity
19
 * @author  Filipe Silva <[email protected]>
20
 */
21
class CollectionsMap implements CollectionsMapInterface
22
{
23
24
    /**
25
     * @var CacheStorageInterface
26
     */
27
    protected $cache;
28
29
    /**
30
     * Set an entity
31
     *
32
     * @param string $collectionId
33
     * @param EntityCollection $collection
34
     *
35
     * @return self|$this|CollectionsMapInterface
36
     */
37 2
    public function set($collectionId, EntityCollection $collection)
38
    {
39 2
        $this->getCache()->set($collectionId, $collection);
40 2
        return $this;
41
    }
42
43
    /**
44
     * Gets the entity with provided id
45
     *
46
     * @param string $collectionId
47
     *
48
     * @param null $default
49
     *
50
     * @return EntityCollection
51
     */
52 2
    public function get($collectionId, $default = null)
53
    {
54 2
        return $this->getCache()->get($collectionId, $default);
55
    }
56
57
    /**
58
     * Set cache storage for this identity map
59
     *
60
     * @param CacheStorageInterface $cache
61
     *
62
     * @return $this|self|CollectionsMap
63
     */
64 6
    public function setCache(CacheStorageInterface $cache)
65
    {
66 6
        $this->cache = $cache;
67 6
        return $this;
68
    }
69
70
    /**
71
     * Gets cache storage for this identity map
72
     *
73
     * @return CacheStorageInterface
74
     */
75 6
    public function getCache()
76
    {
77 6
        if (null == $this->cache) {
78 2
            $this->setCache(Cache::get(Cache::CACHE_MEMORY));
79 2
        }
80 6
        return $this->cache;
81
    }
82
}