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.
I don't think 2 return statements increase the readabillity. A contrario. I suggest $value = stripslashes($value); instead if you do not want to keep the ternary syntax.