From 4786693a927301c93ade8dfc6cb2c0c4d78f88cd Mon Sep 17 00:00:00 2001 From: Pablo Gumilla Date: Tue, 3 Jun 2014 10:49:51 -0300 Subject: [PATCH] Remove Exceptions Exceptions terminate execution, and sometimes this is not the desired behavior for the main application. If args are not valid, throw error message and continue main application execution --- src/indeed.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/indeed.php b/src/indeed.php index 5711f33..d16ca7e 100644 --- a/src/indeed.php +++ b/src/indeed.php @@ -15,11 +15,20 @@ public function __construct($publisher, $version = "2"){ } public function search($args){ - return $this->process_request(self::API_SEARCH_ENDPOINT, $this->validate_args(self::$API_SEARCH_REQUIRED, $args)); + $valid_args = $this->validate_args(self::$API_SEARCH_REQUIRED, $args); + if (!is_array($valid_args)) { + return $valid_args; + } + + return $this->process_request(self::API_SEARCH_ENDPOINT, $valid_args); } public function jobs($args){ $valid_args = $this->validate_args(self::$API_JOBS_REQUIRED, $args); + if (!is_array($valid_args)) { + return $valid_args; + } + $valid_args["jobkeys"] = implode(",", $valid_args['jobkeys']); return $this->process_request(self::API_JOBS_ENDPOINT, $valid_args); } @@ -49,13 +58,14 @@ private function validate_args($required_fields, $args){ } } if(!$has_one_required){ - throw new Exception(sprintf("You must provide one of the following %s", implode(",", $field))); + $error = sprintf("You must provide one of the following %s", implode(",", $field)); + return $error; } } elseif(!array_key_exists($field, $args)){ - throw new Exception("The field $field is required"); + return "The field $field is required"; } } return $args; } -} \ No newline at end of file +}