Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP8 deprecated #2

Open
nono303 opened this issue Dec 30, 2021 · 0 comments · May be fixed by #4
Open

PHP8 deprecated #2

nono303 opened this issue Dec 30, 2021 · 0 comments · May be fixed by #4

Comments

@nono303
Copy link

nono303 commented Dec 30, 2021

Hi @klkvsk!
Using json-decode-stream with PHP8, i have some deprecated warning about return type.

Deprecated: Return type of JsonDecodeStream\Internal\SourceBuffer::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in \composer\vendor\klkvsk\json-decode-stream\src\Internal\SourceBuffer.php on line 37
Deprecated: Return type of JsonDecodeStream\Internal\SourceBuffer::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in \composer\vendor\klkvsk\json-decode-stream\src\Internal\SourceBuffer.php on line 46
Deprecated: Return type of JsonDecodeStream\Internal\SourceBuffer::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in \composer\vendor\klkvsk\json-decode-stream\src\Internal\SourceBuffer.php on line 57
Deprecated: Return type of JsonDecodeStream\Internal\SourceBuffer::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in \composer\vendor\klkvsk\json-decode-stream\src\Internal\SourceBuffer.php on line 62
Deprecated: Return type of JsonDecodeStream\Internal\SourceBuffer::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in \composer\vendor\klkvsk\json-decode-stream\src\Internal\SourceBuffer.php on line 68
Deprecated: Return type of JsonDecodeStream\Tokenizer::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in \composer\vendor\klkvsk\json-decode-stream\src\Tokenizer.php on line 39

Here is my patch to correct them (for my usecase only)
not sure for /src/Tokenizer.php l.39 that's the best way to do...

diff --git a/src/Internal/SourceBuffer.php b/src/Internal/SourceBuffer.php
index bad5a98..60d2428 100644
--- a/src/Internal/SourceBuffer.php
+++ b/src/Internal/SourceBuffer.php
@@ -34,7 +34,7 @@ class SourceBuffer implements Iterator
         }
     }
 
-    public function current()
+    public function current(): mixed
     {
         if (!$this->valid()) {
             return null;
@@ -43,7 +43,7 @@ class SourceBuffer implements Iterator
         return $this->buffer[$this->bufferPosition];
     }
 
-    public function next()
+    public function next(): void
     {
         $this->bufferPosition++;
         if ($this->bufferPosition == min($this->bufferMaxSize, $this->bufferSize)) {
@@ -54,18 +54,18 @@ class SourceBuffer implements Iterator
         }
     }
 
-    public function key()
+    public function key(): mixed
     {
         return $this->sourcePosition;
     }
 
-    public function valid()
+    public function valid(): bool
     {
         return $this->buffer !== null
             && $this->bufferPosition < $this->bufferSize;
     }
 
-    public function rewind()
+    public function rewind(): void
     {
         $this->source->rewind();
         $this->nextBuffer();
diff --git a/src/Tokenizer.php b/src/Tokenizer.php
index ea2543b..f7614a2 100644
--- a/src/Tokenizer.php
+++ b/src/Tokenizer.php
@@ -36,7 +36,7 @@ class Tokenizer implements IteratorAggregate
      * @psalm-return \Traversable<Token>
      * @throws TokenizerException
      */
-    public function getIterator()
+    public function getIterator(): Generator
     {
         return $this->tokens();
     }
@ChadSikorra ChadSikorra linked a pull request Jun 19, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant