From 2cbe6e87cbf0c1ce7a2f89c2000c472b58e66146 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 17 Feb 2020 10:01:51 +1300 Subject: [PATCH] [NFC] Preliminary cleanup Declare exceptions, params, don't declare unused variables --- CRM/Dedupe/BAO/Rule.php | 5 ++++- CRM/Dedupe/Finder.php | 7 ++++--- tests/phpunit/CRM/Dedupe/DedupeFinderTest.php | 20 +++++++++++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/CRM/Dedupe/BAO/Rule.php b/CRM/Dedupe/BAO/Rule.php index 6ff97260ee..ec24a78413 100644 --- a/CRM/Dedupe/BAO/Rule.php +++ b/CRM/Dedupe/BAO/Rule.php @@ -41,6 +41,9 @@ class CRM_Dedupe_BAO_Rule extends CRM_Dedupe_DAO_Rule { * * @return string * SQL query performing the search + * + * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception */ public function sql() { if ($this->params && @@ -126,7 +129,7 @@ class CRM_Dedupe_BAO_Rule extends CRM_Dedupe_DAO_Rule { $id = 'entity_id'; } else { - CRM_Core_Error::fatal("Unsupported rule_table for civicrm_dedupe_rule.id of {$this->id}"); + throw new CRM_Core_Exception("Unsupported rule_table for civicrm_dedupe_rule.id of {$this->id}"); } break; } diff --git a/CRM/Dedupe/Finder.php b/CRM/Dedupe/Finder.php index 25fd1adbea..f2626bcb32 100644 --- a/CRM/Dedupe/Finder.php +++ b/CRM/Dedupe/Finder.php @@ -38,7 +38,7 @@ class CRM_Dedupe_Finder { * @return array * Array of (cid1, cid2, weight) dupe triples * - * @throws Exception + * @throws \CRM_Core_Exception */ public static function dupes($rgid, $cids = [], $checkPermissions = TRUE) { $rgBao = new CRM_Dedupe_BAO_RuleGroup(); @@ -152,7 +152,8 @@ class CRM_Dedupe_Finder { * * @return array * array of (cid1, cid2, weight) dupe triples - * @throws \CiviCRM_API3_Exception + * + * @throws \CRM_Core_Exception */ public static function dupesInGroup($rgid, $gid, $searchLimit = 0) { $cids = array_keys(CRM_Contact_BAO_Group::getMember($gid, TRUE, $searchLimit)); @@ -263,7 +264,7 @@ class CRM_Dedupe_Finder { $supportedFields = CRM_Dedupe_BAO_RuleGroup::supportedFields($ctype); if (is_array($supportedFields)) { foreach ($supportedFields as $table => $fields) { - if ($table == 'civicrm_address') { + if ($table === 'civicrm_address') { // for matching on civicrm_address fields, we also need the location_type_id $fields['location_type_id'] = ''; // FIXME: we also need to do some hacking for id and name fields, see CRM-3902’s comments diff --git a/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php b/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php index 0666a70854..0e5f599a35 100644 --- a/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php +++ b/tests/phpunit/CRM/Dedupe/DedupeFinderTest.php @@ -22,6 +22,8 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { /** * Clean up after the test. + * + * @throws \CRM_Core_Exception */ public function tearDown() { @@ -60,6 +62,8 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { /** * Test duplicate contact retrieval with 2 email fields. + * + * @throws \CRM_Core_Exception */ public function testUnsupervisedWithTwoEmailFields() { $this->setupForGroupDedupe(); @@ -84,6 +88,8 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { * Test that a rule set to is_reserved = 0 works. * * There is a different search used dependent on this variable. + * + * @throws \CRM_Core_Exception */ public function testCustomRule() { $this->setupForGroupDedupe(); @@ -113,6 +119,8 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { /** * Test a custom rule with a non-default field. + * + * @throws \CRM_Core_Exception */ public function testCustomRuleWithAddress() { $this->setupForGroupDedupe(); @@ -142,6 +150,8 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { /** * Test rule from Richard + * + * @throws \CRM_Core_Exception */ public function testRuleThreeContactFieldsEqualWeightWIthThresholdtheTotalSumOfAllWeight() { $this->setupForGroupDedupe(); @@ -164,11 +174,13 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { ]); } $foundDupes = CRM_Dedupe_Finder::dupesInGroup($ruleGroup['id'], $this->groupID); - $this->assertEquals(1, count($foundDupes)); + $this->assertCount(1, $foundDupes); } /** * Test a custom rule with a non-default field. + * + * @throws \CRM_Core_Exception */ public function testInclusiveRule() { $this->setupForGroupDedupe(); @@ -191,7 +203,7 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { ]); } $foundDupes = CRM_Dedupe_Finder::dupesInGroup($ruleGroup['id'], $this->groupID); - $this->assertEquals(4, count($foundDupes)); + $this->assertCount(4, $foundDupes); CRM_Dedupe_Finder::dupes($ruleGroup['id']); } @@ -215,6 +227,8 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { /** * Test dupesByParams function. + * + * @throws \CRM_Core_Exception */ public function testDupesByParams() { // make dupe checks based on based on following contact sets: @@ -346,6 +360,8 @@ class CRM_Dedupe_DedupeFinderTest extends CiviUnitTestCase { /** * Set up a group of dedupable contacts. + * + * @throws \CRM_Core_Exception */ protected function setupForGroupDedupe() { $params = [ -- 2.25.1