Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #86 #87

Merged
merged 3 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CRM/Twingle/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@
*/
public function getCustomFieldMapping() {
$custom_field_mapping = [];
if (is_string($custom_field_definition = $this->getAttribute('custom_field_mapping'))) {
if ('' !== ($custom_field_definition = $this->getAttribute('custom_field_mapping', ''))) {
/** @var string $custom_field_definition */
$custom_field_maps = preg_split(
'/\r\n|\r|\n/',
$custom_field_definition,
Expand Down Expand Up @@ -205,7 +206,9 @@
* @return mixed | NULL
*/
public function getAttribute($attribute_name, $default = NULL) {
return $this->data[$attribute_name] ?? $default;
return (isset($this->data[$attribute_name]) && $this->data[$attribute_name] !== '')
? $this->data[$attribute_name]
: $default;
}

/**
Expand Down Expand Up @@ -247,7 +250,7 @@
* @throws \Civi\Core\Exception\DBQueryException
* When the profile could not be successfully validated.
*/
public function validate(): void {

Check warning on line 253 in CRM/Twingle/Profile.php

View workflow job for this annotation

GitHub Actions / PHP_CodeSniffer

Function's cyclomatic complexity (13) exceeds 10; consider refactoring the function

// Name cannot be empty
if ('' === $this->getName()) {
Expand Down Expand Up @@ -680,7 +683,7 @@
return $default_profile;
}
else {
throw new ProfileException('Could not find default profile', ProfileException::ERROR_CODE_DEFAULT_PROFILE_NOT_FOUND);

Check warning on line 686 in CRM/Twingle/Profile.php

View workflow job for this annotation

GitHub Actions / PHP_CodeSniffer

Line exceeds 120 characters; contains 123 characters
}
}

Expand Down
6 changes: 3 additions & 3 deletions CRM/Twingle/Submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
* @throws \CRM_Core_Exception
* When invalid parameters have been submitted.
*/
public static function validateSubmission(&$params, $profile = NULL): void {

Check warning on line 54 in CRM/Twingle/Submission.php

View workflow job for this annotation

GitHub Actions / PHP_CodeSniffer

Function's cyclomatic complexity (14) exceeds 10; consider refactoring the function
if (!isset($profile)) {
$profile = CRM_Twingle_Profile::createDefaultProfile();
}
Expand All @@ -72,8 +72,8 @@

// Get the payment instrument defined within the profile, or return an error
// if none matches (i.e. an unknown payment method was submitted).
$payment_instrument_id = $profile->getAttribute('pi_' . $params['payment_method']);
if (!isset($payment_instrument_id)) {
$payment_instrument_id = $profile->getAttribute('pi_' . $params['payment_method'], '');
if ('' !== $payment_instrument_id) {
throw new CRM_Core_Exception(
E::ts('Payment method could not be matched to existing payment instrument.'),
'invalid_format'
Expand Down Expand Up @@ -101,7 +101,7 @@
// matches (i.e. an unknown gender was submitted).
if (is_string($params['user_gender'])) {
$gender_id = $profile->getAttribute('gender_' . $params['user_gender']);
if (!isset($gender_id)) {
if (!is_numeric($gender_id)) {
throw new CRM_Core_Exception(
E::ts('Gender could not be matched to existing gender.'),
'invalid_format'
Expand Down
6 changes: 3 additions & 3 deletions api/v3/TwingleDonation/Submit.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
* @see civicrm_api3_create_success
* @see civicrm_api3_create_error
*/
function civicrm_api3_twingle_donation_Submit($params) {

Check warning on line 268 in api/v3/TwingleDonation/Submit.php

View workflow job for this annotation

GitHub Actions / PHP_CodeSniffer

Function's nesting level (6) exceeds 5; consider refactoring the function

Check failure on line 268 in api/v3/TwingleDonation/Submit.php

View workflow job for this annotation

GitHub Actions / PHP_CodeSniffer

Function's cyclomatic complexity (73) exceeds allowed maximum of 20
// Log call if debugging is enabled within civicrm.settings.php.
if (defined('TWINGLE_API_LOGGING') && TWINGLE_API_LOGGING) {
Civi::log()->debug('TwingleDonation.Submit: ' . json_encode($params, JSON_PRETTY_PRINT));
Expand Down Expand Up @@ -420,7 +420,7 @@
// Get the prefix ID defined within the profile
if (
isset($params['user_gender'])
&& NULL !== ($prefix_id = $profile->getAttribute('prefix_' . $params['user_gender']))
&& is_numeric($prefix_id = $profile->getAttribute('prefix_' . $params['user_gender']))
) {
$contact_data['prefix_id'] = $prefix_id;
}
Expand Down Expand Up @@ -830,8 +830,8 @@
$result_values['membership'] = $membership;

// call the postprocess API
$postprocess_call = $profile->getAttribute('membership_postprocess_call');
if (is_string($postprocess_call)) {
if ('' !== ($postprocess_call = $profile->getAttribute('membership_postprocess_call', ''))) {
/** @var string $postprocess_call */
[$pp_entity, $pp_action] = explode('.', $postprocess_call, 2);
try {
// gather the contribution IDs
Expand Down
Loading