diff --git a/CRM/Contribute/Import/Parser.php b/CRM/Contribute/Import/Parser.php index 9ceac6a63d6e..24c30758c8ba 100644 --- a/CRM/Contribute/Import/Parser.php +++ b/CRM/Contribute/Import/Parser.php @@ -427,20 +427,34 @@ public function setActiveFields($fieldKeys) { } /** + * Store the soft credit field information. + * + * This was perhaps done this way on the believe that a lot of code pain + * was worth it to avoid negligible-cost array iterations. Perhaps we could prioritise + * readability & maintainability next since we can just work with functions to retrieve + * data from the metadata. + * * @param array $elements */ public function setActiveFieldSoftCredit($elements) { - for ($i = 0; $i < count($elements); $i++) { - $this->_activeFields[$i]->_softCreditField = $elements[$i]; + foreach ((array) $elements as $i => $element) { + $this->_activeFields[$i]->_softCreditField = $element; } } /** + * Store the soft credit field type information. + * + * This was perhaps done this way on the believe that a lot of code pain + * was worth it to avoid negligible-cost array iterations. Perhaps we could prioritise + * readability & maintainability next since we can just work with functions to retrieve + * data from the metadata. + * * @param array $elements */ public function setActiveFieldSoftCreditType($elements) { - for ($i = 0; $i < count($elements); $i++) { - $this->_activeFields[$i]->_softCreditType = $elements[$i]; + foreach ((array) $elements as $i => $element) { + $this->_activeFields[$i]->_softCreditType = $element; } } diff --git a/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php index 44a6161911e7..d24295ed9339 100644 --- a/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php @@ -155,7 +155,7 @@ public function testContributionStatusLabel() { * @param array|null $fields * Array of field names. Will be calculated from $originalValues if not passed in. */ - protected function runImport($originalValues, $onDuplicateAction, $expectedResult, $mapperSoftCredit = [], $mapperPhoneType = NULL, $mapperSoftCreditType = [], $fields = NULL) { + protected function runImport($originalValues, $onDuplicateAction, $expectedResult, $mapperSoftCredit = NULL, $mapperPhoneType = NULL, $mapperSoftCreditType = NULL, $fields = NULL) { if (!$fields) { $fields = array_keys($originalValues); }