Merge pull request #4910 from colemanw/INFRA-132
[civicrm-core.git] / api / api.php
index 483069dde8577d855b5ea2e351b0780bed6f83dd..b88dc5b278f3dfa3b6efa74b9d4778c0e6781116 100644 (file)
@@ -41,23 +41,26 @@ function civicrm_api($entity, $action, $params, $extra = NULL) {
 function civicrm_api3($entity, $action, $params = array()) {
   $params['version'] = 3;
   $result = civicrm_api($entity, $action, $params);
-  if(is_array($result) && !empty($result['is_error'])){
+  if (is_array($result) && !empty($result['is_error'])) {
     throw new CiviCRM_API3_Exception($result['error_message'], CRM_Utils_Array::value('error_code', $result, 'undefined'), $result);
   }
   return $result;
 }
 
 /**
- * call getfields from api wrapper. This function ensures that settings that could alter
- * getfields output (e.g. action for all api & profile_id for profile api ) are consistently passed in.
+ * Call getfields from api wrapper. This function ensures that settings that
+ * could alter getfields output (e.g. action for all api & profile_id for
+ * profile api ) are consistently passed in.
  *
- * We check whether the api call is 'getfields' because if getfields is being called we return an empty array
- * as no alias swapping, validation or default filling is done on getfields & we want to avoid a loop
+ * We check whether the api call is 'getfields' because if getfields is
+ * being called we return an empty array as no alias swapping, validation or
+ * default filling is done on getfields & we want to avoid a loop
  *
  * @todo other output modifiers include contact_type
  *
  * @param array $apiRequest
- * @return array getfields output
+ * @return array
+ *   getfields output
  */
 function _civicrm_api3_api_getfields(&$apiRequest) {
   if (strtolower($apiRequest['action'] == 'getfields')) {
@@ -71,7 +74,7 @@ function _civicrm_api3_api_getfields(&$apiRequest) {
   }
   $getFieldsParams = array('action' => $apiRequest['action']);
   $entity = $apiRequest['entity'];
-  if($entity == 'profile' && array_key_exists('profile_id', $apiRequest['params'])) {
+  if ($entity == 'profile' && array_key_exists('profile_id', $apiRequest['params'])) {
     $getFieldsParams['profile_id'] = $apiRequest['params']['profile_id'];
   }
   $fields = civicrm_api3($entity, 'getfields', $getFieldsParams);
@@ -86,8 +89,9 @@ function _civicrm_api3_api_getfields(&$apiRequest) {
  *
  * @param $result
  *
- * @return boolean true if error, false otherwise
- * @static void
+ * @return boolean
+ *   true if error, false otherwise
+ * @static
  * @access public
  */
 function civicrm_error($result) {
@@ -111,10 +115,14 @@ function _civicrm_api_get_camel_name($entity) {
 /**
  * Swap out any $values vars - ie. the value after $value is swapped for the parent $result
  * 'activity_type_id' => '$value.testfield',
-   'tag_id'  => '$value.api.tag.create.id',
-    'tag1_id' => '$value.api.entity.create.0.id'
+ * 'tag_id'  => '$value.api.tag.create.id',
+ * 'tag1_id' => '$value.api.entity.create.0.id'
+ *
+ * @param array $params
+ * @param array $parentResult
+ * @param string $separator
  */
-function _civicrm_api_replace_variables($entity, $action, &$params, &$parentResult, $separator = '.') {
+function _civicrm_api_replace_variables(&$params, &$parentResult, $separator = '.') {
 
   foreach ($params as $field => $value) {
 
@@ -153,10 +161,12 @@ function _civicrm_api_replace_variables($entity, $action, &$params, &$parentResu
  * Convert possibly camel name to underscore separated entity name
  *
  * @param string $entity
- *   Entity name in various formats e.g. Contribution, contribution, OptionValue, option_value, UFJoin, uf_join.
- * @return string $entity entity name in underscore separated format
+ *   Entity name in various formats e.g. Contribution, contribution,
+ *   OptionValue, option_value, UFJoin, uf_join.
+ * @return string
+ *   Entity name in underscore separated format.
  *
- * FIXME: Why isn't this called first thing in civicrm_api wrapper?
+ * @fixme Why isn't this called first thing in civicrm_api wrapper?
  */
 function _civicrm_api_get_entity_name_from_camel($entity) {
   if ($entity == strtolower($entity)) {
@@ -178,7 +188,7 @@ function _civicrm_api_get_entity_name_from_camel($entity) {
  *   DAO being passed in.
  * @return string
  */
-function _civicrm_api_get_entity_name_from_dao($bao){
+function _civicrm_api_get_entity_name_from_dao($bao) {
   $daoName = str_replace("BAO", "DAO", get_class($bao));
   return _civicrm_api_get_entity_name_from_camel(CRM_Core_DAO_AllCoreTables::getBriefName($daoName));
 }