@@ -198,20 +198,16 @@ discard block |
||
198 | 198 | $timeDelimPos = strpos($str, 'T'); |
199 | 199 | if (!$timeDelimPos) { |
200 | 200 | $parts = self::parseIsoDateStr(substr($str, 1)); |
201 | - } |
|
202 | - elseif ($timeDelimPos == 1) { |
|
201 | + } elseif ($timeDelimPos == 1) { |
|
203 | 202 | $parts = self::parseTimeStr($str, 2); |
204 | - } |
|
205 | - else { |
|
203 | + } else { |
|
206 | 204 | $parts = self::parseIsoDateStr(substr($str, 1, $timeDelimPos - 1)) + |
207 | 205 | self::parseTimeStr($str, $timeDelimPos + 1); |
208 | 206 | } |
209 | - } |
|
210 | - elseif ($str[0] == '@') { |
|
207 | + } elseif ($str[0] == '@') { |
|
211 | 208 | // verbose PostgreSQL format |
212 | 209 | $parts = self::parsePostgresqlStr($str, 1); |
213 | - } |
|
214 | - elseif (preg_match('~^(?:(-)?(\d+)-(\d+))?\s*(-?\d+)??\s*(-?\d+(?::\d+(?::\d+(?:\.\d+)?)?)?)?$~', $str, $m)) { |
|
210 | + } elseif (preg_match('~^(?:(-)?(\d+)-(\d+))?\s*(-?\d+)??\s*(-?\d+(?::\d+(?::\d+(?:\.\d+)?)?)?)?$~', $str, $m)) { |
|
215 | 211 | // sql format |
216 | 212 | $parts = (isset($m[5]) ? self::parseTimeStr($m[5], 0, false) : []); |
217 | 213 | if (!empty($m[2]) || !empty($m[3])) { |
@@ -222,8 +218,7 @@ discard block |
||
222 | 218 | if (!empty($m[4])) { |
223 | 219 | $parts[self::DAY] = (int)$m[4]; |
224 | 220 | } |
225 | - } |
|
226 | - else { |
|
221 | + } else { |
|
227 | 222 | // PostgreSQL format |
228 | 223 | $parts = self::parsePostgresqlStr($str); |
229 | 224 | } |
@@ -239,8 +234,7 @@ discard block |
||
239 | 234 | self::MONTH => (int)$m[2], |
240 | 235 | self::DAY => (int)$m[3], |
241 | 236 | ]; |
242 | - } |
|
243 | - else { |
|
237 | + } else { |
|
244 | 238 | $parts = []; |
245 | 239 | preg_match_all('~(-?\d+(?:\.\d+)?)([YMDW])~', $str, $matches, PREG_SET_ORDER); |
246 | 240 | static $units = ['Y' => self::YEAR, 'M' => self::MONTH, 'D' => self::DAY, 'W' => self::WEEK]; |
@@ -266,14 +260,12 @@ discard block |
||
266 | 260 | self::MINUTE => $sgn * $m[2], |
267 | 261 | self::SECOND => $sgn * (isset($m[3]) ? (float)$m[3] : 0), |
268 | 262 | ]; |
269 | - } |
|
270 | - else { |
|
263 | + } else { |
|
271 | 264 | return [ |
272 | 265 | self::SECOND => (float)$m[1], |
273 | 266 | ]; |
274 | 267 | } |
275 | - } |
|
276 | - else { |
|
268 | + } else { |
|
277 | 269 | $parts = []; |
278 | 270 | preg_match_all('~(-?\d+(?:\.\d+)?)([HMS])~', $str, $matches, PREG_SET_ORDER, $offset); |
279 | 271 | static $units = ['H' => self::HOUR, 'M' => self::MINUTE, 'S' => self::SECOND]; |
@@ -136,8 +136,7 @@ discard block |
||
136 | 136 | |
137 | 137 | if ($month >= 1 && $month <= 12 && $day >= 1 && $day <= 31) { // works even for months without 31 days |
138 | 138 | return self::fromISOString(sprintf('%s%04d-%02d-%02d', ($z < 0 ? '-' : ''), abs($z), $month, $day)); |
139 | - } |
|
140 | - else { |
|
139 | + } else { |
|
141 | 140 | return self::fromISOString(sprintf('%s%04d-01-01', ($z < 0 ? '-' : ''), abs($z))) |
142 | 141 | ->addParts(0, $month - 1, $day - 1); |
143 | 142 | } |
@@ -178,8 +177,7 @@ discard block |
||
178 | 177 | $date = self::fromISOString(sprintf('%s%04d-%02d-%02d', ($z < 0 ? '-' : ''), abs($z), $month, $day)); |
179 | 178 | if ($date->format('j') == $day) { |
180 | 179 | return $date; |
181 | - } |
|
182 | - else { |
|
180 | + } else { |
|
183 | 181 | throw new \OutOfRangeException('$day out of range'); |
184 | 182 | } |
185 | 183 | } |
@@ -224,8 +222,7 @@ discard block |
||
224 | 222 | { |
225 | 223 | if ($this->inf) { |
226 | 224 | return null; |
227 | - } |
|
228 | - else { |
|
225 | + } else { |
|
229 | 226 | $z = (int)$this->dt->format('Y'); |
230 | 227 | return [($z > 0 ? $z : $z - 1), (int)$this->dt->format('n'), (int)$this->dt->format('j')]; |
231 | 228 | } |
@@ -25,15 +25,13 @@ |
||
25 | 25 | { |
26 | 26 | if (is_array($start)) { |
27 | 27 | $start = Point::fromCoords($start); |
28 | - } |
|
29 | - elseif (!$start instanceof Point) { |
|
28 | + } elseif (!$start instanceof Point) { |
|
30 | 29 | throw new \InvalidArgumentException('start'); |
31 | 30 | } |
32 | 31 | |
33 | 32 | if (is_array($end)) { |
34 | 33 | $end = Point::fromCoords($end); |
35 | - } |
|
36 | - elseif (!$end instanceof Point) { |
|
34 | + } elseif (!$end instanceof Point) { |
|
37 | 35 | throw new \InvalidArgumentException('end'); |
38 | 36 | } |
39 | 37 |
@@ -23,26 +23,22 @@ discard block |
||
23 | 23 | if (is_string($value)) { |
24 | 24 | $xmlStr = $value; |
25 | 25 | $isDoc = self::isXmlDocument($value); |
26 | - } |
|
27 | - elseif ($value instanceof XmlContent) { |
|
26 | + } elseif ($value instanceof XmlContent) { |
|
28 | 27 | return $value; |
29 | - } |
|
30 | - elseif ($value instanceof \DOMDocument) { |
|
28 | + } elseif ($value instanceof \DOMDocument) { |
|
31 | 29 | $xmlStr = $value->saveXML(); |
32 | 30 | if ($xmlStr === false) { |
33 | 31 | throw new \InvalidArgumentException('value'); |
34 | 32 | } |
35 | 33 | $isDoc = true; |
36 | - } |
|
37 | - elseif ($value instanceof \DOMNode) { |
|
34 | + } elseif ($value instanceof \DOMNode) { |
|
38 | 35 | $d = $value->ownerDocument->saveXML($value); |
39 | 36 | if ($d === false) { |
40 | 37 | throw new \InvalidArgumentException('value'); |
41 | 38 | } |
42 | 39 | $xmlStr = self::getXMLDeclaration($value->ownerDocument) . $d; |
43 | 40 | $isDoc = true; |
44 | - } |
|
45 | - elseif ($value instanceof \DOMNodeList) { |
|
41 | + } elseif ($value instanceof \DOMNodeList) { |
|
46 | 42 | $xmlStr = ($value->length > 0 ? self::getXMLDeclaration($value->item(0)->ownerDocument) : ''); |
47 | 43 | foreach ($value as $i => $node) { |
48 | 44 | $n = $node->ownerDocument->saveXML($node); |
@@ -52,26 +48,22 @@ discard block |
||
52 | 48 | $xmlStr .= $n; |
53 | 49 | } |
54 | 50 | $isDoc = ($value->length == 1); |
55 | - } |
|
56 | - elseif ($value instanceof \SimpleXMLElement) { |
|
51 | + } elseif ($value instanceof \SimpleXMLElement) { |
|
57 | 52 | $xmlStr = $value->saveXML(); |
58 | 53 | if ($xmlStr === false) { |
59 | 54 | throw new \InvalidArgumentException('value'); |
60 | 55 | } |
61 | 56 | $isDoc = true; |
62 | - } |
|
63 | - elseif (is_object($value)) { |
|
57 | + } elseif (is_object($value)) { |
|
64 | 58 | $xmlStr = (string)$value; |
65 | 59 | $isDoc = self::isXmlDocument($value); |
66 | - } |
|
67 | - else { |
|
60 | + } else { |
|
68 | 61 | throw new \InvalidArgumentException('value'); |
69 | 62 | } |
70 | 63 | |
71 | 64 | if ($isDoc) { |
72 | 65 | return new XmlDocument($xmlStr); |
73 | - } |
|
74 | - else { |
|
66 | + } else { |
|
75 | 67 | return new XmlContent($xmlStr); |
76 | 68 | } |
77 | 69 | } |
@@ -49,11 +49,9 @@ |
||
49 | 49 | foreach ($points as $i => $point) { |
50 | 50 | if ($point instanceof Point) { |
51 | 51 | $normalized[] = $point; |
52 | - } |
|
53 | - elseif (is_array($point)) { |
|
52 | + } elseif (is_array($point)) { |
|
54 | 53 | $normalized[] = Point::fromCoords($point[0], $point[1]); |
55 | - } |
|
56 | - else { |
|
54 | + } else { |
|
57 | 55 | throw new \InvalidArgumentException("points[$i]"); |
58 | 56 | } |
59 | 57 | } |
@@ -31,8 +31,7 @@ discard block |
||
31 | 31 | { |
32 | 32 | if (PHP_VERSION_ID >= 70100) { |
33 | 33 | return new Timestamp(0, new \DateTimeImmutable('now', self::getUTCTimeZone())); |
34 | - } |
|
35 | - else { |
|
34 | + } else { |
|
36 | 35 | // up to PHP 7.0, new \DateTimeImmutable('now') had only precision up to seconds |
37 | 36 | list($micro, $sec) = explode(' ', microtime()); |
38 | 37 | $microFrac = substr($micro, 1); // cut off the whole part (always a zero) |
@@ -111,8 +110,7 @@ discard block |
||
111 | 110 | '%s%04d-%02d-%02d %02d:%02d:%s', |
112 | 111 | ($z < 0 ? '-' : ''), abs($z), $month, $day, $hour, $minute, self::floatToTwoPlaces($second) |
113 | 112 | )); |
114 | - } |
|
115 | - else { |
|
113 | + } else { |
|
116 | 114 | return self::fromISOString(sprintf('%s%04d-01-01 00:00:00', ($z < 0 ? '-' : ''), abs($z))) |
117 | 115 | ->addParts(0, $month - 1, $day - 1, $hour, $minute, $second); |
118 | 116 | } |
@@ -176,8 +174,7 @@ discard block |
||
176 | 174 | { |
177 | 175 | if ($this->inf) { |
178 | 176 | return null; |
179 | - } |
|
180 | - else { |
|
177 | + } else { |
|
181 | 178 | $y = (int)$this->dt->format('Y'); |
182 | 179 | $u = $this->dt->format('u'); |
183 | 180 | return [ |
@@ -35,15 +35,12 @@ |
||
35 | 35 | |
36 | 36 | if ($maxLength === null) { |
37 | 37 | return new VarBitString($bits, null); |
38 | - } |
|
39 | - elseif ($maxLength <= 0) { |
|
38 | + } elseif ($maxLength <= 0) { |
|
40 | 39 | throw new \InvalidArgumentException('maxLength is non-positive'); |
41 | - } |
|
42 | - elseif ($maxLength < strlen($bits)) { |
|
40 | + } elseif ($maxLength < strlen($bits)) { |
|
43 | 41 | trigger_error("Bit string truncated to the length of $maxLength", E_USER_WARNING); |
44 | 42 | return new VarBitString(substr($bits, 0, $maxLength), $maxLength); |
45 | - } |
|
46 | - else { |
|
43 | + } else { |
|
47 | 44 | return new VarBitString($bits, $maxLength); |
48 | 45 | } |
49 | 46 | } |
@@ -93,8 +93,7 @@ |
||
93 | 93 | { |
94 | 94 | if (PHP_VERSION_ID >= 50500) { |
95 | 95 | return json_last_error_msg(); |
96 | - } |
|
97 | - else { |
|
96 | + } else { |
|
98 | 97 | static $messages = [ |
99 | 98 | JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', |
100 | 99 | JSON_ERROR_STATE_MISMATCH => 'Underflow or the modes mismatch', |
@@ -88,8 +88,7 @@ discard block |
||
88 | 88 | if (isset($m[3]) && $m[3] !== '') { |
89 | 89 | $val .= '.' . preg_replace('~\D+~', '', $m[3]); |
90 | 90 | $val = (float)$val; |
91 | - } |
|
92 | - else { |
|
91 | + } else { |
|
93 | 92 | $val = (int)$val; |
94 | 93 | } |
95 | 94 | |
@@ -151,8 +150,7 @@ discard block |
||
151 | 150 | if ($this->unit == $quantity->unit) { |
152 | 151 | $thisNormValue = $this->value; |
153 | 152 | $quanNormValue = $quantity->value; |
154 | - } |
|
155 | - else { |
|
153 | + } else { |
|
156 | 154 | if (!isset(self::$conversion[$this->unit], self::$conversion[$quantity->unit])) { |
157 | 155 | return false; |
158 | 156 | } |
@@ -183,8 +181,7 @@ discard block |
||
183 | 181 | if (!$this->unit || !$destUnit) { |
184 | 182 | if ($this->value == 0) { |
185 | 183 | return new Quantity($this->value, $destUnit); |
186 | - } |
|
187 | - else { |
|
184 | + } else { |
|
188 | 185 | throw new UndefinedOperationException('Conversion from/to dimensionless quantity is undefined.'); |
189 | 186 | } |
190 | 187 | } |