Skip to content

Commit 28a92b0

Browse files
committed
fix recursive function call
1 parent 379598e commit 28a92b0

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

app/controllers/api/Statements.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,29 @@ public function void() {
8383
}
8484

8585
private function convertDte($value) {
86-
if(isset($value['$dte']))
87-
return new \MongoDate(strtotime($value['$dte']));
88-
89-
else if(is_array($value))
90-
return array_map([$this, __FUNCTION__], $value); // recursively apply this function to whole pipeline
86+
if(is_array($value)) {
87+
if(isset($value['$dte'])) {
88+
$date = $value['$dte'];
89+
$parsedDate = strtotime($date);
90+
if($parsedDate) return new \MongoDate($parsedDate);
91+
else throw new Exceptions\Exception("`$date` is not a valid date.");
92+
}
93+
else
94+
return array_map([$this, __FUNCTION__], $value); // recursively apply this function to whole pipeline
95+
}
9196

92-
else return $value;
97+
return $value;
9398
}
9499

95100
private function convertOid($value) {
96-
if(isset($value['$oid']))
97-
return new \MongoId($value['$oid']);
98-
99-
else if(is_array($value))
100-
return array_map([$this, __FUNCTION__], $value); // recursively apply this function to whole pipeline
101+
if(is_array($value)) {
102+
if(isset($value['$oid']))
103+
return new \MongoId($value['$oid']);
104+
else
105+
return array_map([$this, __FUNCTION__], $value); // recursively apply this function to whole pipeline
106+
}
101107

102-
else return $value;
108+
return $value;
103109
}
104110

105111
private function getPipeline() {

0 commit comments

Comments
 (0)