Completed
Push — develop ( 43816c...8775b9 )
by Narcotic
10s
created

JsonSerializer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 1
cbo 1
dl 0
loc 27
ccs 12
cts 12
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A unserializeObject() 0 17 4
1
<?php
2
/**
3
 * a small extension to the Zumba\Util\JsonSerializer to allow deserializing mongodb legacy driver objects
4
 *
5
 * NOTE: this is only needed as we widely use the "mongodb legacy" driver (pecl/mongo) instead of the newer one
6
 * (pecl/mongodb) - if we once switch to the new driver, we should be able to ditch this.
7
 */
8
9
namespace Graviton\ImportExport\Util;
10
11
use Zumba\Util\JsonSerializer as BaseSerializer;
12
13
/**
14
 * @author   List of contributors <https://github.com/libgraviton/import-export/graphs/contributors>
15
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
16
 * @link     http://swisscom.ch
17
 */
18
class JsonSerializer extends BaseSerializer
19
{
20
    /**
21
     * Convert the serialized array into an object
22
     *
23
     * @param aray $value
24
     * @return object
25
     * @throws Zumba\Exception\JsonSerializerException
26
     */
27 2
    protected function unserializeObject($value) {
28 2
        $className = $value[static::CLASS_IDENTIFIER_KEY];
29
30 2
        $obj = false;
31 2
        if ($className == 'MongoDate') {
32 2
            $obj = new \MongoDate($value['sec'], $value['usec']);
33 2
        } elseif ($className == 'MongoId') {
34 1
            $obj = new \MongoId($value['$id']);
35 1
        }
36
37 2
        if ($obj !== false) {
38 2
            $this->objectMapping[$this->objectMappingIndex++] = $obj;
39 2
            return $obj;
40
        }
41
42 1
        return parent::unserializeObject($value);
43
    }
44
}
45