From 67b821343f5b15d23f4cbb024cd01a0dddf9369f Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Mon, 18 Dec 2017 00:17:55 -0600 Subject: [PATCH] Move initial data validation out of generator parser --- lib/Internal/ArrayParser.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Internal/ArrayParser.php b/lib/Internal/ArrayParser.php index f095660..b37cb88 100644 --- a/lib/Internal/ArrayParser.php +++ b/lib/Internal/ArrayParser.php @@ -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); @@ -26,12 +32,6 @@ class ArrayParser { } 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 {