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

[REF] cleanups on array operator #16821

Merged
merged 2 commits into from
Mar 17, 2020
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
10 changes: 5 additions & 5 deletions tests/extensions/test.extension.manager.paymenttest/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ class test_extension_manager_paymenttest extends CRM_Core_Payment {
public static $counts = array();

public function install() {
self::$counts['install'] = isset(self::$counts['install']) ? self::$counts['install'] : 0;
self::$counts['install'] = self::$counts['install'] ?? 0;
self::$counts['install'] = 1 + (int) self::$counts['install'];
}

public function uninstall() {
self::$counts['uninstall'] = isset(self::$counts['uninstall']) ? self::$counts['uninstall'] : 0;
self::$counts['uninstall'] = self::$counts['uninstall'] ?? 0;
self::$counts['uninstall'] = 1 + (int) self::$counts['uninstall'];
}

public function disable() {
self::$counts['disable'] = isset(self::$counts['disable']) ? self::$counts['disable'] : 0;
self::$counts['disable'] = self::$counts['disable'] ?? 0;
self::$counts['disable'] = 1 + (int) self::$counts['disable'];
}

public function enable() {
self::$counts['enable'] = isset(self::$counts['enable']) ? self::$counts['enable'] : 0;
self::$counts['enable'] = self::$counts['enable'] ?? 0;
self::$counts['enable'] = 1 + (int) self::$counts['enable'];
}

Expand All @@ -38,7 +38,7 @@ public function checkConfig() {
* @return int
*/
public static function getCount($type) {
return isset(self::$counts[$type]) ? self::$counts[$type] : 0;
return self::$counts[$type] ?? 0;
}

}
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Contact/BAO/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ public function testRetrieve() {
$this->assertEquals(1, $values['noteTotalCount'], 'Check for total note count');

foreach ($values['note'] as $key => $val) {
$retrieveNote = CRM_Utils_Array::value('note', $val);
$retrieveNote = $val['note'] ?? NULL;
//check the note value
$this->assertEquals($params['note'], $retrieveNote, 'Check for note');
}
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/CRM/Core/BAO/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,14 @@ public function testParseStreetAddressIfEnabled() {

$result = civicrm_api3('Address', 'create', $params);
$value = array_pop($result['values']);
$street_number = CRM_Utils_Array::value('street_number', $value);
$street_number = $value['street_number'] ?? NULL;
$this->assertEquals($street_number, '54');

// Ensure street parsing does not happen if disabled.
$this->setStreetAddressParsing(FALSE);
$result = civicrm_api3('Address', 'create', $params);
$value = array_pop($result['values']);
$street_number = CRM_Utils_Array::value('street_number', $value);
$street_number = $value['street_number'] ?? NULL;
$this->assertEmpty($street_number);

}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Core/Page/AJAXTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testCheckAuthz() {

foreach ($cases as $case) {
list ($type, $className, $expectedResult) = $case;
$methodName = CRM_Utils_Array::value(3, $case);
$methodName = $case[3] ?? NULL;
$actualResult = CRM_Core_Page_AJAX::checkAuthz($type, $className, $methodName);
if ($methodName) {
$this->assertEquals($expectedResult, $actualResult,
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/CRM/Event/BAO/AdditionalPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ protected function addParticipantWithPayment($feeTotal, $actualPaidAmt, $partici
// -- processing priceSet using the BAO
$lineItems = [];
$priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId, TRUE, FALSE);
$priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
$feeBlock = CRM_Utils_Array::value('fields', $priceSet);
$priceSet = $priceSet[$priceSetId] ?? NULL;
$feeBlock = $priceSet['fields'] ?? NULL;
$params['price_2'] = $feeTotal;
$tempParams = $params;

Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/CRM/Event/BAO/ChangeFeeSelectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public function setUp() {
$this->_priceSetID = $this->priceSetCreate();
CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_eventId, $this->_priceSetID);
$priceSet = CRM_Price_BAO_PriceSet::getSetDetail($this->_priceSetID, TRUE, FALSE);
$priceSet = CRM_Utils_Array::value($this->_priceSetID, $priceSet);
$this->_feeBlock = CRM_Utils_Array::value('fields', $priceSet);
$priceSet = $priceSet[$this->_priceSetID] ?? NULL;
$this->_feeBlock = $priceSet['fields'] ?? NULL;
}

/**
Expand Down Expand Up @@ -376,8 +376,8 @@ public function testCRM21513() {
$this->_priceSetID = $this->priceSetCreate('Text');
CRM_Price_BAO_PriceSet::addTo('civicrm_event', $this->_eventId, $this->_priceSetID);
$priceSet = CRM_Price_BAO_PriceSet::getSetDetail($this->_priceSetID, TRUE, FALSE);
$priceSet = CRM_Utils_Array::value($this->_priceSetID, $priceSet);
$this->_feeBlock = CRM_Utils_Array::value('fields', $priceSet);
$priceSet = $priceSet[$this->_priceSetID] ?? NULL;
$this->_feeBlock = $priceSet['fields'] ?? NULL;

$params = [
'send_receipt' => 1,
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/CRM/Member/BAO/MembershipTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public function testGetMembershipTypesByOrg() {
'limit' => 0,
],
]);
$result = CRM_Utils_Array::value('values', $membershipTypesResult, NULL);
$result = $membershipTypesResult['values'] ?? NULL;
$this->assertEquals(empty($result), FALSE, 'Verify membership types for organization.');

$membershipTypesResult = civicrm_api3('MembershipType', 'get', [
Expand All @@ -357,7 +357,7 @@ public function testGetMembershipTypesByOrg() {
'limit' => 0,
],
]);
$result = CRM_Utils_Array::value('values', $membershipTypesResult, NULL);
$result = $membershipTypesResult['values'] ?? NULL;
$this->assertEquals(empty($result), TRUE, 'Verify membership types for organization.');

$this->membershipTypeDelete(['id' => $membershipType->id]);
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Civi/Core/ThemesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public static function fakeCallback($themes, $themeKey, $cssExt, $cssFile) {
$map['bluemarine']['civicrm']['css/civicrm.css'] = ['http://example.com/blue/civicrm.css'];
$map['bluemarine']['test.extension.uitest']['files/foo.css'] = ['http://example.com/blue/foobar/foo.css'];
$map['aquamarine']['civicrm']['css/civicrm.css'] = ['http://example.com/aqua/civicrm.css'];
return isset($map[$themeKey][$cssExt][$cssFile]) ? $map[$themeKey][$cssExt][$cssFile] : Themes::PASSTHRU;
return $map[$themeKey][$cssExt][$cssFile] ?? Themes::PASSTHRU;
}

public function testGetAll() {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CiviTest/CiviTestSMSProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static function &singleton($providerParams = array(), $force = FALSE) {
$providerID = $provider['id'];
}
else {
$providerID = CRM_Utils_Array::value('provider_id', $providerParams);
$providerID = $providerParams['provider_id'] ?? NULL;
}
$skipAuth = $providerID ? FALSE : TRUE;
$cacheKey = (int) $providerID;
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1064,8 +1064,8 @@ protected function eventCreatePaid($params, $options = [['name' => 'hundy', 'amo
$this->priceSetID = $this->ids['PriceSet'][] = $this->eventPriceSetCreate(55, 0, 'Radio', $options);
CRM_Price_BAO_PriceSet::addTo('civicrm_event', $event['id'], $this->priceSetID);
$priceSet = CRM_Price_BAO_PriceSet::getSetDetail($this->priceSetID, TRUE, FALSE);
$priceSet = CRM_Utils_Array::value($this->priceSetID, $priceSet);
$this->eventFeeBlock = CRM_Utils_Array::value('fields', $priceSet);
$priceSet = $priceSet[$this->priceSetID] ?? NULL;
$this->eventFeeBlock = $priceSet['fields'] ?? NULL;
return $event;
}

Expand Down Expand Up @@ -1927,7 +1927,7 @@ public function getAndCheck($params, $id, $entity, $delete = 1, $errorText = '')
else {
$keys[CRM_Utils_Array::value('name', $settings, $field)] = CRM_Utils_Array::value('name', $settings, $field);
}
$type = CRM_Utils_Array::value('type', $settings);
$type = $settings['type'] ?? NULL;
if ($type == CRM_Utils_Type::T_DATE) {
$dateFields[] = $settings['name'];
// we should identify both real names & unique names as dates
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/api/v3/ContributionPageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2049,8 +2049,8 @@ public function testValidateOutputOnMissingRecurFields() {
*/
public function hook_civicrm_alterPaymentProcessorParams($paymentObj, &$rawParams, &$cookedParams) {
// Ensure total_amount are the same if they're both given.
$total_amount = CRM_Utils_Array::value('total_amount', $rawParams);
$amount = CRM_Utils_Array::value('amount', $rawParams);
$total_amount = $rawParams['total_amount'] ?? NULL;
$amount = $rawParams['amount'] ?? NULL;
if (!empty($total_amount) && !empty($amount) && $total_amount != $amount) {
throw new Exception("total_amount '$total_amount' and amount '$amount' differ.");
}
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/api/v3/MembershipTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,11 @@ public function testEnableMembershipTypeOnContributionPage() {
foreach ($memType as $rowCount => $type) {
$membetype = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($type);
$fieldParams['option_id'] = [1 => $priceFieldValue['id']];
$fieldParams['option_label'][$rowCount] = CRM_Utils_Array::value('name', $membetype);
$fieldParams['option_label'][$rowCount] = $membetype['name'] ?? NULL;
$fieldParams['option_amount'][$rowCount] = $membetype['minimum_fee'] ?? 0;
$fieldParams['option_weight'][$rowCount] = CRM_Utils_Array::value('weight', $membetype);
$fieldParams['option_description'][$rowCount] = CRM_Utils_Array::value('description', $membetype);
$fieldParams['option_financial_type_id'][$rowCount] = CRM_Utils_Array::value('financial_type_id', $membetype);
$fieldParams['option_weight'][$rowCount] = $membetype['weight'] ?? NULL;
$fieldParams['option_description'][$rowCount] = $membetype['description'] ?? NULL;
$fieldParams['option_financial_type_id'][$rowCount] = $membetype['financial_type_id'] ?? NULL;
$fieldParams['membership_type_id'][$rowCount] = $type;
}
$priceField = CRM_Price_BAO_PriceField::create($fieldParams);
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/SyntaxConformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,7 @@ public function testCreateSingleValueAlter($entityName) {
}
$updateParams = [
'id' => $entity['id'],
$field => isset($entity[$field]) ? $entity[$field] : NULL,
$field => $entity[$field] ?? NULL,
];
if (isset($updateParams['financial_type_id']) && in_array($entityName, ['Grant'])) {
//api has special handling on these 2 fields for backward compatibility reasons
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v4/Traits/TestDataLoaderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function loadDataSet($path) {
* @return null|mixed
*/
protected function getReference($name) {
return isset($this->references[$name]) ? $this->references[$name] : NULL;
return $this->references[$name] ?? NULL;
}

/**
Expand Down