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

Update docblock for Process::$pipes #80

Merged
merged 1 commit into from Nov 27, 2020
Merged

Update docblock for Process::$pipes #80

merged 1 commit into from Nov 27, 2020

Conversation

gdejong
Copy link
Contributor

@gdejong gdejong commented Nov 26, 2020

Found this when running Psalm in a project of mine that is using reactphp/child-process.

Possibly undesired iteration over regular object React\Stream\ReadableStreamInterface

for the code:

foreach ($this->process->pipes as $pipe) {

The docblock now better reflects the fact that $pipes is an array of either ReadableStreamInterface or WritableStreamInterface.

Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

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

@gdejong Thanks for spotting, the existing definition is indeed incorrect! 👍

It looks like this should be array<ReadableStreamInterface|WritableStreamInterface> instead of ReadableStreamInterface[]|WritableStreamInterface[].

This subtle different means it can contain a mix of both readable and writable streams, instead of an array of either just readable or just writable streams.

@clue clue added this to the v0.6.2 milestone Nov 26, 2020
@gdejong
Copy link
Contributor Author

gdejong commented Nov 26, 2020

Good catch! I'll update the PR!

Found this when running Psalm in a project of mine that is using reactphp/child-process.
```
Possibly undesired iteration over regular object React\Stream\ReadableStreamInterface
```
for the code:
```
foreach ($this->process->pipes as $pipe) {
```

The docblock now better reflects the fact that `$pipes` is an array of either `ReadableStreamInterface` or `WritableStreamInterface`.
@gdejong
Copy link
Contributor Author

gdejong commented Nov 26, 2020

Updated (amended to the same commit).

Unfortunately the current version of PHPStorm (2020.2) does not understand this syntax yet. Psalm support should be available in 2020.3 though.

For now it means that code like \React\ChildProcess\Process::close has no autocomplete.
image

Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

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

@gdejong Thanks for the update, the changes LGTM! :shipit:

If static analysis and IDE autocompletion is an issue, you can always add an additional assert($pipe instanceof ReadableStreamInterface || $pipe instanceof WritableStreamInterface) in front of the respective method call.

Copy link
Member

@WyriHaximus WyriHaximus left a comment

Choose a reason for hiding this comment

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

Nice catch, thank you 👍

@WyriHaximus WyriHaximus merged commit 437e00c into reactphp:master Nov 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants