Skip to content

Commit 03673b8

Browse files
Merge pull request #20446 from eileenmcnaughton/order
[NFC] Superficial code cleanup
2 parents 10dd5e4 + ee95478 commit 03673b8

File tree

3 files changed

+47
-22
lines changed

3 files changed

+47
-22
lines changed

api/v3/Order.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@
2424
*
2525
* @return array
2626
* Array of Order, if error an array with an error id and error message
27+
* @throws \CiviCRM_API3_Exception
2728
*/
28-
function civicrm_api3_order_get($params) {
29+
function civicrm_api3_order_get(array $params): array {
2930
$contributions = [];
3031
$params['api.line_item.get'] = ['qty' => ['<>' => 0]];
3132
$isSequential = FALSE;
@@ -53,7 +54,7 @@ function civicrm_api3_order_get($params) {
5354
* @param array $params
5455
* Array of parameters determined by getfields.
5556
*/
56-
function _civicrm_api3_order_get_spec(&$params) {
57+
function _civicrm_api3_order_get_spec(array &$params) {
5758
$params['id']['api.aliases'] = ['order_id'];
5859
$params['id']['title'] = ts('Contribution / Order ID');
5960
}
@@ -70,7 +71,7 @@ function _civicrm_api3_order_get_spec(&$params) {
7071
* @throws \CiviCRM_API3_Exception
7172
* @throws API_Exception
7273
*/
73-
function civicrm_api3_order_create($params) {
74+
function civicrm_api3_order_create(array $params): array {
7475
civicrm_api3_verify_one_mandatory($params, NULL, ['line_items', 'total_amount']);
7576
$entity = NULL;
7677
$entityIds = [];
@@ -156,10 +157,10 @@ function civicrm_api3_order_create($params) {
156157
$entity . '_id' => $entityId,
157158
];
158159
// if entity is pledge then build pledge param
159-
if ($entity == 'pledge') {
160+
if ($entity === 'pledge') {
160161
$paymentParams += $entityParams;
161162
}
162-
elseif ($entity == 'membership') {
163+
elseif ($entity === 'membership') {
163164
$contribution['values'][$contribution['id']]['membership_id'][] = $entityId;
164165
$paymentParams['isSkipLineItem'] = TRUE;
165166
}
@@ -174,11 +175,12 @@ function civicrm_api3_order_create($params) {
174175
*
175176
* @param array $params
176177
* Input parameters.
178+
*
177179
* @return array
178180
* @throws API_Exception
179181
* @throws CiviCRM_API3_Exception
180182
*/
181-
function civicrm_api3_order_delete($params) {
183+
function civicrm_api3_order_delete(array $params): array {
182184
$contribution = civicrm_api3('Contribution', 'get', [
183185
'return' => ['is_test'],
184186
'id' => $params['id'],
@@ -199,8 +201,9 @@ function civicrm_api3_order_delete($params) {
199201
* Input parameters.
200202
*
201203
* @return array
204+
* @throws \CiviCRM_API3_Exception
202205
*/
203-
function civicrm_api3_order_cancel($params) {
206+
function civicrm_api3_order_cancel(array $params) {
204207
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
205208
$params['contribution_status_id'] = array_search('Cancelled', $contributionStatuses);
206209
$result = civicrm_api3('Contribution', 'create', $params);
@@ -215,7 +218,7 @@ function civicrm_api3_order_cancel($params) {
215218
* @param array $params
216219
* Array of parameters determined by getfields.
217220
*/
218-
function _civicrm_api3_order_cancel_spec(&$params) {
221+
function _civicrm_api3_order_cancel_spec(array &$params) {
219222
$params['contribution_id'] = [
220223
'api.required' => 1,
221224
'title' => 'Contribution ID',
@@ -231,7 +234,7 @@ function _civicrm_api3_order_cancel_spec(&$params) {
231234
* @param array $params
232235
* Array of parameters determined by getfields.
233236
*/
234-
function _civicrm_api3_order_create_spec(&$params) {
237+
function _civicrm_api3_order_create_spec(array &$params) {
235238
$params['contact_id'] = [
236239
'name' => 'contact_id',
237240
'title' => 'Contact ID',
@@ -271,7 +274,7 @@ function _civicrm_api3_order_create_spec(&$params) {
271274
* @param array $params
272275
* Array of parameters determined by getfields.
273276
*/
274-
function _civicrm_api3_order_delete_spec(&$params) {
277+
function _civicrm_api3_order_delete_spec(array &$params) {
275278
$params['contribution_id'] = [
276279
'api.required' => TRUE,
277280
'title' => 'Contribution ID',

tests/phpunit/CRM/Contribute/Form/ContributionTest.php

+17-6
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,12 @@ protected function assertPostConditions(): void {
142142
*
143143
* @param string $thousandSeparator
144144
*
145+
* @throws \CRM_Core_Exception
146+
* @throws \CiviCRM_API3_Exception
147+
* @throws \Civi\Payment\Exception\PaymentProcessorException
145148
* @dataProvider getThousandSeparators
146149
*/
147-
public function testSubmit($thousandSeparator) {
150+
public function testSubmit(string $thousandSeparator): void {
148151
$this->setCurrencySeparators($thousandSeparator);
149152
$form = new CRM_Contribute_Form_Contribution();
150153
$form->testSubmit([
@@ -162,8 +165,11 @@ public function testSubmit($thousandSeparator) {
162165

163166
/**
164167
* Test the submit function on the contribution page.
168+
*
169+
* @throws \CRM_Core_Exception
170+
* @throws \CiviCRM_API3_Exception
165171
*/
166-
public function testSubmitCreditCard() {
172+
public function testSubmitCreditCard(): void {
167173
$form = new CRM_Contribute_Form_Contribution();
168174
$form->testSubmit([
169175
'total_amount' => 50,
@@ -180,8 +186,11 @@ public function testSubmitCreditCard() {
180186

181187
/**
182188
* Test the submit function on the contribution page.
189+
*
190+
* @throws \CRM_Core_Exception
191+
* @throws \CiviCRM_API3_Exception
183192
*/
184-
public function testSubmitCreditCardPayPal() {
193+
public function testSubmitCreditCardPayPal(): void {
185194
$mut = new CiviMailUtils($this, TRUE);
186195
$mut->clearMessages();
187196
$form = new CRM_Contribute_Form_Contribution();
@@ -236,8 +245,8 @@ public function testSubmitCreditCardPayPal() {
236245
]),
237246
]);
238247

239-
$this->assertEquals(1, $contribution["count"], "Contribution count should be one.");
240-
$this->assertTrue(!empty($contribution["values"][$contribution["id"]]["receipt_date"]), "Receipt date should not be blank.");
248+
$this->assertEquals(1, $contribution['count'], 'Contribution count should be one.');
249+
$this->assertNotTrue(empty($contribution['values'][$contribution['id']]['receipt_date']), 'Receipt date should not be blank.');
241250

242251
$contact = $this->callAPISuccessGetSingle('Contact', ['id' => $this->_individualId]);
243252
$this->assertTrue(empty($contact['source']));
@@ -251,6 +260,8 @@ public function testSubmitCreditCardPayPal() {
251260

252261
/**
253262
* Test the submit function on the contribution page
263+
*
264+
* @throws \CRM_Core_Exception
254265
*/
255266
public function testSubmitCreditCardWithEmailReceipt() {
256267
$mut = new CiviMailUtils($this, TRUE);
@@ -909,7 +920,7 @@ public function testEnterNegativeContribution() {
909920
*
910921
* @dataProvider getThousandSeparators
911922
*/
912-
public function testSubmitUpdate($thousandSeparator) {
923+
public function testSubmitUpdate(string $thousandSeparator): void {
913924
$this->setCurrencySeparators($thousandSeparator);
914925
$form = new CRM_Contribute_Form_Contribution();
915926

tests/phpunit/CRM/Core/Payment/BaseIPNTest.php

+17-6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class CRM_Core_Payment_BaseIPNTest extends CiviUnitTestCase {
6060

6161
/**
6262
* Setup function.
63+
*
64+
* @throws \CRM_Core_Exception
6365
*/
6466
public function setUp(): void {
6567
parent::setUp();
@@ -199,7 +201,7 @@ public function testComposeMailParticipantObjects() {
199201
/**
200202
* Test the LoadObjects function with recurring membership data.
201203
*/
202-
public function testSendMailParticipantObjectsCheckLog() {
204+
public function testSendMailParticipantObjectsCheckLog(): void {
203205
$this->_setUpParticipantObjects();
204206
$mut = new CiviMailUtils($this, TRUE);
205207
$this->callAPISuccess('Contribution', 'sendconfirmation', [
@@ -215,8 +217,11 @@ public function testSendMailParticipantObjectsCheckLog() {
215217

216218
/**
217219
* Test the LoadObjects function with recurring membership data.
220+
*
221+
* @throws \CRM_Core_Exception
222+
* @throws \Exception
218223
*/
219-
public function testsendMailParticipantObjectsNoMail() {
224+
public function testsendMailParticipantObjectsNoMail(): void {
220225
$this->_setUpParticipantObjects();
221226
$event = new CRM_Event_BAO_Event();
222227
$event->id = $this->_eventId;
@@ -238,15 +243,21 @@ public function testsendMailParticipantObjectsNoMail() {
238243
/**
239244
* Test the LoadObjects function with a pledge.
240245
*/
241-
public function testSendMailPledge() {
246+
public function testSendMailPledge(): void {
242247
$this->_setUpPledgeObjects();
243248
$contribution = new CRM_Contribute_BAO_Contribution();
244249
$contribution->id = $this->_contributionId;
245250
$msg = $contribution->composeMessageArray($this->input, $this->ids, $values);
246251
$this->assertStringContainsString('Contribution Information', $msg['html']);
247252
}
248253

249-
public function testThatCancellingEventPaymentWillCancelAllAdditionalPendingParticipantsAndCreateCancellationActivities() {
254+
/**
255+
* @throws \API_Exception
256+
* @throws \CRM_Core_Exception
257+
* @throws \Civi\API\Exception\UnauthorizedException
258+
* @throws \CiviCRM_API3_Exception
259+
*/
260+
public function testThatCancellingEventPaymentWillCancelAllAdditionalPendingParticipantsAndCreateCancellationActivities(): void {
250261
$this->_setUpParticipantObjects('Pending from incomplete transaction');
251262
$additionalParticipantId = $this->participantCreate([
252263
'event_id' => $this->_eventId,
@@ -259,7 +270,7 @@ public function testThatCancellingEventPaymentWillCancelAllAdditionalPendingPart
259270
'contribution_status_id:name' => 'Cancelled',
260271
])->addWhere('id', '=', $this->_contributionId)->execute();
261272

262-
$cancelledParticipantsCount = civicrm_api3('Participant', 'get', [
273+
$cancelledParticipantsCount = $this->callAPISuccess('Participant', 'get', [
263274
'sequential' => 1,
264275
'id' => ['IN' => [$this->_participantId, $additionalParticipantId]],
265276
'status_id' => 'Cancelled',
@@ -355,7 +366,7 @@ public function _setUpContributionObjects($contributionPage = FALSE) {
355366
/**
356367
* Prepare for membership test.
357368
*/
358-
public function _setUpMembershipObjects() {
369+
public function _setUpMembershipObjects(): void {
359370
try {
360371
if (!$this->_membershipTypeID) {
361372
$this->_membershipTypeID = $this->membershipTypeCreate();

0 commit comments

Comments
 (0)