From 446f0940f2a5abbd18991a0942f98e8a1f2349cd Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sun, 6 Apr 2014 02:03:55 -0700 Subject: [PATCH] CRM-14370 - Fix incorrect type reference and other warnings. This had caused a regressino in api_v3_OptionGroupTest::testGetOptionCreateFailOnDuplicate --- Civi/API/Kernel.php | 23 ++++++++++++++++------- api/api.php | 2 +- api/v3/utils.php | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Civi/API/Kernel.php b/Civi/API/Kernel.php index d9efbf697e..09076e554d 100644 --- a/Civi/API/Kernel.php +++ b/Civi/API/Kernel.php @@ -121,11 +121,12 @@ class Kernel { /** * Determine which, if any, service will execute the API request. * - * @param $apiRequest + * @param array $apiRequest + * @throws Exception\NotImplementedException * @return array - * @throws \API_Exception */ public function resolve($apiRequest) { + /** @var ResolveEvent $resolveEvent */ $resolveEvent = $this->dispatcher->dispatch(Events::RESOLVE, new ResolveEvent($apiRequest)); $apiRequest = $resolveEvent->getApiRequest(); if (!$resolveEvent->getApiProvider()) { @@ -139,9 +140,10 @@ class Kernel { * * @param ProviderInterface $apiProvider * @param array $apiRequest - * @throws \API_Exception + * @throws Exception\UnauthorizedException */ public function authorize($apiProvider, $apiRequest) { + /** @var AuthorizeEvent $event */ $event = $this->dispatcher->dispatch(Events::AUTHORIZE, new AuthorizeEvent($apiProvider, $apiRequest)); if (!$event->isAuthorized()) { throw new \Civi\API\Exception\UnauthorizedException("Authorization failed"); @@ -156,6 +158,7 @@ class Kernel { * @return mixed */ public function prepare($apiProvider, $apiRequest) { + /** @var PrepareEvent $event */ $event = $this->dispatcher->dispatch(Events::PREPARE, new PrepareEvent($apiProvider, $apiRequest)); return $event->getApiRequest(); } @@ -169,6 +172,7 @@ class Kernel { * @return mixed */ public function respond($apiProvider, $apiRequest, $result) { + /** @var RespondEvent $event */ $event = $this->dispatcher->dispatch(Events::RESPOND, new RespondEvent($apiProvider, $apiRequest, $result)); return $event->getResponse(); } @@ -181,6 +185,7 @@ class Kernel { // Question: Would it better to eliminate $this->apiProviders and just use $this->dispatcher? $entityNames = array(); foreach ($this->getApiProviders() as $provider) { + /** @var ProviderInterface $provider */ $entityNames = array_merge($entityNames, $provider->getEntityNames($version)); } $entityNames = array_unique($entityNames); @@ -197,6 +202,7 @@ class Kernel { // Question: Would it better to eliminate $this->apiProviders and just use $this->dispatcher? $actionNames = array(); foreach ($this->getApiProviders() as $provider) { + /** @var ProviderInterface $provider */ $actionNames = array_merge($actionNames, $provider->getActionNames($version, $entity)); } $actionNames = array_unique($actionNames); @@ -266,11 +272,12 @@ class Kernel { /** * - * @param $data + * @param string $msg * @param array $data - * @param object $apiRequest DAO / BAO object to be freed here + * @param array $apiRequest + * @param mixed $code doesn't appear to be used * - * @throws API_Exception + * @throws \API_Exception * @return array */ function createError($msg, $data, $apiRequest, $code = NULL) { @@ -279,7 +286,7 @@ class Kernel { try { $fields = _civicrm_api3_api_getfields($apiRequest); _civicrm_api3_validate_fields($apiRequest['entity'], $apiRequest['action'], $apiRequest['params'], $fields, TRUE); - } catch (Exception $e) { + } catch (\Exception $e) { $msg = $e->getMessage(); } } @@ -295,6 +302,8 @@ class Kernel { } /** + * @param array $apiRequest + * @param array $result * @return mixed */ public function formatResult($apiRequest, $result) { diff --git a/api/api.php b/api/api.php index f3b2be9d37..390dda1f63 100644 --- a/api/api.php +++ b/api/api.php @@ -54,7 +54,7 @@ function civicrm_api3($entity, $action, $params = array()) { * @todo other output modifiers include contact_type * * @param array $apiRequest - * @return getfields output + * @return array getfields output */ function _civicrm_api3_api_getfields(&$apiRequest) { if (strtolower($apiRequest['action'] == 'getfields')) { diff --git a/api/v3/utils.php b/api/v3/utils.php index cd7fb34b5b..3fde44b5ae 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -1285,7 +1285,7 @@ function _civicrm_api3_validate_uniquekey(&$params, &$fieldName, &$fieldInfo) { // an entry already exists for this unique field if ($existing['count'] == 1) { // question - could this ever be a security issue? - throw new Exception("Field: `$fieldName` must be unique. An conflicting entity already exists - id: " . $existing['id']); + throw new API_Exception("Field: `$fieldName` must be unique. An conflicting entity already exists - id: " . $existing['id']); } } -- 2.25.1