Unverified Commit a3b9a8e3 authored by eileen's avatar eileen 🎱 Committed by GitHub

Merge pull request #13980 from seamuslee001/new_coder_style_check_api

(NFC) Bring up API folder to style of future coder checker
parents e4a739c7 7c31ae57
......@@ -43,7 +43,6 @@ function civicrm_api3_acl_role_create($params) {
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'EntityRole');
}
/**
* AclRole create metadata.
*
......
......@@ -43,7 +43,6 @@ function civicrm_api3_action_schedule_get($params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'ActionSchedule');
}
/**
* Create a new ActionSchedule.
*
......
......@@ -31,7 +31,6 @@
* @package CiviCRM_APIv3
*/
/**
* Creates or updates an Activity.
*
......@@ -291,7 +290,7 @@ function _civicrm_api3_activity_get_spec(&$params) {
* @param array $params
* Array per getfields documentation.
*
* @return array API result array
* @return array
* API result array
*
* @throws \API_Exception
......@@ -592,7 +591,7 @@ function _civicrm_api3_activity_fill_activity_contact_names(&$activities, $param
$typeMap = [
$assigneeType => 'assignee',
$sourceType => 'source',
$targetType => 'target'
$targetType => 'target',
];
$activityContactTypes = [$sourceType];
......@@ -609,7 +608,7 @@ function _civicrm_api3_activity_fill_activity_contact_names(&$activities, $param
'activity_id',
'record_type_id',
'contact_id.display_name',
'contact_id'
'contact_id',
],
'check_permissions' => !empty($params['check_permissions']),
];
......@@ -631,7 +630,6 @@ function _civicrm_api3_activity_fill_activity_contact_names(&$activities, $param
}
}
/**
* Delete a specified Activity.
*
......
......@@ -481,7 +481,8 @@ function _civicrm_api3_attachment_getfields() {
// Would be hard to securely handle changes.
$spec['entity_table']['title'] = CRM_Utils_Array::value('title', $spec['entity_table'], 'Entity Table') . ' (write-once)';
$spec['entity_id'] = $entityFileFields['entity_id'];
$spec['entity_id']['title'] = CRM_Utils_Array::value('title', $spec['entity_id'], 'Entity ID') . ' (write-once)'; // would be hard to securely handle changes
// would be hard to securely handle changes
$spec['entity_id']['title'] = CRM_Utils_Array::value('title', $spec['entity_id'], 'Entity ID') . ' (write-once)';
$spec['url'] = [
'title' => 'URL (read-only)',
'description' => 'URL for downloading the file (not searchable, expire-able)',
......
......@@ -32,7 +32,6 @@
* @package CiviCRM_APIv3
*/
/**
* Open a new case, add client and manager roles, and standard timeline.
*
......@@ -67,11 +66,10 @@ function civicrm_api3_case_create($params) {
if (empty($params['id'])) {
// Creating a new case, so make sure we have the necessary parameters
civicrm_api3_verify_mandatory($params, NULL, [
'contact_id',
'subject',
['case_type', 'case_type_id'],
]
);
'contact_id',
'subject',
['case_type', 'case_type_id'],
]);
}
else {
// Update an existing case
......@@ -744,7 +742,6 @@ function _civicrm_api3_case_format_params(&$params) {
}
}
/**
* It actually works a lot better to use the CaseContact api instead of the Case api
* for entityRef fields so we can perform the necessary joins,
......
......@@ -52,8 +52,10 @@ function civicrm_api3_case_type_create($params) {
}
// This is an existing case-type.
if (!empty($params['id']) && isset($params['definition'])
&& !CRM_Case_BAO_CaseType::isForked($params['id']) // which is not yet forked
&& !CRM_Case_BAO_CaseType::isForkable($params['id']) // for which new forks are prohibited
// which is not yet forked
&& !CRM_Case_BAO_CaseType::isForked($params['id'])
// for which new forks are prohibited
&& !CRM_Case_BAO_CaseType::isForkable($params['id'])
) {
unset($params['definition']);
}
......
......@@ -524,7 +524,6 @@ function civicrm_api3_contact_delete($params) {
}
}
/**
* Check parameters passed in.
*
......@@ -549,12 +548,11 @@ function _civicrm_api3_contact_check_params(&$params) {
case 'individual':
civicrm_api3_verify_one_mandatory($params, NULL, [
'first_name',
'last_name',
'email',
'display_name',
]
);
'first_name',
'last_name',
'email',
'display_name',
]);
break;
}
......@@ -1454,7 +1452,6 @@ WHERE $whereClause
return civicrm_api3_create_success($contacts, $params, 'Contact', 'get_by_location', $dao);
}
/**
* Get parameters for getlist function.
*
......
......@@ -672,7 +672,7 @@ function civicrm_api3_contribution_repeattransaction(&$params) {
return _ipn_process_transaction($params, $contribution, $input, $ids, $original_contribution);
}
catch(Exception $e) {
catch (Exception $e) {
throw new API_Exception('failed to load related objects' . $e->getMessage() . "\n" . $e->getTraceAsString());
}
}
......
......@@ -242,9 +242,8 @@ SELECT count(*)
break;
}
if (in_array($htmlType, [
'Select', 'Multi-Select', 'CheckBox', 'Radio']) &&
!isset($errors[$fieldName])
if (in_array($htmlType, ['Select', 'Multi-Select', 'CheckBox', 'Radio'])
&& !isset($errors[$fieldName])
) {
$options = CRM_Core_OptionGroup::valuesByID($fieldDetails['option_group_id']);
if (!is_array($value)) {
......
......@@ -31,7 +31,6 @@
* @package CiviCRM_APIv3
*/
/**
* Sets custom values for an entity.
*
......
......@@ -317,7 +317,7 @@ function civicrm_api3_cxn_create($params) {
return civicrm_api3_create_success($result, $params, 'Cxn', 'create');
}
catch(Exception $ex){
catch (Exception $ex) {
throw $ex;
}
}
......@@ -25,8 +25,8 @@
+--------------------------------------------------------------------+
*/
use \Civi\Cxn\Rpc\Message\AppMetasMessage;
use \Civi\Cxn\Rpc\Message\GarbledMessage;
use Civi\Cxn\Rpc\Message\AppMetasMessage;
use Civi\Cxn\Rpc\Message\GarbledMessage;
/**
* The CxnApp API provides a pseudo-entity for exploring the list
......
......@@ -31,7 +31,6 @@
* @package CiviCRM_APIv3
*/
/**
* Creates or updates an Dashlet.
*
......@@ -42,12 +41,11 @@
*/
function civicrm_api3_dashboard_create($params) {
civicrm_api3_verify_one_mandatory($params, NULL, [
'name',
'label',
'url',
'fullscreen_url',
]
);
'name',
'label',
'url',
'fullscreen_url',
]);
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Dashboard');
}
......
......@@ -76,16 +76,9 @@ function civicrm_api3_domain_get($params) {
if (!empty($values['location']['phone'])) {
$domain['domain_phone'] = [
'phone_type' => CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_Phone', 'phone_type_id',
CRM_Utils_Array::value(
'phone_type_id',
$values['location']['phone'][1]
)
),
'phone' => CRM_Utils_Array::value(
'phone',
$values['location']['phone'][1]
),
];
CRM_Utils_Array::value('phone_type_id', $values['location']['phone'][1])),
'phone' => CRM_Utils_Array::value('phone', $values['location']['phone'][1]),
];
}
if (!empty($values['location']['address'])) {
......
......@@ -190,7 +190,7 @@ function civicrm_api3_entity_tag_replace($params) {
return civicrm_api3_create_success($result, $params, 'EntityTag', 'replace');
}
catch(Exception $e) {
catch (Exception $e) {
$transaction->rollback();
return civicrm_api3_create_error($e->getMessage());
}
......
......@@ -217,7 +217,6 @@ function _civicrm_api3_event_getisfull(&$event, $event_id) {
$event[$event_id]['is_full'] = $event[$event_id]['available_places'] == 0 ? 1 : 0;
}
/**
* Get event list parameters.
*
......
......@@ -24,6 +24,7 @@
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* Get a Dedupe Exception.
*
......@@ -36,6 +37,7 @@
function civicrm_api3_exception_get($params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
/**
* Create or update an dedupe exception.
*
......
......@@ -301,13 +301,15 @@ function civicrm_api3_extension_refresh($params) {
if ($params['local']) {
$system->getManager()->refresh();
$system->getManager()->getStatuses(); // force immediate scan
// force immediate scan
$system->getManager()->getStatuses();
}
if ($params['remote']) {
if ($system->getBrowser()->isEnabled() && empty($system->getBrowser()->checkRequirements)) {
$system->getBrowser()->refresh();
$system->getBrowser()->getExtensions(); // force immediate download
// force immediate download
$system->getBrowser()->getExtensions();
}
}
......@@ -358,7 +360,8 @@ function civicrm_api3_extension_get($params) {
continue;
}
$info = CRM_Extension_System::createExtendedInfo($obj);
$info['id'] = $id++; // backward compatibility with indexing scheme
// backward compatibility with indexing scheme
$info['id'] = $id++;
if (!empty($keys)) {
if (in_array($key, $keys)) {
$result[] = $info;
......@@ -392,7 +395,8 @@ function civicrm_api3_extension_getremote($params) {
$id = 0;
foreach ($extensions as $key => $obj) {
$info = [];
$info['id'] = $id++; // backward compatibility with indexing scheme
// backward compatibility with indexing scheme
$info['id'] = $id++;
$info = array_merge($info, (array) $obj);
$result[] = $info;
}
......
......@@ -130,7 +130,8 @@ function civicrm_api3_generic_getfields($apiRequest, $unique = TRUE) {
'api.required' => 1,
'api.aliases' => [$lowercase_entity . '_id'],
'type' => CRM_Utils_Type::T_INT,
]];
],
];
break;
// Note: adding setvalue case here instead of in a generic spec function because
......
......@@ -57,8 +57,7 @@ function civicrm_api3_generic_setValue($apiRequest) {
$fields = civicrm_api($entity, 'getFields', [
'version' => 3,
'action' => 'create',
"sequential"]
);
]);
// getfields error, shouldn't happen.
if ($fields['is_error']) {
return $fields;
......
......@@ -31,7 +31,6 @@
* @package CiviCRM_APIv3
*/
/**
* Get group organization record/s.
*
......
......@@ -228,6 +228,7 @@ function civicrm_api3_job_send_reminder($params) {
return civicrm_api3_create_error($result['messages']);
}
}
/**
* Adjust metadata for "send_reminder" action.
*
......@@ -244,6 +245,7 @@ function _civicrm_api3_job_send_reminder(&$params) {
'title' => 'Action Schedule ID',
];
}
/**
* Execute a specific report instance and send the output via email.
*
......@@ -464,7 +466,6 @@ function civicrm_api3_job_process_participant($params) {
}
}
/**
* This api checks and updates the status of all membership records for a given domain.
*
......
......@@ -86,7 +86,7 @@ function civicrm_api3_loc_block_create($params) {
_civicrm_api3_object_to_array($dao, $values[$dao->id]);
return civicrm_api3_create_success($values, $params, 'LocBlock', 'create', $dao);
}
throw New API_Exception('Unable to create LocBlock. Please check your params.');
throw new API_Exception('Unable to create LocBlock. Please check your params.');
}
/**
......
......@@ -37,7 +37,7 @@
* @param array $params
*
* @return array
* API Success Array
* API Success Array
* @throws \API_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
......@@ -88,7 +88,7 @@ function _civicrm_api3_logging_revert_spec(&$params) {
* @param array $params
*
* @return array
* API Success Array
* API Success Array
* @throws \API_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
......
......@@ -38,7 +38,7 @@
* @param array $params
*
* @return array
* API Success Array
* API Success Array
* @throws \API_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
......@@ -440,7 +440,8 @@ function _civicrm_api3_mailing_event_reply_spec(&$params) {
$params['hash']['api.required'] = 1;
$params['hash']['title'] = 'Hash';
$params['replyTo']['api.required'] = 0;
$params['replyTo']['title'] = 'Reply To';//doesn't really explain adequately
//doesn't really explain adequately
$params['replyTo']['title'] = 'Reply To';
}
/**
......@@ -635,17 +636,17 @@ function civicrm_api3_mailing_send_test($params) {
$testEmailParams['emails'] = array_key_exists('test_email', $testEmailParams) ? explode(',', strtolower($testEmailParams['test_email'])) : NULL;
if (!empty($params['test_email'])) {
$query = CRM_Utils_SQL_Select::from('civicrm_email e')
->select(['e.id', 'e.contact_id', 'e.email'])
->join('c', 'INNER JOIN civicrm_contact c ON e.contact_id = c.id')
->where('e.email IN (@emails)', ['@emails' => $testEmailParams['emails']])
->where('e.on_hold = 0')
->where('c.is_opt_out = 0')
->where('c.do_not_email = 0')
->where('c.is_deceased = 0')
->where('c.is_deleted = 0')
->groupBy('e.id')
->orderBy(['e.is_bulkmail DESC', 'e.is_primary DESC'])
->toSQL();
->select(['e.id', 'e.contact_id', 'e.email'])
->join('c', 'INNER JOIN civicrm_contact c ON e.contact_id = c.id')
->where('e.email IN (@emails)', ['@emails' => $testEmailParams['emails']])
->where('e.on_hold = 0')
->where('c.is_opt_out = 0')
->where('c.do_not_email = 0')
->where('c.is_deceased = 0')
->where('c.is_deleted = 0')
->groupBy('e.id')
->orderBy(['e.is_bulkmail DESC', 'e.is_primary DESC'])
->toSQL();
$dao = CRM_Core_DAO::executeQuery($query);
$emailDetail = [];
// fetch contact_id and email id for all existing emails
......
......@@ -135,13 +135,13 @@ function civicrm_api3_mailing_a_b_submit($params) {
throw new API_Exception("Cannot transition to state 'Testing'");
}
civicrm_api3('Mailing', 'submit', $submitParams + [
'id' => $dao->mailing_id_a,
'_skip_evil_bao_auto_recipients_' => 0,
]);
'id' => $dao->mailing_id_a,
'_skip_evil_bao_auto_recipients_' => 0,
]);
civicrm_api3('Mailing', 'submit', $submitParams + [
'id' => $dao->mailing_id_b,
'_skip_evil_bao_auto_recipients_' => 1,
]);
'id' => $dao->mailing_id_b,
'_skip_evil_bao_auto_recipients_' => 1,
]);
CRM_Mailing_BAO_MailingAB::distributeRecipients($dao);
break;
......@@ -150,9 +150,9 @@ function civicrm_api3_mailing_a_b_submit($params) {
throw new API_Exception("Cannot transition to state 'Final'");
}
civicrm_api3('Mailing', 'submit', $submitParams + [
'id' => $dao->mailing_id_c,
'_skip_evil_bao_auto_recipients_' => 1,
]);
'id' => $dao->mailing_id_c,
'_skip_evil_bao_auto_recipients_' => 1,
]);
break;
default:
......
......@@ -44,7 +44,6 @@ function civicrm_api3_mailing_component_create($params) {
return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'MailingComponent');
}
/**
* Adjust Metadata for Create action.
*
......
......@@ -83,7 +83,8 @@ function _civicrm_api3_mailing_contact_get_spec(&$params) {
$params['type'] = [
'api.default' => 'Delivered',
'title' => 'Type', // doesn't really explain the field - but not sure I understand it to explain it better
// doesn't really explain the field - but not sure I understand it to explain it better
'title' => 'Type',
'type' => CRM_Utils_Type::T_STRING,
'options' => [
'Delivered' => 'Delivered',
......
......@@ -31,7 +31,6 @@
* @package CiviCRM_APIv3
*/
/**
* Returns array of MailingRecipients.
*
......
......@@ -280,7 +280,6 @@ function _civicrm_api3_membership_get_customv2behaviour(&$params, $membershipTyp
return $membershipValues;
}
/**
* Non-standard behaviour inherited from v2.
*
......
......@@ -189,7 +189,7 @@ function civicrm_api3_order_cancel($params) {
*/
function _civicrm_api3_order_cancel_spec(&$params) {
$params['contribution_id'] = [
'api.required' => 1 ,
'api.required' => 1,
'title' => 'Contribution ID',
'type' => CRM_Utils_Type::T_INT,
];
......
......@@ -128,7 +128,6 @@ function _civicrm_api3_participant_createlineitem(&$params, $participant) {
}
}
/**
* Adjust Metadata for Create action.
*
......
......@@ -150,12 +150,12 @@ function civicrm_api3_payment_create(&$params) {
function _civicrm_api3_payment_create_spec(&$params) {
$params = [
'contribution_id' => [
'api.required' => 1 ,
'api.required' => 1,
'title' => 'Contribution ID',
'type' => CRM_Utils_Type::T_INT,
],
'total_amount' => [
'api.required' => 1 ,
'api.required' => 1,
'title' => 'Total Payment Amount',
'type' => CRM_Utils_Type::T_FLOAT,
],
......@@ -209,7 +209,7 @@ function _civicrm_api3_payment_get_spec(&$params) {
function _civicrm_api3_payment_delete_spec(&$params) {
$params = [
'id' => [
'api.required' => 1 ,
'api.required' => 1,
'title' => 'Payment ID',
'type' => CRM_Utils_Type::T_INT,
'api.aliases' => ['payment_id'],
......@@ -228,7 +228,7 @@ function _civicrm_api3_payment_delete_spec(&$params) {
function _civicrm_api3_payment_cancel_spec(&$params) {
$params = [
'id' => [
'api.required' => 1 ,
'api.required' => 1,
'title' => 'Payment ID',
'type' => CRM_Utils_Type::T_INT,
'api.aliases' => ['payment_id'],
......@@ -263,7 +263,8 @@ function civicrm_api3_payment_sendconfirmation($params) {
'subject' => $result[1],
'message_txt' => $result[2],
'message_html' => $result[3],
]]);
],
]);
}
/**
......
......@@ -93,7 +93,6 @@ function civicrm_api3_payment_processor_get($params) {
return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}
/**
* Set default getlist parameters.
*
......
......@@ -32,6 +32,7 @@
*
* @package CiviCRM_APIv3
*/
/**
* Create or update a survey.
*
......
......@@ -446,7 +446,7 @@ function _civicrm_api3_profile_getbillingpseudoprofile(&$params) {
'api.email.get.1' => ['location_type_id' => 'Billing'],
'api.email.get.2' => ['is_billing' => TRUE],
'return' => 'api.email.get, api.address.get, api.address.getoptions, country, state_province, email, first_name, last_name, middle_name, ' . implode($addressFields, ','),
]
]
);
$values = [
......@@ -611,10 +611,10 @@ function _civicrm_api3_buildprofile_submitfields($profileID, $optionsBehaviour =
}
/**
* putting this on hold -this would cause the api to set the default - but could have unexpected behaviour
if (isset($result['values'][$realName]['default_value'])) {
//this would be the case for a custom field with a configured default
$profileFields[$profileID][$entityfield]['api.default'] = $result['values'][$realName]['default_value'];
}
* if (isset($result['values'][$realName]['default_value'])) {
* //this would be the case for a custom field with a configured default
* $profileFields[$profileID][$entityfield]['api.default'] = $result['values'][$realName]['default_value'];
* }
*/
}
}
......
......@@ -216,6 +216,6 @@ function _civicrm_api3_relationship_getoptions_spec(&$params) {
'title' => ts('Is Form?'),
'description' => $relationshipTypePrefix . ts('Formats the options for use'
. ' in a form if true. The format is <id>_a_b => <label>'),
'type' => CRM_Utils_Type::T_BOOLEAN
'type' => CRM_Utils_Type::T_BOOLEAN,
];
}
......@@ -135,7 +135,7 @@ function _civicrm_api3_report_template_getrows($params) {
'option_group_name' => 'report_template',
'return' => 'name',
'value' => $params['report_id'],
]
]
);
$reportInstance = new $class();
......@@ -154,7 +154,7 @@ function _civicrm_api3_report_template_getrows($params) {
$reportInstance->beginPostProcessCommon();
$sql = $reportInstance->buildQuery();
$reportInstance->addToDeveloperTab($sql);
$rows = $metadata = $requiredMetadata = [];
$rows = $metadata = $requiredMetadata = [];
$reportInstance->buildRows($sql, $rows);
$reportInstance->formatDisplay($rows);
......@@ -191,6 +191,7 @@ function civicrm_api3_report_template_getstatistics($params) {
$reportInstance->cleanUpTemporaryTables();
return civicrm_api3_create_success($stats, $params, 'ReportTemplate', 'getstatistics', CRM_Core_DAO::$_nullObject, $metadata);
}
/**
* Adjust metadata for template getrows action.
*
......
......@@ -38,7 +38,8 @@
* @param array $params
* Associative array of property name-value pairs to insert in new saved search.