From c0c7b7275b0829881162de7d60bc8832df198efc Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 8 Aug 2019 13:02:47 +1200 Subject: [PATCH 1/2] Update test to pass null instead of array Per https://lab.civicrm.org/dev/core/issues/1001 we want to test NULL is correctly handled & does not give a warning in php7 since we seem not to have eliminated it & also the usage of count is actually really dumb and / or php4 oriented --- tests/phpunit/CRM/Contribute/Import/Parser/ContributionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); } From d8148eeefa96cdc9d58a82f7759814aaf0084914 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 8 Aug 2019 13:03:58 +1200 Subject: [PATCH 2/2] dev/core#1001 fix php 7.2 coun warning errors --- CRM/Contribute/Import/Parser.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) 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; } }