Completed
Pull Request — master (#14)
by Ivo
01:30
created
src/Jms/Handler/XmlSchemaDateHandler.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -147,6 +147,9 @@
 block discarded – undo
147 147
         return $datetime;
148 148
     }
149 149
 
150
+    /**
151
+     * @param string $interval
152
+     */
150 153
     private function createDateInterval($interval){
151 154
         $f = 0.0;
152 155
         if (preg_match('~\.\d+~',$interval,$match)) {
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -63,100 +63,100 @@
 block discarded – undo
63 63
 
64 64
     public function __construct($defaultTimezone = 'UTC')
65 65
     {
66
-        $this->defaultTimezone = new \DateTimeZone($defaultTimezone);
66
+        $this->defaultTimezone = new \DateTimeZone ($defaultTimezone);
67 67
 
68 68
     }
69 69
 
70
-    public function deserializeDateIntervalXml(XmlDeserializationVisitor $visitor, $data, array $type){
71
-        $attributes = $data->attributes('xsi', true);
70
+    public function deserializeDateIntervalXml(XmlDeserializationVisitor $visitor, $data, array $type) {
71
+        $attributes = $data->attributes ('xsi', true);
72 72
         if (isset($attributes['nil'][0]) && (string) $attributes['nil'][0] === 'true') {
73 73
             return null;
74 74
         }
75
-        return $this->createDateInterval((string)$data);
75
+        return $this->createDateInterval ((string) $data);
76 76
     }
77 77
 
78 78
     public function serializeDate(XmlSerializationVisitor $visitor, \DateTime $date, array $type, Context $context)
79 79
     {
80 80
 
81
-        $v = $date->format('Y-m-d');
81
+        $v = $date->format ('Y-m-d');
82 82
 
83
-        return $visitor->visitSimpleString($v, $type, $context);
83
+        return $visitor->visitSimpleString ($v, $type, $context);
84 84
     }
85 85
 
86 86
     public function deserializeDate(XmlDeserializationVisitor $visitor, $data, array $type)
87 87
     {
88
-        $attributes = $data->attributes('xsi', true);
89
-        if (isset($attributes['nil'][0]) && (string)$attributes['nil'][0] === 'true') {
88
+        $attributes = $data->attributes ('xsi', true);
89
+        if (isset($attributes['nil'][0]) && (string) $attributes['nil'][0] === 'true') {
90 90
             return null;
91 91
         }
92
-        if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})(Z|([+-]\d{2}:\d{2}))?$/', $data)) {
93
-            throw new RuntimeException(sprintf('Invalid date "%s", expected valid XML Schema date string.', $data));
92
+        if (!preg_match ('/^(\d{4})-(\d{2})-(\d{2})(Z|([+-]\d{2}:\d{2}))?$/', $data)) {
93
+            throw new RuntimeException (sprintf ('Invalid date "%s", expected valid XML Schema date string.', $data));
94 94
         }
95 95
 
96
-        return $this->parseDateTime($data, $type);
96
+        return $this->parseDateTime ($data, $type);
97 97
     }
98 98
 
99 99
     public function serializeDateTime(XmlSerializationVisitor $visitor, \DateTime $date, array $type, Context $context)
100 100
     {
101 101
 
102
-        $v = $date->format(\DateTime::W3C);
102
+        $v = $date->format (\DateTime::W3C);
103 103
 
104
-        return $visitor->visitSimpleString($v, $type, $context);
104
+        return $visitor->visitSimpleString ($v, $type, $context);
105 105
     }
106 106
 
107 107
     public function deserializeDateTime(XmlDeserializationVisitor $visitor, $data, array $type)
108 108
     {
109
-        $attributes = $data->attributes('xsi', true);
110
-        if (isset($attributes['nil'][0]) && (string)$attributes['nil'][0] === 'true') {
109
+        $attributes = $data->attributes ('xsi', true);
110
+        if (isset($attributes['nil'][0]) && (string) $attributes['nil'][0] === 'true') {
111 111
             return null;
112 112
         }
113 113
 
114
-        return $this->parseDateTime($data, $type);
114
+        return $this->parseDateTime ($data, $type);
115 115
 
116 116
     }
117 117
 
118 118
     public function serializeTime(XmlSerializationVisitor $visitor, \DateTime $date, array $type, Context $context)
119 119
     {
120
-        $v = $date->format('H:i:s');
121
-        if ($date->getTimezone()->getOffset($date) !== $this->defaultTimezone->getOffset($date)) {
122
-            $v .= $date->format('P');
120
+        $v = $date->format ('H:i:s');
121
+        if ($date->getTimezone ()->getOffset ($date) !== $this->defaultTimezone->getOffset ($date)) {
122
+            $v .= $date->format ('P');
123 123
         }
124
-        return $visitor->visitSimpleString($v, $type, $context);
124
+        return $visitor->visitSimpleString ($v, $type, $context);
125 125
     }
126 126
 
127 127
     public function deserializeTime(XmlDeserializationVisitor $visitor, $data, array $type)
128 128
     {
129
-        $attributes = $data->attributes('xsi', true);
130
-        if (isset($attributes['nil'][0]) && (string)$attributes['nil'][0] === 'true') {
129
+        $attributes = $data->attributes ('xsi', true);
130
+        if (isset($attributes['nil'][0]) && (string) $attributes['nil'][0] === 'true') {
131 131
             return null;
132 132
         }
133 133
 
134
-        $data = (string)$data;
134
+        $data = (string) $data;
135 135
 
136
-        return new \DateTime($data, $this->defaultTimezone);
136
+        return new \DateTime ($data, $this->defaultTimezone);
137 137
     }
138 138
 
139 139
     private function parseDateTime($data, array $type)
140 140
     {
141
-        $timezone = isset($type['params'][1]) ? new \DateTimeZone($type['params'][1]) : $this->defaultTimezone;
142
-        $datetime = new \DateTime((string)$data, $timezone);
141
+        $timezone = isset($type['params'][1]) ? new \DateTimeZone ($type['params'][1]) : $this->defaultTimezone;
142
+        $datetime = new \DateTime ((string) $data, $timezone);
143 143
         if (false === $datetime) {
144
-            throw new RuntimeException(sprintf('Invalid datetime "%s", expected valid XML Schema dateTime string.', $data));
144
+            throw new RuntimeException (sprintf ('Invalid datetime "%s", expected valid XML Schema dateTime string.', $data));
145 145
         }
146 146
 
147 147
         return $datetime;
148 148
     }
149 149
 
150
-    private function createDateInterval($interval){
150
+    private function createDateInterval($interval) {
151 151
         $f = 0.0;
152
-        if (preg_match('~\.\d+~',$interval,$match)) {
153
-            $interval = str_replace($match[0], "", $interval);
154
-            $f = (float)$match[0];
152
+        if (preg_match ('~\.\d+~', $interval, $match)) {
153
+            $interval = str_replace ($match[0], "", $interval);
154
+            $f = (float) $match[0];
155 155
         }
156
-        $di = new \DateInterval($interval);
156
+        $di = new \DateInterval ($interval);
157 157
         // milliseconds are only available from >=7.1
158
-        if(isset($di->f)){
159
-            $di->f= $f;
158
+        if (isset($di->f)) {
159
+            $di->f = $f;
160 160
         }
161 161
 
162 162
         return $di;
Please login to merge, or discard this patch.