Fix PHPCS errors/warnings from Jenkins

Hi,

Here, I fixed some PHPCS errors reported by Jenkins.
I also reduced number of nested levels in some functions. I tried to do this as safe as possible.

If these modifications are ok for everyone, I'll merge it.

Thanks.
(This could be quite delicate, that's why I'm using a pull request...)