@@ -10,20 +10,20 @@ |
||
10 | 10 | { |
11 | 11 | protected function doSerialize($var, Handlers $handlers) |
12 | 12 | { |
13 | - if(is_object($var)) { |
|
13 | + if (is_object($var)) { |
|
14 | 14 | $class = get_class($var); |
15 | 15 | $handler = $handlers->getHandler($class); |
16 | 16 | |
17 | - if(null === $handler) { |
|
17 | + if (null === $handler) { |
|
18 | 18 | throw new \RuntimeException(sprintf('No serialization handler for class %s!', $class)); |
19 | 19 | } |
20 | 20 | |
21 | 21 | return $this->doSerialize(call_user_func_array($handler, array($var)), $handlers); |
22 | 22 | } |
23 | 23 | |
24 | - if(is_array($var)) { |
|
24 | + if (is_array($var)) { |
|
25 | 25 | $return = array(); |
26 | - foreach($var as $key => $value) { |
|
26 | + foreach ($var as $key => $value) { |
|
27 | 27 | $return[$key] = $this->doSerialize($value, $handlers); |
28 | 28 | } |
29 | 29 |
@@ -36,7 +36,7 @@ |
||
36 | 36 | { |
37 | 37 | $format = $this->formats->get($alias); |
38 | 38 | |
39 | - if(false === $format instanceof FormatInterface) { |
|
39 | + if (false === $format instanceof FormatInterface) { |
|
40 | 40 | throw new \RuntimeException(sprintf('No registered format for alias %s!', $alias)); |
41 | 41 | } |
42 | 42 |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | $doc->formatOutput = true; |
21 | 21 | $parent = $parent ?: $doc; |
22 | 22 | |
23 | - switch(true) { |
|
23 | + switch (true) { |
|
24 | 24 | case is_object($var): { |
25 | 25 | $handler = $handlers->getHandler(get_class($var)); |
26 | 26 | $arr = $handler($var); |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | } |
30 | 30 | case is_array($var): { |
31 | 31 | $item = $key ? $doc->createElement($key) : $parent; |
32 | - foreach($var as $index => $value) { |
|
32 | + foreach ($var as $index => $value) { |
|
33 | 33 | $this->doSerialize($value, $handlers, $doc, $item, $index); |
34 | 34 | } |
35 | 35 | !$key ?: $parent->appendChild($item); |
@@ -59,22 +59,22 @@ discard block |
||
59 | 59 | /** @var \DOMElement $parent */ |
60 | 60 | /** @var \DOMElement $node */ |
61 | 61 | $tags = array(); |
62 | - foreach($parent->childNodes as $node) { |
|
63 | - if($node->nodeName === '#text') { |
|
62 | + foreach ($parent->childNodes as $node) { |
|
63 | + if ($node->nodeName === '#text') { |
|
64 | 64 | continue; |
65 | 65 | } |
66 | - if($node->childNodes->length === 1 && $node->childNodes->item(0) instanceof \DOMText) { |
|
66 | + if ($node->childNodes->length === 1 && $node->childNodes->item(0) instanceof \DOMText) { |
|
67 | 67 | $ret[$node->tagName] = $node->childNodes->item(0)->nodeValue; |
68 | 68 | continue; |
69 | 69 | } |
70 | 70 | $result = $this->parse($doc, $node); |
71 | - if(array_key_exists($node->tagName, $ret)) { |
|
71 | + if (array_key_exists($node->tagName, $ret)) { |
|
72 | 72 | $tags[] = $node->tagName; |
73 | 73 | $ret = array($ret[$node->tagName]); |
74 | 74 | $ret[] = $result; |
75 | 75 | continue; |
76 | 76 | } |
77 | - if(in_array($node->tagName, $tags)) { |
|
77 | + if (in_array($node->tagName, $tags)) { |
|
78 | 78 | $ret[] = $result; |
79 | 79 | continue; |
80 | 80 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | public function add($class, $root, $handler) |
13 | 13 | { |
14 | - if(false === is_callable($handler)) { |
|
14 | + if (false === is_callable($handler)) { |
|
15 | 15 | throw new \RuntimeException(sprintf('Invalid handler for class %s!', $class)); |
16 | 16 | } |
17 | 17 | |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | { |
24 | 24 | $handler = $this->getHandler($class); |
25 | 25 | |
26 | - if(null === $handler) { |
|
26 | + if (null === $handler) { |
|
27 | 27 | throw new \RuntimeException(sprintf('Handler for class %s does not exist!', $class)); |
28 | 28 | } |
29 | 29 |
@@ -19,32 +19,32 @@ discard block |
||
19 | 19 | public function __invoke($var) |
20 | 20 | { |
21 | 21 | $data = file_get_contents($this->path); |
22 | - if(!$data) { |
|
22 | + if (!$data) { |
|
23 | 23 | throw new \RuntimeException(sprintf('Failed to read file at path %s!', $this->path)); |
24 | 24 | } |
25 | 25 | |
26 | 26 | $yaml = Yaml::parse($data); |
27 | 27 | $keys = array_keys($yaml); |
28 | 28 | $yaml = $yaml[$keys[0]]; |
29 | - if(!$yaml) { |
|
30 | - throw new \InvalidArgumentException('No config at '.$this->path); |
|
29 | + if (!$yaml) { |
|
30 | + throw new \InvalidArgumentException('No config at ' . $this->path); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | $hasPolicy = array_key_exists('exclusion_policy', $yaml); |
34 | - if(!$hasPolicy || ($hasPolicy && 'ALL' !== $yaml['exclusion_policy'])) { |
|
34 | + if (!$hasPolicy || ($hasPolicy && 'ALL' !== $yaml['exclusion_policy'])) { |
|
35 | 35 | throw new \RuntimeException(sprintf('This serializer supports only ALL, %s given!', $yaml['exclusion_policy'])); |
36 | 36 | } |
37 | 37 | |
38 | 38 | $ref = new \ReflectionObject($var); |
39 | 39 | $result = []; |
40 | - foreach($yaml['properties'] as $key => $config) { |
|
41 | - if($config['expose'] !== true) { |
|
40 | + foreach ($yaml['properties'] as $key => $config) { |
|
41 | + if ($config['expose'] !== true) { |
|
42 | 42 | continue; |
43 | 43 | } |
44 | 44 | |
45 | 45 | $name = array_key_exists('serialized_name', $config) ? $config['serialized_name'] : $key; |
46 | 46 | |
47 | - if($ref->hasProperty($key)) { |
|
47 | + if ($ref->hasProperty($key)) { |
|
48 | 48 | $prop = $ref->getProperty($key); |
49 | 49 | $prop->setAccessible(true); |
50 | 50 | |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | continue; |
54 | 54 | } |
55 | 55 | |
56 | - $method = 'get'.ucfirst($key); |
|
57 | - if(method_exists($var, $method)) { |
|
56 | + $method = 'get' . ucfirst($key); |
|
57 | + if (method_exists($var, $method)) { |
|
58 | 58 | $result[$name] = call_user_func_array([$var, $method], []); |
59 | 59 | |
60 | 60 | continue; |
@@ -18,8 +18,8 @@ |
||
18 | 18 | $ref = new \ReflectionObject($var); |
19 | 19 | |
20 | 20 | $result = []; |
21 | - foreach($ref->getProperties() as $property) { |
|
22 | - if(in_array($property->getName(), $this->skipped)) { |
|
21 | + foreach ($ref->getProperties() as $property) { |
|
22 | + if (in_array($property->getName(), $this->skipped)) { |
|
23 | 23 | continue; |
24 | 24 | } |
25 | 25 |