Change code style to PSR-2

Reviewed the code and change coding style to PSR-2 (used PHP_CodeSniffer for validation) also fix some small issue related to not defined variable or missing function parameters.