Completed
Pull Request — master (#12)
by
unknown
01:38
created
src/Jms/Handler/XmlSchemaDateHandler.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -69,19 +69,19 @@  discard block
 block discarded – undo
69 69
 
70 70
     public function __construct($defaultTimezone = 'UTC')
71 71
     {
72
-        $this->defaultTimezone = new \DateTimeZone($defaultTimezone);
72
+        $this->defaultTimezone = new \DateTimeZone ($defaultTimezone);
73 73
 
74 74
     }
75 75
 
76
-    public function deserializeDateIntervalXml(XmlDeserializationVisitor $visitor, $data, array $type){
77
-        $attributes = $data->attributes('xsi', true);
76
+    public function deserializeDateIntervalXml(XmlDeserializationVisitor $visitor, $data, array $type) {
77
+        $attributes = $data->attributes ('xsi', true);
78 78
         if (isset($attributes['nil'][0]) && (string) $attributes['nil'][0] === 'true') {
79 79
             return null;
80 80
         }
81 81
 
82 82
         //Accept negative intervals like -PT1M23S.  Safe to assume that "-" doesn't exist elsewhere in a valid interval spec.
83
-        $interval = str_replace('-', '', (string)$data, $count);
84
-        $dateInterval = new \DateInterval($interval);
83
+        $interval = str_replace ('-', '', (string) $data, $count);
84
+        $dateInterval = new \DateInterval ($interval);
85 85
 
86 86
         //Invert if a negative sign was found
87 87
         $dateInterval->invert = !!$count;
@@ -91,14 +91,14 @@  discard block
 block discarded – undo
91 91
 
92 92
     public function serializeDateInterval(XmlSerializationVisitor $visitor, \DateInterval $interval, array $type, Context $context)
93 93
     {
94
-        $date = array_filter(array(
94
+        $date = array_filter (array(
95 95
             'Y' => $interval->y,
96 96
             'M' => $interval->m,
97 97
             'D' => $interval->d
98 98
         ));
99 99
 
100 100
         // Reading all non-zero time parts.
101
-        $time = array_filter(array(
101
+        $time = array_filter (array(
102 102
             'H' => $interval->h,
103 103
             'M' => $interval->i,
104 104
             'S' => $interval->s
@@ -108,84 +108,84 @@  discard block
 block discarded – undo
108 108
 
109 109
         // Adding each part to the spec-string.
110 110
         foreach ($date as $key => $value) {
111
-            $specString .= $value . $key;
111
+            $specString .= $value.$key;
112 112
         }
113
-        if (count($time) > 0) {
113
+        if (count ($time) > 0) {
114 114
             $specString .= 'T';
115 115
             foreach ($time as $key => $value) {
116
-                $specString .= $value . $key;
116
+                $specString .= $value.$key;
117 117
             }
118 118
         }
119 119
 
120
-        return $visitor->visitSimpleString($specString, $type, $context);
120
+        return $visitor->visitSimpleString ($specString, $type, $context);
121 121
     }
122 122
 
123 123
     public function serializeDate(XmlSerializationVisitor $visitor, \DateTime $date, array $type, Context $context)
124 124
     {
125
-        $v = $date->format('Y-m-d');
125
+        $v = $date->format ('Y-m-d');
126 126
 
127
-        return $visitor->visitSimpleString($v, $type, $context);
127
+        return $visitor->visitSimpleString ($v, $type, $context);
128 128
     }
129 129
 
130 130
     public function deserializeDate(XmlDeserializationVisitor $visitor, $data, array $type)
131 131
     {
132
-        $attributes = $data->attributes('xsi', true);
133
-        if (isset($attributes['nil'][0]) && (string)$attributes['nil'][0] === 'true') {
132
+        $attributes = $data->attributes ('xsi', true);
133
+        if (isset($attributes['nil'][0]) && (string) $attributes['nil'][0] === 'true') {
134 134
             return null;
135 135
         }
136
-        if (!preg_match('/^(\d{4})-(\d{2})-(\d{2})(Z|([+-]\d{2}:\d{2}))?$/', $data)) {
137
-            throw new RuntimeException(sprintf('Invalid date "%s", expected valid XML Schema date string.', $data));
136
+        if (!preg_match ('/^(\d{4})-(\d{2})-(\d{2})(Z|([+-]\d{2}:\d{2}))?$/', $data)) {
137
+            throw new RuntimeException (sprintf ('Invalid date "%s", expected valid XML Schema date string.', $data));
138 138
         }
139 139
 
140
-        return $this->parseDateTime($data, $type);
140
+        return $this->parseDateTime ($data, $type);
141 141
     }
142 142
 
143 143
     public function serializeDateTime(XmlSerializationVisitor $visitor, \DateTime $date, array $type, Context $context)
144 144
     {
145 145
 
146
-        $v = $date->format(\DateTime::W3C);
146
+        $v = $date->format (\DateTime::W3C);
147 147
 
148
-        return $visitor->visitSimpleString($v, $type, $context);
148
+        return $visitor->visitSimpleString ($v, $type, $context);
149 149
     }
150 150
 
151 151
     public function deserializeDateTime(XmlDeserializationVisitor $visitor, $data, array $type)
152 152
     {
153
-        $attributes = $data->attributes('xsi', true);
154
-        if (isset($attributes['nil'][0]) && (string)$attributes['nil'][0] === 'true') {
153
+        $attributes = $data->attributes ('xsi', true);
154
+        if (isset($attributes['nil'][0]) && (string) $attributes['nil'][0] === 'true') {
155 155
             return null;
156 156
         }
157 157
 
158
-        return $this->parseDateTime($data, $type);
158
+        return $this->parseDateTime ($data, $type);
159 159
 
160 160
     }
161 161
 
162 162
     public function serializeTime(XmlSerializationVisitor $visitor, \DateTime $date, array $type, Context $context)
163 163
     {
164
-        $v = $date->format('H:i:s');
165
-        if ($date->getTimezone()->getOffset($date) !== $this->defaultTimezone->getOffset($date)) {
166
-            $v .= $date->format('P');
164
+        $v = $date->format ('H:i:s');
165
+        if ($date->getTimezone ()->getOffset ($date) !== $this->defaultTimezone->getOffset ($date)) {
166
+            $v .= $date->format ('P');
167 167
         }
168
-        return $visitor->visitSimpleString($v, $type, $context);
168
+        return $visitor->visitSimpleString ($v, $type, $context);
169 169
     }
170 170
 
171 171
     public function deserializeTime(XmlDeserializationVisitor $visitor, $data, array $type)
172 172
     {
173
-        $attributes = $data->attributes('xsi', true);
174
-        if (isset($attributes['nil'][0]) && (string)$attributes['nil'][0] === 'true') {
173
+        $attributes = $data->attributes ('xsi', true);
174
+        if (isset($attributes['nil'][0]) && (string) $attributes['nil'][0] === 'true') {
175 175
             return null;
176 176
         }
177 177
 
178
-        $data = (string)$data;
178
+        $data = (string) $data;
179 179
 
180
-        return new \DateTime($data, $this->defaultTimezone);
180
+        return new \DateTime ($data, $this->defaultTimezone);
181 181
     }
182 182
 
183 183
     private function parseDateTime($data, array $type)
184 184
     {
185
-        $timezone = isset($type['params'][1]) ? new \DateTimeZone($type['params'][1]) : $this->defaultTimezone;
186
-        $datetime = new \DateTime((string)$data, $timezone);
185
+        $timezone = isset($type['params'][1]) ? new \DateTimeZone ($type['params'][1]) : $this->defaultTimezone;
186
+        $datetime = new \DateTime ((string) $data, $timezone);
187 187
         if (false === $datetime) {
188
-            throw new RuntimeException(sprintf('Invalid datetime "%s", expected valid XML Schema dateTime string.', $data));
188
+            throw new RuntimeException (sprintf ('Invalid datetime "%s", expected valid XML Schema dateTime string.', $data));
189 189
         }
190 190
 
191 191
         return $datetime;
Please login to merge, or discard this patch.