Failed Conditions
Pull Request — 2.8.x (#7919)
by
unknown
07:31
created

EntityCacheEntry   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 36.36%

Importance

Changes 0
Metric Value
wmc 4
eloc 11
c 0
b 0
f 0
dl 0
loc 56
ccs 4
cts 11
cp 0.3636
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __set_state() 0 3 1
A resolveAssociationEntries() 0 9 2
1
<?php
2
3
/*
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the MIT license. For more information, see
18
 * <http://www.doctrine-project.org>.
19
 */
20
21
namespace Doctrine\ORM\Cache;
22
23
use Doctrine\ORM\EntityManagerInterface;
24
25
/**
26
 * Entity cache entry
27
 *
28
 * @since   2.5
29
 * @author  Fabio B. Silva <[email protected]>
30
 */
31
class EntityCacheEntry implements CacheEntry
32
{
33
    /**
34
     * READ-ONLY: Public only for performance reasons, it should be considered immutable.
35
     *
36
     * @var array The entity map data
37
     */
38
    public $data;
39
40
    /**
41
     * READ-ONLY: Public only for performance reasons, it should be considered immutable.
42
     *
43
     * @var string The entity class name
44
     */
45
    public $class;
46
47
    /**
48
     * @param string $class The entity class.
49
     * @param array  $data  The entity data.
50
     */
51 16
    public function __construct($class, array $data)
52
    {
53 16
        $this->class = $class;
54 16
        $this->data  = $data;
55 16
    }
56
57
    /**
58
     * Creates a new EntityCacheEntry
59
     *
60
     * This method allow Doctrine\Common\Cache\PhpFileCache compatibility
61
     *
62
     * @param array $values array containing property values
63
     *
64
     * @return EntityCacheEntry
65
     */
66
    public static function __set_state(array $values)
67
    {
68
        return new self($values['class'], $values['data']);
69
    }
70
71
    /**
72
     * Retrieves the entity data resolving cache entries
73
     *
74
     * @param \Doctrine\ORM\EntityManagerInterface $em
75
     *
76
     * @return array
77
     */
78
    public function resolveAssociationEntries(EntityManagerInterface $em)
79
    {
80
        return array_map(function($value) use ($em) {
81
            if ( ! ($value instanceof AssociationCacheEntry)) {
82
                return $value;
83
            }
84
85
            return $em->getReference($value->class, $value->identifier);
86
        }, $this->data);
87
    }
88
}
89