fix #5428 only read the stream contents once
#5428 an attempt at a better fix
#5428 PSR compliant
#5428 use stream_filter_remove as there was a hint about it in the code. Also added unit test
Merge branch 'hotfix/5555'

Close #5555
Merge pull request #5570 from jeremyquinton/issue-5428-fix

fix #5428 only read the stream contents once
[#5570] CS and test fixes

- Braces, whitespace.
- Incorrect variable references in tests caused them to fail; fixing them makes
  them pass.
Merge branch 'hotfix/5570' into develop

Forward port #5570