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] Move daoName generation so we don't need to pass the variable name #18552

Merged
merged 1 commit into from
Sep 22, 2020

Conversation

eileenmcnaughton
Copy link
Contributor

@eileenmcnaughton eileenmcnaughton commented Sep 22, 2020

Overview

Minor code cleanup - rather than pass around the name of the dao class just figure it out from the entity name when needed. This has the added benefit that we can declare the class in a way IDEs recognise

Before

 public function copyDataToNewBlockDAO(string $daoName, $otherBlockId, $name, $blkCount) {

After

  public function copyDataToNewBlockDAO($otherBlockId, $name, $blkCount) {

Technical Details

$name is the name of the entity - I thought about renaming but in follow up patches I can remove most references to it so I've left for now

Comments

Note that we can remove some variables now - I've excluded from this PR as they clash with #18500

@civibot
Copy link

civibot bot commented Sep 22, 2020

(Standard links)

@@ -1820,7 +1820,7 @@ public static function mergeLocations($mergeHandler) {
if (!$otherBlockId) {
continue;
}
$otherBlockDAO = $mergeHandler->copyDataToNewBlockDAO($daoName, $otherBlockId, $name, $blkCount);
$otherBlockDAO = $mergeHandler->copyDataToNewBlockDAO($otherBlockId, $name, $blkCount);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like line 1812 above (which defines the now-unused variable $daoName) is no longer needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@colemanw - yes - removing that in this PR makes it confllct with the one in the PR template

Comment on lines +238 to +257
switch ($entity) {
case 'email':
return new CRM_Core_DAO_Email();

case 'address':
return new CRM_Core_DAO_Address();

case 'phone':
return new CRM_Core_DAO_Phone();

case 'website':
return new CRM_Core_DAO_Website();

case 'im':
return new CRM_Core_DAO_IM();

default:
// Mostly here, along with the switch over a more concise format, to help IDEs understand the possibilities.
throw new CRM_Core_Exception('Unsupported entity');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I just removed a long switch statement like this in #18546. Aside from the $entity being the nonstandard lowercase, is there any reason not to do it this way?

Suggested change
switch ($entity) {
case 'email':
return new CRM_Core_DAO_Email();
case 'address':
return new CRM_Core_DAO_Address();
case 'phone':
return new CRM_Core_DAO_Phone();
case 'website':
return new CRM_Core_DAO_Website();
case 'im':
return new CRM_Core_DAO_IM();
default:
// Mostly here, along with the switch over a more concise format, to help IDEs understand the possibilities.
throw new CRM_Core_Exception('Unsupported entity');
}
return CRM_Core_DAO_AllCoreTables::getFullName(CRM_Core_DAO_AllCoreTables::convertEntityNameToCamel($entity, TRUE));

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@colemanw yeah - the follow on patches do more by adding extra variables in there

As an aside, I think a switch in it's own function is not bad for readability - it's the long switch in the midst of a function that is

@colemanw colemanw merged commit aaa8790 into civicrm:master Sep 22, 2020
@colemanw
Copy link
Member

Ok I'll trust you on this one.

@colemanw colemanw deleted the ref branch September 22, 2020 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants