Completed
Push — master ( 66f480...24a417 )
by Tomasz
02:30 queued 17s
created

AbstractFormat   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 0
cbo 1
dl 0
loc 27
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B doSerialize() 0 24 5
1
<?php
2
namespace Thunder\Serializard\Format;
3
4
use Thunder\Serializard\HandlerContainer\HandlerContainerInterface as Handlers;
5
6
/**
7
 * @author Tomasz Kowalczyk <[email protected]>
8
 */
9
abstract class AbstractFormat implements FormatInterface
10
{
11
    protected function doSerialize($var, Handlers $handlers)
12
    {
13
        if(is_object($var)) {
14
            $class = get_class($var);
15
            $handler = $handlers->getHandler($class);
16
17
            if(null === $handler) {
18
                throw new \RuntimeException(sprintf('No serialization handler for class %s!', $class));
19
            }
20
21
            return $this->doSerialize(call_user_func_array($handler, array($var)), $handlers);
22
        }
23
24
        if(is_array($var)) {
25
            $return = array();
26
            foreach($var as $key => $value) {
27
                $return[$key] = $this->doSerialize($value, $handlers);
28
            }
29
30
            return $return;
31
        }
32
33
        return $var;
34
    }
35
}
36