Skip to content

Commit 21532f0

Browse files
Wout Gevaerttransistive
authored andcommitted
Changes in date regexes and remove superfluous array_key_first check
1 parent 35e788c commit 21532f0

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/Formatter/Specialised/JoltHttpOGMTranslator.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function formatHttpResult(
8787
$allResults = [];
8888
/** @var stdClass $result */
8989
foreach ($body->results as $result) {
90+
9091
/** @var stdClass $header */
9192
$header = $result->header;
9293
/** @var list<string> $fields */
@@ -133,7 +134,7 @@ private function translateJoltType(?stdClass $value)
133134
*/
134135
private function translateDateTime(string $datetime)
135136
{
136-
if (preg_match('/^\d+-\d{2}-\d{2}$/', $datetime)) {
137+
if (preg_match('/^[\-−]?\d+-\d{2}-\d{2}$/u', $datetime)) {
137138
$date = DateTimeImmutable::createFromFormat('Y-m-d', $datetime);
138139

139140
return new Date((int) $date->diff(new DateTimeImmutable('@0'))->format('%a'));
@@ -145,7 +146,7 @@ private function translateDateTime(string $datetime)
145146
return new LocalTime($nanoseconds);
146147
}
147148

148-
if (preg_match('/^(\d{2}):(\d{2}):(\d{2})((\.)(\d+))?(?<zone>[\w\W])+$/', $datetime, $matches)) {
149+
if (preg_match('/^(\d{2}):(\d{2}):(\d{2})((\.)(\d+))?(?<zone>.+)$/', $datetime, $matches)) {
149150
$nanoseconds = $this->nanosecondsFromMatches($matches);
150151

151152
$offset = $this->offsetFromMatches($matches);
@@ -239,13 +240,11 @@ private function translateMap(stdClass $value): CypherMap
239240
function () use ($value) {
240241
/** @var stdClass|array|null $element */
241242
foreach ((array) $value as $key => $element) {
242-
// There is an odd case in the JOLT protocol when dealing with properties in a node. Lists appear not to receive a composite type label, which is why we have to handle them specifically here.
243+
// There is an odd case in the JOLT protocol when dealing with properties in a node.
244+
// Lists appear not to receive a composite type label,
245+
// which is why we have to handle them specifically here.
243246
if (is_array($element)) {
244-
if (array_key_first($element) === 0) {
245-
yield $key => new CypherList($element);
246-
} else {
247-
yield $key => new CypherMap($element);
248-
}
247+
yield $key => new CypherList($element);
249248
} else {
250249
yield $key => $this->translateJoltType($element);
251250
}

src/Formatter/SummarizedResultFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function formatHttpStats(stdClass $response, ConnectionInterface $connect
7575
if ($response->summary instanceof stdClass) {
7676
/** @var stdClass $stats */
7777
$stats = $response->summary->stats;
78-
} elseif (!isset($response->stats)) {
78+
} elseif (isset($response->stats)) {
7979
/** @var stdClass $stats */
8080
$stats = $response->stats;
8181
} else {

0 commit comments

Comments
 (0)