violet-php / streaming-json-encoder

PHP library for iteratively encoding large JSON documents piece by piece
http://violet.riimu.net
MIT License
314 stars 16 forks source link

Fix warnings on PHP 8.1 #4

Closed jtojnar closed 2 years ago

jtojnar commented 2 years ago

With, PHP 8.1 lack of a return type hint for a method of a child class, whose parent has return type hint is considered mismatch.

https://php.watch/versions/8.1/internal-method-return-types#no-return-type

Since standard classes and interfaces started adding typehings, errors like the following are produced:

PHP Deprecated: Return type of Violet\StreamingJsonEncoder\AbstractJsonEncoder::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice

void type is only available since PHP 7.1 and mixed type requires PHP 8.0:

https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.void https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.mixed

To preserve compatibility with PHP < 8.0, we need to add the attribute.

codecov-commenter commented 2 years ago

Codecov Report

Merging #4 (21fdb9f) into master (31661f6) will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##              master        #4   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity       114       114           
===========================================
  Files              4         4           
  Lines            296       296           
===========================================
  Hits             296       296           
Impacted Files Coverage Δ
src/AbstractJsonEncoder.php 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 31661f6...21fdb9f. Read the comment docs.

Riimu commented 2 years ago

Thanks, I merged this via #6, since I needed to rebase it.