Skip to content

Commit

Permalink
Move initial data validation out of generator parser
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Dec 18, 2017
1 parent 82e439c commit 67b8213
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/Internal/ArrayParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class ArrayParser {
* @throws \Amp\Postgres\ParseException
*/
public function parse(string $data, callable $cast = null, string $delimiter = ','): array {
$data = \trim($data);

if ($data[0] !== '{' || \substr($data, -1) !== '}') {
throw new ParseException("Missing opening or closing brackets");
}

$parser = $this->parser($data, $cast, $delimiter);
$data = \iterator_to_array($parser);

Expand All @@ -26,12 +32,6 @@ public function parse(string $data, callable $cast = null, string $delimiter = '
}

private function parser(string $data, callable $cast = null, string $delimiter = ','): \Generator {
$data = \trim($data);

if ($data[0] !== '{' || \substr($data, -1) !== '}') {
throw new ParseException("Missing opening or closing brackets");
}

$data = \ltrim(\substr($data, 1));

do {
Expand Down

0 comments on commit 67b8213

Please sign in to comment.