Completed
Pull Request — master (#6)
by Nick
03:09
created

Entity::getEntityValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 2
1
<?php
2
3
namespace Acquia\LiftClient\Entity;
4
5
use Symfony\Component\Serializer\Encoder\JsonEncoder;
6
use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
7
use Symfony\Component\Serializer\Serializer;
8
9
class Entity extends \ArrayObject
10
{
11
    /**
12
     * @param string                 $key
13
     * @param string|int|float|array $default
14
     *
15
     * @return mixed
16
     */
17
    protected function getEntityValue($key, $default)
18
    {
19
        return isset($this[$key]) ? $this[$key] : $default;
20
    }
21
22
    /**
23
     * Returns the json representation of the current object.
24
     *
25
     * @return string
26
     */
27
    public function json()
28
    {
29
        $encoders = array(new JsonEncoder());
30
        $normalizers = array(new CustomNormalizer());
31
        $serializer = new Serializer($normalizers, $encoders);
32
33
        return $serializer->serialize($this, 'json');
34
    }
35
}
36