PHP Code Sniffer fixes

This commit is contained in:
Jens Schuppe 2024-04-03 12:22:39 +02:00
parent 6313fffa44
commit d7b066751a
4 changed files with 23 additions and 6 deletions

View file

@ -353,6 +353,7 @@ class CRM_Twingle_Profile {
], ],
] ]
// Add contribution status for all payment methods. // Add contribution status for all payment methods.
// phpcs:ignore Drupal.Formatting.SpaceUnaryOperator.PlusMinus
+ array_fill_keys(array_map(function($attribute) { + array_fill_keys(array_map(function($attribute) {
return $attribute . '_status'; return $attribute . '_status';
}, array_keys(static::paymentInstruments())), CRM_Twingle_Submission::CONTRIBUTION_STATUS_COMPLETED)); }, array_keys(static::paymentInstruments())), CRM_Twingle_Submission::CONTRIBUTION_STATUS_COMPLETED));
@ -440,6 +441,7 @@ class CRM_Twingle_Profile {
$stats = []; $stats = [];
$profile_data = CRM_Core_DAO::executeQuery('SELECT name, last_access, access_counter FROM civicrm_twingle_profile'); $profile_data = CRM_Core_DAO::executeQuery('SELECT name, last_access, access_counter FROM civicrm_twingle_profile');
while ($profile_data->fetch()) { while ($profile_data->fetch()) {
// phpcs:disable Drupal.Arrays.Array.ArrayIndentation
$stats[$profile_data->name] = [ $stats[$profile_data->name] = [
'name' => $profile_data->name, 'name' => $profile_data->name,
'last_access' => $profile_data->last_access, 'last_access' => $profile_data->last_access,
@ -451,6 +453,7 @@ class CRM_Twingle_Profile {
? ((int) $profile_data->access_counter) . 'x' ? ((int) $profile_data->access_counter) . 'x'
: E::ts('never'), : E::ts('never'),
]; ];
// phpcs:enable
} }
return $stats; return $stats;
} }

View file

@ -123,10 +123,13 @@ class CRM_Twingle_Tools {
break; break;
case CRM_Twingle_Config::RCUR_PROTECTION_EXCEPTION: case CRM_Twingle_Config::RCUR_PROTECTION_EXCEPTION:
// phpcs:disable Generic.Files.LineLength.TooLong
throw new Exception(E::ts( throw new Exception(E::ts(
'This is a Twingle recurring contribution. It should be terminated through the Twingle interface, otherwise it will still be collected.' 'This is a Twingle recurring contribution. It should be terminated through the Twingle interface, otherwise it will still be collected.'
)); ));
// phpcs:enable
case CRM_Twingle_Config::RCUR_PROTECTION_ACTIVITY: case CRM_Twingle_Config::RCUR_PROTECTION_ACTIVITY:
// create contact source activity // create contact source activity
// first: get the contact ID // first: get the contact ID
@ -157,8 +160,12 @@ class CRM_Twingle_Tools {
'target_id' => $target_id, 'target_id' => $target_id,
'assignee_id' => Civi::settings()->get('twingle_protect_recurring_activity_assignee'), 'assignee_id' => Civi::settings()->get('twingle_protect_recurring_activity_assignee'),
'status_id' => Civi::settings()->get('twingle_protect_recurring_activity_status'), 'status_id' => Civi::settings()->get('twingle_protect_recurring_activity_status'),
'details' => E::ts("Recurring contribution [%1] (Transaction ID '%2') was terminated by a user. You need to end the corresponding record in Twingle as well, or it will still be collected.", // phpcs:disable Generic.Files.LineLength.TooLong
[1 => $recurring_contribution_id, 2 => $trxn_id]), 'details' => E::ts(
"Recurring contribution [%1] (Transaction ID '%2') was terminated by a user. You need to end the corresponding record in Twingle as well, or it will still be collected.",
[1 => $recurring_contribution_id, 2 => $trxn_id]
),
// phpcs:enable
'source_contact_id' => CRM_Core_Session::getLoggedInContactID(), 'source_contact_id' => CRM_Core_Session::getLoggedInContactID(),
]); ]);
} }

View file

@ -89,8 +89,9 @@ class CRM_Twingle_Upgrader extends CRM_Extension_Upgrader_Base {
foreach ($profiles_data as $profile_name => $profile_data) { foreach ($profiles_data as $profile_name => $profile_data) {
$profile = new CRM_Twingle_Profile($profile_name, $profile_data); $profile = new CRM_Twingle_Profile($profile_name, $profile_data);
$data = json_encode($profile->getData()); $data = json_encode($profile->getData());
CRM_Core_DAO::executeQuery( CRM_Core_DAO::executeQuery(<<<SQL
'INSERT IGNORE INTO civicrm_twingle_profile(name,config,last_access,access_counter) VALUES (%1, %2, NOW(), 0)', INSERT IGNORE INTO civicrm_twingle_profile(name,config,last_access,access_counter) VALUES (%1, %2, NOW(), 0)
SQL,
[ [
1 => [$profile_name, 'String'], 1 => [$profile_name, 'String'],
2 => [$data, 'String'], 2 => [$data, 'String'],

View file

@ -321,7 +321,8 @@ function civicrm_api3_twingle_donation_Submit($params) {
// Chain a CustomGroup.getsingle API call. // Chain a CustomGroup.getsingle API call.
'api.CustomGroup.getsingle' => [], 'api.CustomGroup.getsingle' => [],
]); ]);
$custom_fields[$custom_field['api.CustomGroup.getsingle']['extends']][$custom_field_mapping[$twingle_field]] = $value; $entity = $custom_field['api.CustomGroup.getsingle']['extends'];
$custom_fields[$entity][$custom_field_mapping[$twingle_field]] = $value;
} }
} }
} }
@ -652,6 +653,7 @@ function civicrm_api3_twingle_donation_Submit($params) {
$mandate_data = $mandate_data =
$contribution_data $contribution_data
// ... CiviSEPA mandate attributes, ... // ... CiviSEPA mandate attributes, ...
// phpcs:ignore Drupal.Formatting.SpaceUnaryOperator.PlusMinus
+ [ + [
'type' => ($params['donation_rhythm'] == 'one_time' ? 'OOFF' : 'RCUR'), 'type' => ($params['donation_rhythm'] == 'one_time' ? 'OOFF' : 'RCUR'),
'iban' => $params['debit_iban'], 'iban' => $params['debit_iban'],
@ -664,6 +666,7 @@ function civicrm_api3_twingle_donation_Submit($params) {
'creditor_id' => $creditor_id, 'creditor_id' => $creditor_id,
] ]
// ... and frequency unit and interval from a static mapping. // ... and frequency unit and interval from a static mapping.
// phpcs:ignore Drupal.Formatting.SpaceUnaryOperator.PlusMinus
+ CRM_Twingle_Submission::getFrequencyMapping($params['donation_rhythm']); + CRM_Twingle_Submission::getFrequencyMapping($params['donation_rhythm']);
// Add custom field values. // Add custom field values.
if (!empty($custom_fields['ContributionRecur'])) { if (!empty($custom_fields['ContributionRecur'])) {
@ -748,7 +751,10 @@ function civicrm_api3_twingle_donation_Submit($params) {
// Create contribution. // Create contribution.
$contribution_data += [ $contribution_data += [
'contribution_status_id' => $profile->getAttribute("pi_{$params['payment_method']}_status", CRM_Twingle_Submission::CONTRIBUTION_STATUS_COMPLETED), 'contribution_status_id' => $profile->getAttribute(
"pi_{$params['payment_method']}_status",
CRM_Twingle_Submission::CONTRIBUTION_STATUS_COMPLETED
),
'receive_date' => $params['confirmed_at'], 'receive_date' => $params['confirmed_at'],
]; ];