Use interfaces as typehints where applicable.
Fix the tests.
Fix incorrect filesystem interface.
Merge pull request #6318 from franzliedke/contracts

[5.0] Use Contracts As Typehints