code refactoring to be PSR compliant and removing trigger_error in favor of throwing exception