GenericEntity::offsetGet()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 15
rs 10
1
<?php
2
/**
3
 *
4
 * This file is part of the Aura project for PHP.
5
 *
6
 * @package Aura.Marshal
7
 *
8
 * @license https://opensource.org/licenses/mit-license.php MIT
9
 *
10
 */
11
namespace Aura\Marshal\Entity;
12
13
use Aura\Marshal\Data;
14
use Aura\Marshal\Lazy\LazyInterface;
15
use Aura\Marshal\ToArrayInterface;
16
use Aura\Marshal\ToArrayTrait;
17
18
/**
19
 *
20
 * Represents a single entity.
21
 *
22
 * @package Aura.Marshal
23
 *
24
 */
25
#[\AllowDynamicProperties]
26
class GenericEntity extends Data implements ToArrayInterface
27
{
28
    use MagicArrayAccessTrait;
29
    use ToArrayTrait;
30
31
    /**
32
     *
33
     * ArrayAccess: get a field value.
34
     *
35
     * @param string $field The requested field.
36
     *
37
     * @return mixed
38
     *
39
     */
40
    public function offsetGet($field)
41
    {
42
        // get the field value
43
        $value = $this->data[$field];
44
45
        // is it a Lazy placeholder?
46
        if ($value instanceof LazyInterface) {
47
            // replace the Lazy placeholder with the real object
48
            $value = $value->get($this);
49
            // retain the real object
50
            $this->offsetSet($field, $value);
51
        }
52
53
        // done!
54
        return $value;
55
    }
56
}
57