DateTimeZoneSerializer::unserialize()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4286
cc 3
eloc 6
nc 3
nop 3
1
<?php
2
3
/**
4
 * Author: Nil Portugués Calderó <[email protected]>
5
 * Date: 7/3/15
6
 * Time: 6:00 PM.
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\Serializer\Serializer\InternalClasses;
12
13
use DateTimeZone;
14
use NilPortugues\Serializer\Serializer;
15
use ReflectionClass;
16
17
class DateTimeZoneSerializer
18
{
19
    /**
20
     * @param Serializer   $serializer
21
     * @param DateTimeZone $dateTimeZone
22
     *
23
     * @return mixed
24
     */
25
    public static function serialize(Serializer $serializer, DateTimeZone $dateTimeZone)
0 ignored issues
show
Unused Code introduced by
The parameter $serializer is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
    {
27
        return array(
28
            Serializer::CLASS_IDENTIFIER_KEY => 'DateTimeZone',
29
            'timezone' => array(
30
                Serializer::SCALAR_TYPE => 'string',
31
                Serializer::SCALAR_VALUE => $dateTimeZone->getName(),
32
            ),
33
        );
34
    }
35
36
    /**
37
     * @param Serializer $serializer
38
     * @param string     $className
39
     * @param array      $value
40
     *
41
     * @return object
42
     */
43
    public static function unserialize(Serializer $serializer, $className, array $value)
44
    {
45
        $ref = new ReflectionClass($className);
46
47
        foreach ($value as &$v) {
48
            if (\is_array($v)) {
49
                $v = $serializer->unserialize($v);
50
            }
51
        }
52
53
        return $ref->newInstanceArgs($value);
54
    }
55
}
56