Skip to content

Fix NodeList::getFieldSelection() return type#650

Merged
simPod merged 3 commits intowebonyx:masterfrom
shmax:fix-resolve-info-get-field-selection
Apr 25, 2020
Merged

Fix NodeList::getFieldSelection() return type#650
simPod merged 3 commits intowebonyx:masterfrom
shmax:fix-resolve-info-get-field-selection

Conversation

@shmax
Copy link
Copy Markdown
Contributor

@shmax shmax commented Apr 24, 2020

Correcting the return type of ResolveInfo.getFieldSelection.

Not a big deal, but it was causing stanning errors in my app code.

Also fixed one of the new contravariant errors that was introduced in a recent version of PHPStan.

Comment thread src/Language/AST/NodeList.php Outdated
/**
* @param int|string $offset
* @param Node|mixed[] $value
* @param int|string|null $offset
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I believe $offset cannot be null

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also the case for previous PRs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah, that's ArrayObject... mkay. Therefore, I think we have a bug here https://github.com/webonyx/graphql-php/pull/650/files#diff-d22cf662ac36edb6150cfc3e80fdfbc0R107 as null can't be used for array index directly.

Though I would solve it in separate PR, you have this change in all your recent PRs. Does phpstan complain about it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

as null can't be used for array index directly.

It can.
According to the docs:
https://www.php.net/manual/en/language.types.array.php

Null will be cast to the empty string, i.e. the key null will actually be stored under "".

It's weird, but I don't think we need to worry about it, now.

you have this change in all your recent PRs. Does phpstan complain about it?

Well, yes. If you prefer I could add the warning to the baseline file and leave the annotation as-is.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Null will be cast to the empty string, i.e. the key null will actually be stored under "".

Umm, black magic...

Any idea why it did not complain here? a2780a0 It's recent commit, the build passed though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure. I'll see if I can figure it out...

Copy link
Copy Markdown
Contributor Author

@shmax shmax Apr 25, 2020

Choose a reason for hiding this comment

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

In my other PRs I lock phpstan to 0.12.18 (I had to update to get a fix for baseline file generation), so that's what I still have on local. In
a2780a0 you're still locked to 0.12.11. Tell you what, since it's bothering you, I'll go ahead and remove this bit from this PR so we can move forward, and we can deal with it some other time.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah cool. This should be done in PR related to phpstan upgrade. That's why I've locked phpstan to concrete version to prevent irrelevant build breakage.

Copy link
Copy Markdown
Collaborator

@simPod simPod left a comment

Choose a reason for hiding this comment

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

LGTM, I think I can go ahead and merge such small PR without @vladar

@simPod simPod changed the title fix return type Fix NodeList::getFieldSelection() return type Apr 25, 2020
@simPod simPod merged commit 7412bf6 into webonyx:master Apr 25, 2020
@shmax shmax deleted the fix-resolve-info-get-field-selection branch April 25, 2020 16:46
@shmax
Copy link
Copy Markdown
Contributor Author

shmax commented Apr 25, 2020

Thanks much!

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