improve readability of code

* coding style fixes
* some PHPStorm code inspection fixes
* few method extractions
* removed unused methods
* whitespace fixes

 all as part of our code cleanup strategy and to make code better readable.
Do you follow a rule? Because IMHO, or the query is considered complexed and there is a new line before each keyword (FROM, JOIN, WHERE) or is simple and all can be put in one line.