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

EntityTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getEntityValue() 0 4 2
A json() 0 8 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
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