Completed
Push — master ( 7b6a9e...621ea2 )
by Nick
15:23
created

EntityTrait::json()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
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
trait EntityTrait
10
{
11
    /**
12
   * @param string $key
13
   * @param string $default
14
   *
15
   * @return mixed
16
   */
17
  private 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