Skip to content

Commit

Permalink
Merge pull request #16137 from eileenmcnaughton/less_dep
Browse files Browse the repository at this point in the history
[REF] Minor cleanup - declare exceptions, use single quotes, strict comparison
  • Loading branch information
mattwire authored Dec 22, 2019
2 parents 2ca9b2e + 923dfab commit 574cf20
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
26 changes: 15 additions & 11 deletions CRM/Contact/BAO/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -1124,14 +1124,16 @@ public static function &getValues(&$params, &$values) {
*
* @return array
* [select, from, where]
* @throws \Exception
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public static function makeURLClause($contactId, $status, $numRelationship, $count, $relationshipId, $direction, $params = []) {
$select = $from = $where = '';

$select = '( ';
if ($count) {
if ($direction == 'a_b') {
if ($direction === 'a_b') {
$select .= ' SELECT count(DISTINCT civicrm_relationship.id) as cnt1, 0 as cnt2 ';
}
else {
Expand Down Expand Up @@ -1166,7 +1168,7 @@ public static function makeURLClause($contactId, $status, $numRelationship, $cou
civicrm_relationship.is_permission_b_a as is_permission_b_a,
civicrm_relationship.case_id as case_id';

if ($direction == 'a_b') {
if ($direction === 'a_b') {
$select .= ', civicrm_relationship_type.label_a_b as label_a_b,
civicrm_relationship_type.label_b_a as relation ';
}
Expand All @@ -1176,30 +1178,30 @@ public static function makeURLClause($contactId, $status, $numRelationship, $cou
}
}

$from = "
$from = '
FROM civicrm_relationship
INNER JOIN civicrm_relationship_type ON ( civicrm_relationship.relationship_type_id = civicrm_relationship_type.id )
INNER JOIN civicrm_contact ";
if ($direction == 'a_b') {
INNER JOIN civicrm_contact ';
if ($direction === 'a_b') {
$from .= 'ON ( civicrm_contact.id = civicrm_relationship.contact_id_a ) ';
}
else {
$from .= 'ON ( civicrm_contact.id = civicrm_relationship.contact_id_b ) ';
}

if (!$count) {
$from .= "
$from .= '
LEFT JOIN civicrm_address ON (civicrm_address.contact_id = civicrm_contact.id AND civicrm_address.is_primary = 1)
LEFT JOIN civicrm_phone ON (civicrm_phone.contact_id = civicrm_contact.id AND civicrm_phone.is_primary = 1)
LEFT JOIN civicrm_email ON (civicrm_email.contact_id = civicrm_contact.id AND civicrm_email.is_primary = 1)
LEFT JOIN civicrm_state_province ON (civicrm_address.state_province_id = civicrm_state_province.id)
LEFT JOIN civicrm_country ON (civicrm_address.country_id = civicrm_country.id)
";
';
}

$where = 'WHERE ( 1 )';
if ($contactId) {
if ($direction == 'a_b') {
if ($direction === 'a_b') {
$where .= ' AND civicrm_relationship.contact_id_b = ' . CRM_Utils_Type::escape($contactId, 'Positive');
}
else {
Expand Down Expand Up @@ -1245,7 +1247,7 @@ public static function makeURLClause($contactId, $status, $numRelationship, $cou
$where .= ' AND relationship_type_id = ' . CRM_Utils_Type::escape($params['relationship_type_id'], 'Positive');
}
}
if ($direction == 'a_b') {
if ($direction === 'a_b') {
$where .= ' ) UNION ';
}
else {
Expand Down Expand Up @@ -1279,7 +1281,9 @@ public static function makeURLClause($contactId, $status, $numRelationship, $cou
*
* @return array|int
* relationship records
* @throws \Exception
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public static function getRelationship(
$contactId = NULL,
Expand Down
3 changes: 3 additions & 0 deletions CRM/Member/BAO/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,9 @@ public static function create(&$params, &$ids = []) {
*
* @return array
* array of contact_id of all related contacts.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public static function checkMembershipRelationship($membershipTypeID, $contactId, $action = CRM_Core_Action::ADD) {
$contacts = [];
Expand Down
6 changes: 6 additions & 0 deletions tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class api_v3_ContributionTest extends CiviUnitTestCase {

/**
* Setup function.
*
* @throws \CRM_Core_Exception
*/
public function setUp() {
parent::setUp();
Expand Down Expand Up @@ -126,6 +128,8 @@ public function tearDown() {

/**
* Test Get.
*
* @throws \CRM_Core_Exception
*/
public function testGetContribution() {
$contributionSettings = $this->enableTaxAndInvoicing();
Expand Down Expand Up @@ -211,6 +215,8 @@ public function testGetContribution() {

/**
* Test that test contributions can be retrieved.
*
* @throws \CRM_Core_Exception
*/
public function testGetTestContribution() {
$this->callAPISuccess('Contribution', 'create', array_merge($this->_params, ['is_test' => 1]));
Expand Down

0 comments on commit 574cf20

Please sign in to comment.