@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * Hence the lessonperson.schedulingstatus attribute, holding enum values "scheduled" or "actual". |
24 | 24 | */ |
25 | 25 | $rel = new StatementRelation( |
26 | - 'SELECT lesson.id AS lesson_id, lesson.name AS lesson_name, |
|
26 | + 'SELECT lesson.id AS lesson_id, lesson.name AS lesson_name, |
|
27 | 27 | lp.schedulingstatus, |
28 | 28 | p.id AS person_id, p.firstname AS person_firstname, p.lastname AS person_lastname, |
29 | 29 | p.schedabbr AS person_schedabbr |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | JOIN lessonperson lp ON lp.lesson_id = lesson.id |
32 | 32 | JOIN person p ON p.id = lp.person_id |
33 | 33 | WHERE lesson.actual_timerange && %', |
34 | - new DateTimeRange(new \DateTime(), new \DateTime('+1 day')) |
|
34 | + new DateTimeRange(new \DateTime(), new \DateTime('+1 day')) |
|
35 | 35 | ); |
36 | 36 | |
37 | 37 | // CASE 1; map: lesson ID => row |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | |
50 | 50 | // CASE 4; map: lesson ID => map: person ID => user function result |
51 | 51 | $res = $rel->map('lesson_id')->map('person_id')->col(function ($row) { |
52 | - return ($row['person_schedabbr'] ? : mb_substr($row['person_lastname'], 0, 4)); |
|
52 | + return ($row['person_schedabbr'] ? : mb_substr($row['person_lastname'], 0, 4)); |
|
53 | 53 | }); |
54 | 54 | var_dump($res[4][7]); // prints, e.g., "Brez", which is the scheduling abbreviation of person 7, who teaches in lesson 4 |
55 | 55 |
@@ -48,8 +48,8 @@ discard block |
||
48 | 48 | var_dump($res[4][7]['person_lastname']); // prints, e.g., "Brezina", which is the lastname of person 7, who teaches in lesson 4 |
49 | 49 | |
50 | 50 | // CASE 4; map: lesson ID => map: person ID => user function result |
51 | -$res = $rel->map('lesson_id')->map('person_id')->col(function ($row) { |
|
52 | - return ($row['person_schedabbr'] ? : mb_substr($row['person_lastname'], 0, 4)); |
|
51 | +$res = $rel->map('lesson_id')->map('person_id')->col(function($row) { |
|
52 | + return ($row['person_schedabbr'] ?: mb_substr($row['person_lastname'], 0, 4)); |
|
53 | 53 | }); |
54 | 54 | var_dump($res[4][7]); // prints, e.g., "Brez", which is the scheduling abbreviation of person 7, who teaches in lesson 4 |
55 | 55 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | var_dump($res[4]['actual'][1]); // prints, e.g., 89, which is the ID of the second actual teacher returned for lesson 4 |
71 | 71 | |
72 | 72 | // CASE 9; map: lesson ID parity => list: row only with the lesson ID and person ID |
73 | -$res = $rel->multimap(function ($row) { return $row['lesson_id'] % 2; })->project(['lesson_id', 'person_id']); |
|
73 | +$res = $rel->multimap(function($row) { return $row['lesson_id'] % 2; })->project(['lesson_id', 'person_id']); |
|
74 | 74 | var_dump($res[1][5]['lesson_id']); // prints, e.g., 631, which is the ID of the sixth returned lesson with odd ID |
75 | 75 | |
76 | 76 | // CASE 10; map: lesson ID => list of rows with the "actual" scheduling status: person ID |
@@ -78,14 +78,14 @@ discard block |
||
78 | 78 | var_dump($res[4][1]); // prints, e.g., 89, which is the ID of the second actual teacher returned for lesson 4 |
79 | 79 | |
80 | 80 | // CASE 11; map: lesson ID => list of rows with odd person ID: person ID |
81 | -$res = $rel->multimap('lesson_id')->filter(function ($row) { return $row['person_id'] % 2 == 1; })->col('person_id'); |
|
81 | +$res = $rel->multimap('lesson_id')->filter(function($row) { return $row['person_id'] % 2 == 1; })->col('person_id'); |
|
82 | 82 | var_dump($res[4][1]); // prints, e.g., 97, which is the ID of the second teacher returned for lesson 4 who has their person ID odd |
83 | 83 | |
84 | 84 | // CASE 12; equivalent to CASE 11, but specifying the filter sooner, yet on the application side |
85 | -$res = $rel->filter(function ($row) { return $row['person_id'] % 2 == 1; })->multimap('lesson_id')->col('person_id'); |
|
85 | +$res = $rel->filter(function($row) { return $row['person_id'] % 2 == 1; })->multimap('lesson_id')->col('person_id'); |
|
86 | 86 | |
87 | 87 | // CASE 13: equivalent to CASE 11, but with the filter applied to the single-column projection |
88 | -$res = $rel->multimap('lesson_id')->col('person_id')->filter(function ($personId) { return $personId % 2 == 1; }); |
|
88 | +$res = $rel->multimap('lesson_id')->col('person_id')->filter(function($personId) { return $personId % 2 == 1; }); |
|
89 | 89 | |
90 | 90 | // CASE 14; list: row only with the lesson_id and person_id attributes |
91 | 91 | $res = $rel->project(['lesson_id', 'person_id']); |
@@ -65,7 +65,7 @@ |
||
65 | 65 | $addYears = 0; |
66 | 66 | $dateCreateInput = preg_replace_callback( |
67 | 67 | '~\d{5,}(?=-|\d{4})~', // supports both dash-separated date parts and also the form without dash separators |
68 | - function ($y) use (&$addYears) { |
|
68 | + function($y) use (&$addYears) { |
|
69 | 69 | $res = $y[0] % 10000; |
70 | 70 | $addYears = $y[0] - $res; |
71 | 71 | return $res; |
@@ -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 [ |
@@ -17,66 +17,66 @@ |
||
17 | 17 | */ |
18 | 18 | class VarBitString extends BitString |
19 | 19 | { |
20 | - /** @var int|null */ |
|
21 | - private $maxLength; |
|
20 | + /** @var int|null */ |
|
21 | + private $maxLength; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @param string $bits the bit string, i.e., a string of 1's and 0's |
|
25 | - * @param int|null $maxLength maximal length of the bit string in bits; |
|
26 | - * <tt>null</tt> for no limit; |
|
27 | - * if less than <tt>strlen($bits)</tt>, the bits get truncated on the right and a warning |
|
28 | - * is issued |
|
29 | - * @return VarBitString |
|
30 | - * @throws \InvalidArgumentException if <tt>$length</tt> is a non-positive number (PostgreSQL forbids it) |
|
31 | - */ |
|
32 | - public static function fromString($bits, $maxLength = null) |
|
33 | - { |
|
34 | - $bits = (string)$bits; |
|
23 | + /** |
|
24 | + * @param string $bits the bit string, i.e., a string of 1's and 0's |
|
25 | + * @param int|null $maxLength maximal length of the bit string in bits; |
|
26 | + * <tt>null</tt> for no limit; |
|
27 | + * if less than <tt>strlen($bits)</tt>, the bits get truncated on the right and a warning |
|
28 | + * is issued |
|
29 | + * @return VarBitString |
|
30 | + * @throws \InvalidArgumentException if <tt>$length</tt> is a non-positive number (PostgreSQL forbids it) |
|
31 | + */ |
|
32 | + public static function fromString($bits, $maxLength = null) |
|
33 | + { |
|
34 | + $bits = (string)$bits; |
|
35 | 35 | |
36 | - if ($maxLength === null) { |
|
37 | - return new VarBitString($bits, null); |
|
38 | - } |
|
39 | - elseif ($maxLength <= 0) { |
|
40 | - throw new \InvalidArgumentException('maxLength is non-positive'); |
|
41 | - } |
|
42 | - elseif ($maxLength < strlen($bits)) { |
|
43 | - trigger_error("Bit string truncated to the length of $maxLength", E_USER_WARNING); |
|
44 | - return new VarBitString(substr($bits, 0, $maxLength), $maxLength); |
|
45 | - } |
|
46 | - else { |
|
47 | - return new VarBitString($bits, $maxLength); |
|
48 | - } |
|
49 | - } |
|
36 | + if ($maxLength === null) { |
|
37 | + return new VarBitString($bits, null); |
|
38 | + } |
|
39 | + elseif ($maxLength <= 0) { |
|
40 | + throw new \InvalidArgumentException('maxLength is non-positive'); |
|
41 | + } |
|
42 | + elseif ($maxLength < strlen($bits)) { |
|
43 | + trigger_error("Bit string truncated to the length of $maxLength", E_USER_WARNING); |
|
44 | + return new VarBitString(substr($bits, 0, $maxLength), $maxLength); |
|
45 | + } |
|
46 | + else { |
|
47 | + return new VarBitString($bits, $maxLength); |
|
48 | + } |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param string $bits |
|
53 | - * @param int|null $maxLength |
|
54 | - */ |
|
55 | - protected function __construct($bits, $maxLength) |
|
56 | - { |
|
57 | - parent::__construct($bits); |
|
51 | + /** |
|
52 | + * @param string $bits |
|
53 | + * @param int|null $maxLength |
|
54 | + */ |
|
55 | + protected function __construct($bits, $maxLength) |
|
56 | + { |
|
57 | + parent::__construct($bits); |
|
58 | 58 | |
59 | - if ($maxLength !== null && $maxLength < 0) { // NOTE: zero max. length permitted for substr() to calculate correctly |
|
60 | - throw new \InvalidArgumentException('maxLength is negative'); |
|
61 | - } |
|
62 | - $this->maxLength = $maxLength; |
|
63 | - } |
|
59 | + if ($maxLength !== null && $maxLength < 0) { // NOTE: zero max. length permitted for substr() to calculate correctly |
|
60 | + throw new \InvalidArgumentException('maxLength is negative'); |
|
61 | + } |
|
62 | + $this->maxLength = $maxLength; |
|
63 | + } |
|
64 | 64 | |
65 | - public function equals($other) |
|
66 | - { |
|
67 | - $parRes = parent::equals($other); |
|
68 | - if (!$parRes) { |
|
69 | - return $parRes; |
|
70 | - } |
|
71 | - /** @var VarBitString $other */ |
|
72 | - return ($this->maxLength == $other->maxLength); |
|
73 | - } |
|
65 | + public function equals($other) |
|
66 | + { |
|
67 | + $parRes = parent::equals($other); |
|
68 | + if (!$parRes) { |
|
69 | + return $parRes; |
|
70 | + } |
|
71 | + /** @var VarBitString $other */ |
|
72 | + return ($this->maxLength == $other->maxLength); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @return int|null maximal length this bit string might have carried, or <tt>null</tt> for unlimited length |
|
77 | - */ |
|
78 | - public function getMaxLength() |
|
79 | - { |
|
80 | - return $this->maxLength; |
|
81 | - } |
|
75 | + /** |
|
76 | + * @return int|null maximal length this bit string might have carried, or <tt>null</tt> for unlimited length |
|
77 | + */ |
|
78 | + public function getMaxLength() |
|
79 | + { |
|
80 | + return $this->maxLength; |
|
81 | + } |
|
82 | 82 | } |
@@ -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', |
@@ -44,7 +44,7 @@ |
||
44 | 44 | self::GIGABYTE => [self::BYTE, 1024 * 1024 * 1024], |
45 | 45 | self::TERABYTE => [self::BYTE, 1024 * 1024 * 1024 * 1024], |
46 | 46 | |
47 | - self::MILLISECOND => [self::SECOND, 1/1000], |
|
47 | + self::MILLISECOND => [self::SECOND, 1 / 1000], |
|
48 | 48 | self::SECOND => [self::SECOND, 1], |
49 | 49 | self::MINUTE => [self::SECOND, 60], |
50 | 50 | self::HOUR => [self::SECOND, 60 * 60], |
@@ -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 | } |