small style changes to comply with PSR2

After editing code in this repo I ran phpcs with standard PSR2 and found some errors and warnings. I changed the code accordingly. I only changed files in the lib directory, please let me know if you want to comply to PSR2. If appreciated I could also go through the tests directory and make it comply to PSR2 too.

For reference: 
https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md#1-overview
> Opening parentheses for control structures MUST NOT have a space after them, and closing parentheses for control structures MUST NOT have a space before.
this should be reverted to follow the Doctrine coding standards (this is a deviation from PSR-2, we require spaces around ``!``)