General code cleanup as reported by the PHPStorm static code
analysis. I hope it's not a problem that I made a lot of very
different (but all very tiny) changes in a single patch. If you
want to merge this but you think it's better to split it into
several patches first, please tell me.
Change-Id: I2e2c4bb47f8d20e038d28e236e2ff813b30504af
Detects changes to different parts of the document as independent from each
other. Refactored parser passes all tests the previous parser passed plus
a number of new tests which fail with the original parser.
Change-Id: I65fdc6d9f922cbe9ff684332945def3776c70d30