@@ -36,8 +36,7 @@ |
||
36 | 36 | if (!$val instanceof TimeInterval) { |
37 | 37 | if (is_array($val)) { |
38 | 38 | $val = TimeInterval::fromParts($val); |
39 | - } |
|
40 | - else { |
|
39 | + } else { |
|
41 | 40 | $val = TimeInterval::fromString($val); |
42 | 41 | } |
43 | 42 | } |
@@ -21,8 +21,7 @@ |
||
21 | 21 | { |
22 | 22 | if ($str === null) { |
23 | 23 | return null; |
24 | - } |
|
25 | - else { |
|
24 | + } else { |
|
26 | 25 | return PgLogSequenceNumber::fromString($str); |
27 | 26 | } |
28 | 27 | } |
@@ -13,56 +13,56 @@ |
||
13 | 13 | */ |
14 | 14 | class BigIntType extends IntegerType implements IDiscreteType |
15 | 15 | { |
16 | - const _PHP_INT_MIN = (PHP_MAJOR_VERSION >= 7 ? PHP_INT_MIN : -PHP_INT_MAX); // PHP 7: refactor out |
|
16 | + const _PHP_INT_MIN = (PHP_MAJOR_VERSION >= 7 ? PHP_INT_MIN : -PHP_INT_MAX); // PHP 7: refactor out |
|
17 | 17 | |
18 | - public function parseValue($str) |
|
19 | - { |
|
20 | - if ($str > PHP_INT_MAX || $str < self::_PHP_INT_MIN) { // correctness: int does not overflow, but rather gets converted to a float |
|
21 | - return $str; |
|
22 | - } |
|
23 | - else { |
|
24 | - return parent::parseValue($str); |
|
25 | - } |
|
26 | - } |
|
18 | + public function parseValue($str) |
|
19 | + { |
|
20 | + if ($str > PHP_INT_MAX || $str < self::_PHP_INT_MIN) { // correctness: int does not overflow, but rather gets converted to a float |
|
21 | + return $str; |
|
22 | + } |
|
23 | + else { |
|
24 | + return parent::parseValue($str); |
|
25 | + } |
|
26 | + } |
|
27 | 27 | |
28 | - public function serializeValue($val) |
|
29 | - { |
|
30 | - if ($val > PHP_INT_MAX || $val < self::_PHP_INT_MIN) { |
|
31 | - if (preg_match('~^\s*-?[0-9]+\s*$~', $val)) { |
|
32 | - return (string)$val; |
|
33 | - } |
|
34 | - else { |
|
35 | - $this->throwInvalidValue($val); |
|
36 | - } |
|
37 | - } |
|
38 | - else { |
|
39 | - return parent::serializeValue($val); |
|
40 | - } |
|
41 | - } |
|
28 | + public function serializeValue($val) |
|
29 | + { |
|
30 | + if ($val > PHP_INT_MAX || $val < self::_PHP_INT_MIN) { |
|
31 | + if (preg_match('~^\s*-?[0-9]+\s*$~', $val)) { |
|
32 | + return (string)$val; |
|
33 | + } |
|
34 | + else { |
|
35 | + $this->throwInvalidValue($val); |
|
36 | + } |
|
37 | + } |
|
38 | + else { |
|
39 | + return parent::serializeValue($val); |
|
40 | + } |
|
41 | + } |
|
42 | 42 | |
43 | - public function compareValues($a, $b) |
|
44 | - { |
|
45 | - if ($a === null || $b === null) { |
|
46 | - return null; |
|
47 | - } |
|
48 | - if ($a > PHP_INT_MAX || $b > PHP_INT_MAX || $a < self::_PHP_INT_MIN || $b < self::_PHP_INT_MIN) { |
|
49 | - return bccomp($a, $b, 0); |
|
50 | - } |
|
51 | - else { |
|
52 | - return (int)$a - (int)$b; |
|
53 | - } |
|
54 | - } |
|
43 | + public function compareValues($a, $b) |
|
44 | + { |
|
45 | + if ($a === null || $b === null) { |
|
46 | + return null; |
|
47 | + } |
|
48 | + if ($a > PHP_INT_MAX || $b > PHP_INT_MAX || $a < self::_PHP_INT_MIN || $b < self::_PHP_INT_MIN) { |
|
49 | + return bccomp($a, $b, 0); |
|
50 | + } |
|
51 | + else { |
|
52 | + return (int)$a - (int)$b; |
|
53 | + } |
|
54 | + } |
|
55 | 55 | |
56 | - public function step($delta, $value) |
|
57 | - { |
|
58 | - if ($value === null) { |
|
59 | - return null; |
|
60 | - } |
|
61 | - if ($value > PHP_INT_MAX || $value < self::_PHP_INT_MIN) { |
|
62 | - return bcadd($value, $delta, 0); |
|
63 | - } |
|
64 | - else { |
|
65 | - return (int)$value + $delta; |
|
66 | - } |
|
67 | - } |
|
56 | + public function step($delta, $value) |
|
57 | + { |
|
58 | + if ($value === null) { |
|
59 | + return null; |
|
60 | + } |
|
61 | + if ($value > PHP_INT_MAX || $value < self::_PHP_INT_MIN) { |
|
62 | + return bcadd($value, $delta, 0); |
|
63 | + } |
|
64 | + else { |
|
65 | + return (int)$value + $delta; |
|
66 | + } |
|
67 | + } |
|
68 | 68 | } |
@@ -19,8 +19,7 @@ discard block |
||
19 | 19 | { |
20 | 20 | if ($str > PHP_INT_MAX || $str < self::_PHP_INT_MIN) { // correctness: int does not overflow, but rather gets converted to a float |
21 | 21 | return $str; |
22 | - } |
|
23 | - else { |
|
22 | + } else { |
|
24 | 23 | return parent::parseValue($str); |
25 | 24 | } |
26 | 25 | } |
@@ -30,12 +29,10 @@ discard block |
||
30 | 29 | if ($val > PHP_INT_MAX || $val < self::_PHP_INT_MIN) { |
31 | 30 | if (preg_match('~^\s*-?[0-9]+\s*$~', $val)) { |
32 | 31 | return (string)$val; |
33 | - } |
|
34 | - else { |
|
32 | + } else { |
|
35 | 33 | $this->throwInvalidValue($val); |
36 | 34 | } |
37 | - } |
|
38 | - else { |
|
35 | + } else { |
|
39 | 36 | return parent::serializeValue($val); |
40 | 37 | } |
41 | 38 | } |
@@ -47,8 +44,7 @@ discard block |
||
47 | 44 | } |
48 | 45 | if ($a > PHP_INT_MAX || $b > PHP_INT_MAX || $a < self::_PHP_INT_MIN || $b < self::_PHP_INT_MIN) { |
49 | 46 | return bccomp($a, $b, 0); |
50 | - } |
|
51 | - else { |
|
47 | + } else { |
|
52 | 48 | return (int)$a - (int)$b; |
53 | 49 | } |
54 | 50 | } |
@@ -60,8 +56,7 @@ discard block |
||
60 | 56 | } |
61 | 57 | if ($value > PHP_INT_MAX || $value < self::_PHP_INT_MIN) { |
62 | 58 | return bcadd($value, $delta, 0); |
63 | - } |
|
64 | - else { |
|
59 | + } else { |
|
65 | 60 | return (int)$value + $delta; |
66 | 61 | } |
67 | 62 | } |
@@ -43,8 +43,7 @@ discard block |
||
43 | 43 | if (preg_match($re, $str, $m)) { |
44 | 44 | try { |
45 | 45 | return Line::fromEquationCoeffs($m[1], $m[2], $m[3]); |
46 | - } |
|
47 | - catch (\InvalidArgumentException $e) { |
|
46 | + } catch (\InvalidArgumentException $e) { |
|
48 | 47 | $this->throwInvalidValue($str, $e); |
49 | 48 | } |
50 | 49 | } |
@@ -54,8 +53,7 @@ discard block |
||
54 | 53 | /** @var LineSegment $lineSeg */ |
55 | 54 | $lineSeg = $this->lineSegType->parseValue($str); |
56 | 55 | return Line::fromPoints($lineSeg->getStart(), $lineSeg->getEnd()); |
57 | - } |
|
58 | - catch (\InvalidArgumentException $e) { |
|
56 | + } catch (\InvalidArgumentException $e) { |
|
59 | 57 | $this->throwInvalidValue($str, $e); |
60 | 58 | } |
61 | 59 | } |
@@ -64,15 +62,13 @@ discard block |
||
64 | 62 | { |
65 | 63 | if ($val === null) { |
66 | 64 | return 'NULL'; |
67 | - } |
|
68 | - elseif ($val instanceof Line) { |
|
65 | + } elseif ($val instanceof Line) { |
|
69 | 66 | list($p1, $p2) = $val->getPoints(); |
70 | 67 | return sprintf('line(%s,%s)', |
71 | 68 | $this->pointType->serializeValue($p1), |
72 | 69 | $this->pointType->serializeValue($p2) |
73 | 70 | ); |
74 | - } |
|
75 | - else { |
|
71 | + } else { |
|
76 | 72 | $this->throwInvalidValue($val); |
77 | 73 | } |
78 | 74 | } |
@@ -13,26 +13,26 @@ discard block |
||
13 | 13 | */ |
14 | 14 | class DecimalType extends \Ivory\Type\BaseType implements ITotallyOrderedType |
15 | 15 | { |
16 | - public function parseValue($str) |
|
17 | - { |
|
18 | - if ($str === null) { |
|
19 | - return null; |
|
20 | - } |
|
21 | - |
|
22 | - if (strcasecmp($str, 'NaN') == 0) { |
|
23 | - return Decimal::NaN(); |
|
24 | - } |
|
25 | - |
|
26 | - return Decimal::fromNumber($str); |
|
27 | - } |
|
28 | - |
|
29 | - public function serializeValue($val) |
|
30 | - { |
|
31 | - if ($val === null) { |
|
32 | - return 'NULL'; |
|
33 | - } |
|
34 | - |
|
35 | - if (!$val instanceof Decimal) { |
|
16 | + public function parseValue($str) |
|
17 | + { |
|
18 | + if ($str === null) { |
|
19 | + return null; |
|
20 | + } |
|
21 | + |
|
22 | + if (strcasecmp($str, 'NaN') == 0) { |
|
23 | + return Decimal::NaN(); |
|
24 | + } |
|
25 | + |
|
26 | + return Decimal::fromNumber($str); |
|
27 | + } |
|
28 | + |
|
29 | + public function serializeValue($val) |
|
30 | + { |
|
31 | + if ($val === null) { |
|
32 | + return 'NULL'; |
|
33 | + } |
|
34 | + |
|
35 | + if (!$val instanceof Decimal) { |
|
36 | 36 | $val = Decimal::fromNumber($val); |
37 | 37 | } |
38 | 38 | |
@@ -41,17 +41,17 @@ discard block |
||
41 | 41 | } |
42 | 42 | else { |
43 | 43 | return $val->toString(); |
44 | - } |
|
45 | - } |
|
46 | - |
|
47 | - public function compareValues($a, $b) |
|
48 | - { |
|
49 | - if ($a === null || $b === null) { |
|
50 | - return null; |
|
51 | - } |
|
52 | - if (!$a instanceof Decimal) { |
|
53 | - $a = Decimal::fromNumber($a); |
|
54 | - } |
|
55 | - return $a->compareTo($b); |
|
56 | - } |
|
44 | + } |
|
45 | + } |
|
46 | + |
|
47 | + public function compareValues($a, $b) |
|
48 | + { |
|
49 | + if ($a === null || $b === null) { |
|
50 | + return null; |
|
51 | + } |
|
52 | + if (!$a instanceof Decimal) { |
|
53 | + $a = Decimal::fromNumber($a); |
|
54 | + } |
|
55 | + return $a->compareTo($b); |
|
56 | + } |
|
57 | 57 | } |
@@ -38,8 +38,7 @@ |
||
38 | 38 | |
39 | 39 | if ($val->isNaN()) { |
40 | 40 | return "'NaN'"; |
41 | - } |
|
42 | - else { |
|
41 | + } else { |
|
43 | 42 | return $val->toString(); |
44 | 43 | } |
45 | 44 | } |
@@ -15,8 +15,7 @@ discard block |
||
15 | 15 | { |
16 | 16 | if ($str === null) { |
17 | 17 | return null; |
18 | - } |
|
19 | - else { |
|
18 | + } else { |
|
20 | 19 | throw new InternalException('A non-null value to be parsed for a polymorphic pseudo-type'); |
21 | 20 | } |
22 | 21 | } |
@@ -25,8 +24,7 @@ discard block |
||
25 | 24 | { |
26 | 25 | if ($val === null) { |
27 | 26 | return 'NULL'; |
28 | - } |
|
29 | - else { |
|
27 | + } else { |
|
30 | 28 | $this->throwInvalidValue($val); |
31 | 29 | } |
32 | 30 | } |
@@ -12,36 +12,36 @@ |
||
12 | 12 | */ |
13 | 13 | class IntegerType extends \Ivory\Type\BaseType implements IDiscreteType |
14 | 14 | { |
15 | - public function parseValue($str) |
|
16 | - { |
|
17 | - if ($str === null) { |
|
18 | - return null; |
|
19 | - } |
|
20 | - else { |
|
21 | - return (int)$str; |
|
22 | - } |
|
23 | - } |
|
15 | + public function parseValue($str) |
|
16 | + { |
|
17 | + if ($str === null) { |
|
18 | + return null; |
|
19 | + } |
|
20 | + else { |
|
21 | + return (int)$str; |
|
22 | + } |
|
23 | + } |
|
24 | 24 | |
25 | - public function serializeValue($val) |
|
26 | - { |
|
27 | - if ($val === null) { |
|
28 | - return 'NULL'; |
|
29 | - } |
|
30 | - else { |
|
31 | - return (int)$val; |
|
32 | - } |
|
33 | - } |
|
25 | + public function serializeValue($val) |
|
26 | + { |
|
27 | + if ($val === null) { |
|
28 | + return 'NULL'; |
|
29 | + } |
|
30 | + else { |
|
31 | + return (int)$val; |
|
32 | + } |
|
33 | + } |
|
34 | 34 | |
35 | - public function compareValues($a, $b) |
|
36 | - { |
|
37 | - if ($a === null || $b === null) { |
|
38 | - return null; |
|
39 | - } |
|
40 | - return (int)$a - (int)$b; |
|
41 | - } |
|
35 | + public function compareValues($a, $b) |
|
36 | + { |
|
37 | + if ($a === null || $b === null) { |
|
38 | + return null; |
|
39 | + } |
|
40 | + return (int)$a - (int)$b; |
|
41 | + } |
|
42 | 42 | |
43 | - public function step($delta, $value) |
|
44 | - { |
|
45 | - return ($value === null ? null : $value + $delta); |
|
46 | - } |
|
43 | + public function step($delta, $value) |
|
44 | + { |
|
45 | + return ($value === null ? null : $value + $delta); |
|
46 | + } |
|
47 | 47 | } |
@@ -16,8 +16,7 @@ discard block |
||
16 | 16 | { |
17 | 17 | if ($str === null) { |
18 | 18 | return null; |
19 | - } |
|
20 | - else { |
|
19 | + } else { |
|
21 | 20 | return (int)$str; |
22 | 21 | } |
23 | 22 | } |
@@ -26,8 +25,7 @@ discard block |
||
26 | 25 | { |
27 | 26 | if ($val === null) { |
28 | 27 | return 'NULL'; |
29 | - } |
|
30 | - else { |
|
28 | + } else { |
|
31 | 29 | return (int)$val; |
32 | 30 | } |
33 | 31 | } |
@@ -21,8 +21,7 @@ |
||
21 | 21 | |
22 | 22 | try { |
23 | 23 | return Json::fromEncoded($str); |
24 | - } |
|
25 | - catch (\InvalidArgumentException $e) { |
|
24 | + } catch (\InvalidArgumentException $e) { |
|
26 | 25 | $this->throwInvalidValue($str, $e); |
27 | 26 | } |
28 | 27 | } |
@@ -12,30 +12,30 @@ |
||
12 | 12 | */ |
13 | 13 | abstract class BitStringType extends \Ivory\Type\BaseType implements ITotallyOrderedType |
14 | 14 | { |
15 | - public function serializeValue($val) |
|
16 | - { |
|
17 | - if ($val === null) { |
|
18 | - return 'NULL'; |
|
19 | - } |
|
20 | - elseif ($val instanceof BitString) { |
|
21 | - return "B'" . $val->toString() . "'"; |
|
22 | - } |
|
23 | - else { |
|
24 | - $this->throwInvalidValue($val); |
|
25 | - } |
|
26 | - } |
|
15 | + public function serializeValue($val) |
|
16 | + { |
|
17 | + if ($val === null) { |
|
18 | + return 'NULL'; |
|
19 | + } |
|
20 | + elseif ($val instanceof BitString) { |
|
21 | + return "B'" . $val->toString() . "'"; |
|
22 | + } |
|
23 | + else { |
|
24 | + $this->throwInvalidValue($val); |
|
25 | + } |
|
26 | + } |
|
27 | 27 | |
28 | - public function compareValues($a, $b) |
|
29 | - { |
|
30 | - if ($a === null || $b === null) { |
|
31 | - return null; |
|
32 | - } |
|
33 | - if (!$a instanceof BitString) { |
|
34 | - throw new IncomparableException('$a is not a ' . BitString::class); |
|
35 | - } |
|
36 | - if (!$b instanceof BitString) { |
|
37 | - throw new IncomparableException('$b is not a ' . BitString::class); |
|
38 | - } |
|
39 | - return strcmp($a->toString(), $b->toString()); |
|
40 | - } |
|
28 | + public function compareValues($a, $b) |
|
29 | + { |
|
30 | + if ($a === null || $b === null) { |
|
31 | + return null; |
|
32 | + } |
|
33 | + if (!$a instanceof BitString) { |
|
34 | + throw new IncomparableException('$a is not a ' . BitString::class); |
|
35 | + } |
|
36 | + if (!$b instanceof BitString) { |
|
37 | + throw new IncomparableException('$b is not a ' . BitString::class); |
|
38 | + } |
|
39 | + return strcmp($a->toString(), $b->toString()); |
|
40 | + } |
|
41 | 41 | } |
@@ -16,11 +16,9 @@ |
||
16 | 16 | { |
17 | 17 | if ($val === null) { |
18 | 18 | return 'NULL'; |
19 | - } |
|
20 | - elseif ($val instanceof BitString) { |
|
19 | + } elseif ($val instanceof BitString) { |
|
21 | 20 | return "B'" . $val->toString() . "'"; |
22 | - } |
|
23 | - else { |
|
21 | + } else { |
|
24 | 22 | $this->throwInvalidValue($val); |
25 | 23 | } |
26 | 24 | } |