From 95da3c7bd400c9c6edbf37a0dc6e66afc28a7944 Mon Sep 17 00:00:00 2001 From: Nikita Dezzpil Orlov Date: Fri, 22 May 2020 00:28:15 +0300 Subject: [PATCH 1/2] fixes around ArrayIterator for PHP7.4 --- src/LTDBeget/stringstream/StringStream.php | 36 ++++++++++++++++------ 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/LTDBeget/stringstream/StringStream.php b/src/LTDBeget/stringstream/StringStream.php index addc4c2..7aa1061 100644 --- a/src/LTDBeget/stringstream/StringStream.php +++ b/src/LTDBeget/stringstream/StringStream.php @@ -30,11 +30,12 @@ public function __construct(string $string) /** * Current char of stream - * @return string + * @return string|null */ - public function current() : string + public function current() : ?string { - return current($this->stream); + //return current($this->stream); + return $this->stream->current(); } /** @@ -62,7 +63,7 @@ public function currentAscii() : AsciiChar */ public function position() : int { - return key($this->stream); + return $this->stream->key(); } /** @@ -71,7 +72,14 @@ public function position() : int public function next() { $this->pointerAtStart = false; - $this->pointerAtEnd = next($this->stream) === false; + + //var_dump($this->stream->key() . " - " . $this->stream->count()); + if ($this->stream->key() === $this->stream->count() - 1) { + $this->pointerAtEnd = true; + } else { + $this->pointerAtEnd = false; + $this->stream->next(); + } } /** @@ -80,7 +88,15 @@ public function next() public function previous() { $this->pointerAtEnd = false; - $this->pointerAtStart = prev($this->stream) === false; + // $this->pointerAtStart = prev($this->stream) === false; + + $this->pointerAtStart = false; + if ($this->stream->key() == 0) { + $this->pointerAtStart = true; + } else { + $prevPos = $this->stream->key() - 1; + $this->stream->seek($prevPos); + } } /** @@ -88,7 +104,8 @@ public function previous() */ public function start() { - reset($this->stream); + //reset($this->stream); + $this->stream->rewind(); } /** @@ -105,7 +122,8 @@ public function isStart() : bool */ public function end() { - end($this->stream); + //end($this->stream); + $this->stream->seek($this->stream->count() - 1); } /** @@ -169,7 +187,7 @@ private function makeIterator(string $string) : ArrayIterator } /** - * @var array + * @var ArrayIterator */ private $stream; From 073823ad03ea65496a24098a60ef621a88f1c10d Mon Sep 17 00:00:00 2001 From: Nikita Dezzpil Orlov Date: Fri, 22 May 2020 01:19:25 +0300 Subject: [PATCH 2/2] remove obsolete comments, remove nullable return declaration --- src/LTDBeget/stringstream/StringStream.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/LTDBeget/stringstream/StringStream.php b/src/LTDBeget/stringstream/StringStream.php index 7aa1061..872e55b 100644 --- a/src/LTDBeget/stringstream/StringStream.php +++ b/src/LTDBeget/stringstream/StringStream.php @@ -32,9 +32,8 @@ public function __construct(string $string) * Current char of stream * @return string|null */ - public function current() : ?string + public function current() { - //return current($this->stream); return $this->stream->current(); } @@ -72,8 +71,6 @@ public function position() : int public function next() { $this->pointerAtStart = false; - - //var_dump($this->stream->key() . " - " . $this->stream->count()); if ($this->stream->key() === $this->stream->count() - 1) { $this->pointerAtEnd = true; } else { @@ -88,8 +85,6 @@ public function next() public function previous() { $this->pointerAtEnd = false; - // $this->pointerAtStart = prev($this->stream) === false; - $this->pointerAtStart = false; if ($this->stream->key() == 0) { $this->pointerAtStart = true; @@ -104,7 +99,6 @@ public function previous() */ public function start() { - //reset($this->stream); $this->stream->rewind(); } @@ -122,7 +116,6 @@ public function isStart() : bool */ public function end() { - //end($this->stream); $this->stream->seek($this->stream->count() - 1); }