Passed
Push — master ( c39fb6...9e9a0d )
by Rafael
04:42
created

setReferenceByObjectId()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 3
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/*******************************************************************************
3
 *  This file is part of the GraphQL Bundle package.
4
 *
5
 *  (c) YnloUltratech <[email protected]>
6
 *
7
 *  For the full copyright and license information, please view the LICENSE
8
 *  file that was distributed with this source code.
9
 ******************************************************************************/
10
11
namespace Ynlo\GraphQLBundle\Test\FixtureLoader\Cache;
12
13
use Doctrine\Common\DataFixtures\ReferenceRepository;
14
15
/**
16
 * CachedReferenceRepository
17
 */
18
class CachedReferenceRepository extends ReferenceRepository
19
{
20
    private static $oids = [];
21
22
    private static $references = [];
23
24
    private static $identities = [];
25
26
    /**
27
     * @param string $oid
28
     * @param string $reference
29
     */
30 21
    public function setReferenceByObjectId($oid, $reference)
31
    {
32 21
        foreach (self::$oids as $name => $originalId) {
33 21
            if ($oid === $originalId) {
34 21
                self::$references[$name] = $reference;
35
            }
36
        }
37 21
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42 1
    public function setReference($name, $reference)
43
    {
44 1
        if (!isset(self::$references[$name])) {
45 1
            parent::setReference($name, $reference);
46 1
            self::$references[$name] = $reference;
47 1
            self::$oids[$name] = spl_object_hash($reference);
48
        }
49 1
    }
50
51
    /**
52
     *{@inheritDoc}
53
     */
54
    public function setReferenceIdentity($name, $identity)
55
    {
56
        if (!isset(self::$identities[$name])) {
57
            parent::setReferenceIdentity($name, $identity);
58
            self::$identities[$name] = $identity;
59
        }
60
    }
61
62
    /**
63
     *{@inheritDoc}
64
     */
65
    public function addReference($name, $object)
66
    {
67
        if (!isset(self::$references[$name])) {
68
            parent::addReference($name, $object);
69
            self::$references[$name] = $object;
70
        }
71
    }
72
73
    /**
74
     *{@inheritDoc}
75
     */
76 11
    public function getReference($name)
77
    {
78 11
        if (!isset(self::$references[$name])) {
79
            self::$references[$name] = parent::getReference($name);
80
        }
81
82 11
        return self::$references[$name];
83
    }
84
85
    /**
86
     *{@inheritDoc}
87
     */
88
    public function getReferences()
89
    {
90
        return self::$references;
91
    }
92
}
93