GravityPDF / querypath

A fork of QueryPath: a PHP library for HTML(5)/XML querying (CSS 4 or XPath) and processing (like jQuery) with PHP8.3 support
Other
21 stars 2 forks source link

Set return type in QueryPathIterator::current() #28

Closed Berdir closed 1 year ago

Berdir commented 1 year ago

Fixes #27

jakejackson1 commented 1 year ago

Hi @Berdir, thanks for the contribution!

The PHP docs show that the method current() should have a type of mixed. Where did Traversable come from?

Looking at the docs for Iterator, it seems like current() should have #[ReturnTypeWillChange] added to resolve the deprecation notice I imagine you are getting in PHP8.1. Would that resolve the problem for you?

Berdir commented 1 year ago

Yeah, I don't know what I was thinking, this makes no sense :) It didn't complain about it, strangely enough.

The annotation works, but I suppose you could also just set it to mixed. the annotation afaik is mostly for cases where you provide your own API/interface/base class and don't want to introduce a BC break (yet).

Berdir commented 1 year ago

I updated it to mixed now.

jakejackson1 commented 1 year ago

Yeah, I don't know what I was thinking, this makes no sense :) It didn't complain about it, strangely enough.

The annotation works, but I suppose you could also just set it to mixed. the annotation afaik is mostly for cases where you provide your own API/interface/base class and don't want to introduce a BC break (yet).

Since mixed wasn't added as a valid return type until PHP8.0, the annotation will be the best approach for now. I've also merged an update to the automated test suite, so deprecation notices will at least show in the logs.

jakejackson1 commented 1 year ago

@Berdir also, could you create a quick unit test for QueryPathIterator::current() to accompany this PR? Drop it in a new file at tests/QueryPath/QueryPathIteratorTest.php 👍

Thanks!

jakejackson1 commented 1 year ago

@Berdir closing in favour of https://github.com/GravityPDF/querypath/pull/32. Thanks again for your contribution!