From e5b955ecc86b91cd9a82ab9d6452a8881c069059 Mon Sep 17 00:00:00 2001 From: spawnia Date: Thu, 9 May 2019 17:04:17 +0200 Subject: [PATCH 1/2] Use array_keys for iterating over NodeList --- src/Language/AST/NodeList.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Language/AST/NodeList.php b/src/Language/AST/NodeList.php index cede5a4..c91fbcf 100644 --- a/src/Language/AST/NodeList.php +++ b/src/Language/AST/NodeList.php @@ -114,9 +114,8 @@ class NodeList implements ArrayAccess, IteratorAggregate, Countable */ public function getIterator() { - $count = count($this->nodes); - for ($i = 0; $i < $count; $i++) { - yield $this->offsetGet($i); + foreach (array_keys($this->nodes) as $key) { + yield $this->offsetGet($key); } } From 019ed04a5160aa20b92b96ea83502ae794458976 Mon Sep 17 00:00:00 2001 From: Benedikt Franke Date: Thu, 9 May 2019 19:33:37 +0200 Subject: [PATCH 2/2] Update src/Language/AST/NodeList.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Šimon Podlipský --- src/Language/AST/NodeList.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Language/AST/NodeList.php b/src/Language/AST/NodeList.php index c91fbcf..648f68a 100644 --- a/src/Language/AST/NodeList.php +++ b/src/Language/AST/NodeList.php @@ -114,7 +114,7 @@ class NodeList implements ArrayAccess, IteratorAggregate, Countable */ public function getIterator() { - foreach (array_keys($this->nodes) as $key) { + foreach ($this->nodes as $key => $_) { yield $this->offsetGet($key); } }