JsonSerializer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 8
Bugs 0 Features 0
Metric Value
wmc 3
c 8
b 0
f 0
lcom 0
cbo 2
dl 0
loc 29
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A serializeObject() 0 10 2
1
<?php
2
3
/**
4
 * Author: Nil Portugués Calderó <[email protected]>
5
 * Date: 8/16/15
6
 * Time: 4:43 AM.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace NilPortugues\Laravel5\JsonSerializer;
12
13
use ErrorException;
14
use Illuminate\Database\Eloquent\Model;
15
use NilPortugues\Api\Json\JsonTransformer;
16
use NilPortugues\Serializer\DeepCopySerializer;
17
use NilPortugues\Serializer\Drivers\Eloquent\EloquentDriver;
18
use ReflectionClass;
19
use ReflectionMethod;
20
21
/**
22
 * Class JsonSerializer.
23
 */
24
class JsonSerializer extends DeepCopySerializer
25
{
26
    /**
27
     * @param \NilPortugues\Api\Json\JsonTransformer $jsonTransformer
28
     */
29
    public function __construct(JsonTransformer $jsonTransformer)
30
    {
31
        parent::__construct($jsonTransformer);
32
    }
33
34
35
    /**
36
     * Extract the data from an object.
37
     *
38
     * @param mixed $value
39
     *
40
     * @return array
41
     */
42
    protected function serializeObject($value)
43
    {
44
45
        $serialized = EloquentDriver::serialize($value);
46
        if ($value !== $serialized) {
47
            return $serialized;
48
        }
49
50
        return parent::serializeObject($value);
51
    }
52
}
53