JsonSerializer::unserialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 10
ccs 0
cts 10
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Ubiquity\contents\serializers;
4
5
/**
6
 * Ubiquity\contents\serializers$JsonSerializer
7
 * This class is part of Ubiquity
8
 *
9
 * @author jc
10
 * @version 1.0.0
11
 *
12
 */
13
class JsonSerializer implements SerializerInterface {
14
15
	public function serialize($object) {
16
		return \json_encode ( [ 'class' => \get_class ( $object ),'o' => $object ] );
17
	}
18
19
	public function unserialize($serial) {
20
		$datas = \json_decode ( $serial );
21
		$class = $datas->class;
22
		$stdObj = $datas->o;
23
		$count = \strlen ( $class );
24
		$temp = \serialize ( $stdObj );
25
		$temp = \preg_replace ( "@^O:8:\"stdClass\":@", "O:$count:\"$class\":", $temp );
26
		$o = \unserialize ( $temp );
27
		$o->_rest = ( array ) ($o->_rest);
28
		return $o;
29
	}
30
}
31
32