Skip to content

Conversation

@szepeviktor
Copy link
Contributor

@szepeviktor szepeviktor commented Oct 24, 2020

All things fixed, even broken greg.php 👍

@acobster Please help me in the last one:

 ------ -----------------------------------------------------------
  Line   src/api.php
 ------ -----------------------------------------------------------
  122    Cannot call method to_array() on array<int, Timber\Post>.
  127    Cannot call method to_array() on array<int, Timber\Post>.
 ------ -----------------------------------------------------------

@szepeviktor
Copy link
Contributor Author

szepeviktor commented Oct 24, 2020

BTW Tests were moved from test to tests - so CI may brake, please see the other PR #1

* Get the results for this EventQuery as a collection of zero or more Events
*
* @internal
* @return array
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@acobster Just put list<\Timber\Post> here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it means array<int, \Timber\Post>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know, but array<int, \Timber\Post> is not quite correct, is it? Wouldn't array<\Timber\Post> be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes.

@acobster
Copy link
Contributor

Unfortunately the return type for Timber::get_posts() is still annotated as array|bool|null, but should be \Timber\PostCollectionInterface|false. That will be addressed upstream in timber/timber#1863 relatively soon, so let's leave this open until then.

@szepeviktor
Copy link
Contributor Author

Okay!!

@szepeviktor
Copy link
Contributor Author

Cannot call method to_array() on array|true.

Still seems to be already an array thus not possible to call that method on it.

@acobster
Copy link
Contributor

acobster commented Oct 26, 2020

I think it's complaining because of the Timber type annotation array|bool|null. false and null are precluded by the ternary:

return $posts ? $posts->to_array() : [];

...but PHPStan still considers it possible it will return true. That's why we need to update Timber.

If posts are found, ::get_posts() returns a PostCollectionInterface which has a to_array() method.

@szepeviktor
Copy link
Contributor Author

I see!!

So /** @var \Timber\PostCollectionInterface|false $post */

@szepeviktor
Copy link
Contributor Author

Here is the Anti-Problem Laser Gun 🔫
https://twitter.com/szepeviktor/status/1324135927975940096

Now it is very easy to resolve these kind of problems.

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 this pull request may close these issues.

2 participants