Entity::json()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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|bool $default
14
     *
15
     * @return mixed
16
     */
17 201
    protected function getEntityValue($key, $default)
18
    {
19 201
        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 168
    public function json()
28
    {
29 168
        $encoders = [new JsonEncoder()];
30 168
        $normalizers = [new CustomNormalizer()];
31 168
        $serializer = new Serializer($normalizers, $encoders);
32
33 168
        return $serializer->serialize($this, 'json');
34
    }
35
}
36