Skip to content

Refactor IO #80

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

Closed
wants to merge 2 commits into from
Closed

Refactor IO #80

wants to merge 2 commits into from

Conversation

AydinHassan
Copy link
Member

@AydinHassan AydinHassan commented Apr 16, 2018

Refactor the input + output to their own stream based handlers - allows to use with virtual terminals and in non-blocking apps. Inspired by https://www.reddit.com/r/PHP/comments/59qpk8/phpschoolclimenu_200/d9asoli/ and code from https://github.com/amphp/byte-stream.

It improves the tests by allowing phpunit output buffering to replaced by our own implementation. This is also helping me with the input tests a lot.

Only thing I'm not sure of is whether the terminal object should be the point of writing eg $terminal->getOutput()->write('string'); Also not sure if I care - we can change it later if we want, I am happy to hear suggestions though.

@AydinHassan AydinHassan requested a review from mikeymike April 16, 2018 19:30
@codecov-io
Copy link

codecov-io commented Apr 16, 2018

Codecov Report

Merging #80 into master will decrease coverage by 0.37%.
The diff coverage is 69.23%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master      #80      +/-   ##
============================================
- Coverage     89.13%   88.75%   -0.38%     
- Complexity      246      267      +21     
============================================
  Files            18       21       +3     
  Lines           690      729      +39     
============================================
+ Hits            615      647      +32     
- Misses           75       82       +7
Impacted Files Coverage Δ Complexity Δ
src/IO/ResourceOutputStream.php 100% <100%> (ø) 7 <7> (?)
src/Terminal/TerminalFactory.php 100% <100%> (ø) 1 <0> (ø) ⬇️
src/CliMenu.php 89.26% <100%> (ø) 57 <0> (ø) ⬇️
src/IO/ResourceInputStream.php 100% <100%> (ø) 7 <7> (?)
src/Dialogue/Dialogue.php 90% <100%> (ø) 8 <0> (ø) ⬇️
src/Terminal/UnixTerminal.php 13.33% <17.64%> (+2.01%) 34 <6> (+3) ⬆️
src/IO/BufferedOutput.php 77.77% <77.77%> (ø) 4 <4> (?)

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 6270594...8e04ad1. Read the comment docs.

Copy link
Member

@mikeymike mikeymike left a comment

Choose a reason for hiding this comment

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

Looks good, the only thing I'd say is I agree with the $this->terminal->getOutput()->write($row) not being "right" ... reaching through feels wrong, I think it's probably cleaner just to have methods on the terminal class and remove the getOutput ?

Aside I was thinking that it kind of makes sense to properly pull this into php-school/terminal and use that in our packages instead, what do you think ?


public function __toString() : string
{
return $this->fetch();
Copy link
Member

Choose a reason for hiding this comment

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

looks like this would always return an empty string ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope - it will return whatever has been written so far and clean the buffer

Copy link
Member

Choose a reason for hiding this comment

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

oh my dayz... obvs .. I must have been tired not to see that 😂


public function __construct($stream = null)
{
if ($stream === null) {
Copy link
Member

Choose a reason for hiding this comment

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

maybe I'm being silly, can't you have STDIN as the default value?

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's give it a whirl

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed we can!

@AydinHassan
Copy link
Member Author

Makes sense @mikeymike I'll have a think about it - but it sees strange to duplicate the write method from the output stream on to the terminal - and should we also do the same with reading? Gonna take a look at some other packages

@AydinHassan
Copy link
Member Author

Moved to php-school/terminal#1

@AydinHassan AydinHassan deleted the refactor-io branch April 19, 2018 11:45
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.

3 participants