Problem/Motivation

Refactor how to get the entity or module name

CommentFileSizeAuthor
#39 3169818-39.patch31.4 KBliuchanggang
#38 3169818-38.patch31.4 KBliuchanggang
#32 3169818-32.patch31.38 KBliuchanggang
#29 3169818-29.patch31.22 KBliuchanggang
#26 3169818-26.patch31.08 KBliuchanggang
#24 3169818-24.patch30.8 KBliuchanggang
#22 3169818-22.patch30.8 KBliuchanggang
#21 3169818-21.patch30.8 KBliuchanggang
#19 3169818-19.patch30.44 KBliuchanggang
#17 3169818-17.patch22.7 KBliuchanggang
#16 3169818-16.patch21.87 KBliuchanggang
#15 3169818-15.patch21.87 KBliuchanggang
#13 3169818-12.patch21.88 KBliuchanggang
#11 3169818-11.patch18.19 KBliuchanggang
#10 3169818-10.patch15.41 KBliuchanggang
#9 3169818-9.patch15.81 KBliuchanggang
#7 3169818-7.patch15.98 KBliuchanggang
#6 3169818-6.patch15.98 KBliuchanggang
#5 3169818-5.patch6.1 KBliuchanggang
#4 3169818-4.patch6.53 KBliuchanggang
#3 3169818-3.patch6.53 KBliuchanggang
#2 3169818-2.patch4.62 KBliuchanggang
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

liuchanggang created an issue. See original summary.

liuchanggang’s picture

This is just a test patch. Not ready for reveiw.

liuchanggang’s picture

FileSize
6.53 KB
liuchanggang’s picture

FileSize
6.53 KB

This is for test only.

liuchanggang’s picture

Status: Active » Needs review
FileSize
6.1 KB

This patch is ready for review. Thanks.

liuchanggang’s picture

FileSize
15.98 KB
liuchanggang’s picture

FileSize
15.98 KB

Status: Needs review » Needs work

The last submitted patch, 7: 3169818-7.patch, failed testing. View results

liuchanggang’s picture

FileSize
15.81 KB
liuchanggang’s picture

Status: Needs work » Needs review
FileSize
15.41 KB
liuchanggang’s picture

FileSize
18.19 KB
yas’s picture

@liuchanggang

Thank you for the refactoring. Is there any reason why you put the convert methods into CloudService? Could we place the methods to Drupal\cloud\Traits\CloudContentEntityTrait?

liuchanggang’s picture

FileSize
21.88 KB
liuchanggang’s picture

@yas

The methods are defined in CloudContentEntityTrait. However, there are a few places in .module files, where we can't call trait directly.
In that case, I called CloudServiceBase who USE CloudContentEntityTrait, so we can call those methods.

Let me know if there is better way to do.

Thanks

Chang

liuchanggang’s picture

FileSize
21.87 KB
liuchanggang’s picture

FileSize
21.87 KB

Rebased latest 3.x-dev.

liuchanggang’s picture

FileSize
22.7 KB

@yas,

I made following changes.

1, added method getLowerCaseSpace() and updated code
2, changed method name to getCamelCase()
3, added comments

Thanks

yas’s picture

Issue summary: View changes
Status: Needs review » Needs work
  1. +++ b/src/Traits/CloudContentEntityTrait.php
    @@ -188,7 +188,7 @@ trait CloudContentEntityTrait {
    -    return str_replace('_', ' ', $this->getModuleName($entity));
    +    return self::getLowerCaseSpace($this->getModuleName($entity));
    

    This can be replaced to getModuleNameWhitespace().

  2. +++ b/src/Traits/CloudContentEntityTrait.php
    @@ -533,4 +533,46 @@ trait CloudContentEntityTrait {
    +  public static function getUpperCaseSpace($words) {
    

    The method name can be getUpperCaseWithWhitespace().

    Also, the method can be used in the following methods:
    CloudContentEntityTrait::getShortEntityTypeNameWhitespace()
    CloudContentEntityTrait::getShortEntityTypeNamePluralCamel()
    CloudContentEntityTrait::getShortEntityTypeNameWhitespace()

  3. In that case, could you please refactor / aggregate the whole K8sFormTrait trait, too?
  4. +++ b/src/Traits/CloudContentEntityTrait.php
    @@ -533,4 +533,46 @@ trait CloudContentEntityTrait {
    +    return strtolower(str_replace('_', ' ', $words));
    

    strtolower() is required?

  5. +++ b/src/Traits/CloudContentEntityTrait.php
    @@ -533,4 +533,46 @@ trait CloudContentEntityTrait {
    +  public static function getCamelCase($words) {
    

    The method name can be getCamelCaseWithWhitespace().

  6. Please change the method from CloudContentEntityTrait::getModuleNameWhitespace() to CloudContentEntityTrait::getModuleNameWithWhitespace()
liuchanggang’s picture

FileSize
30.44 KB

@yas,
I have updated code by your comments.

Thanks

liuchanggang’s picture

Status: Needs work » Needs review
liuchanggang’s picture

liuchanggang’s picture

FileSize
30.8 KB
yas’s picture

Status: Needs review » Needs work
  1. +++ b/src/Traits/CloudContentEntityTrait.php
    @@ -533,4 +533,46 @@ trait CloudContentEntityTrait {
    +  public static function getWithWhitespace($words) {
    

    In this case, the method can be changeUndersocreToWhiteSpace().

  2. +++ b/src/Traits/CloudContentEntityTrait.php
    @@ -533,4 +533,46 @@ trait CloudContentEntityTrait {
    +  public static function getUpperCaseWithWhitespace($words) {
    

    The method name can be getCamelCaseWithWhiteSpace().

  3. +++ b/src/Traits/CloudContentEntityTrait.php
    @@ -533,4 +533,46 @@ trait CloudContentEntityTrait {
    +  public static function getCamelCaseWithoutWhitespace($words) {
    

    The method name can be getCamelCaseWithoutWhiteSpace().

  4. +++ b/src/Traits/CloudContentEntityTrait.php
    @@ -187,8 +187,8 @@ trait CloudContentEntityTrait {
    +  protected function getModuleNameWithWhitespace(EntityInterface $entity): string {
    +    return self::getWithWhitespace($this->getModuleName($entity));
    

    Please change the method name to getModuleNameWithWhiteSpace().

  5. Please check the coding standard violations: https://www.drupal.org/pift-ci-job/1819079
liuchanggang’s picture

Status: Needs work » Needs review
FileSize
30.8 KB

@yas,

I have updated the code. Thanks

yas’s picture

Status: Needs review » Needs work

@liuchanggang

Thank you for the update.

  1. +++ b/modules/cloud_service_providers/k8s/src/Traits/K8sFormTrait.php
    @@ -33,9 +36,7 @@ trait K8sFormTrait {
       protected function getShortEntityTypeNameWhitespace(CloudContentEntityBase $entity) {
    
    @@ -48,7 +49,7 @@ trait K8sFormTrait {
       protected function getShortEntityTypeNameCamel(CloudContentEntityBase $entity) {
    
    @@ -62,11 +63,7 @@ trait K8sFormTrait {
       protected function getShortEntityTypeNamePluralCamel(CloudContentEntityBase $entity) {
    

    Those methods are overlapped in CloudContentEntityTrait. Could you remove K8sFormTrait by aggregating those method? In that case, please consider the getShortEntityTypeNameUnderscore() as more generic function.

  2. +++ b/src/Traits/CloudContentEntityTrait.php
    @@ -533,4 +533,43 @@ trait CloudContentEntityTrait {
    +  public static function changeUndersocreToWhiteSpace($words) {
    

    On second thought, can you change the method name to convertUndersocreToWhiteSpace()?

liuchanggang’s picture

FileSize
31.08 KB

@yas,

Thanks for insight. I have updated the code.

liuchanggang’s picture

Status: Needs work » Needs review
yas’s picture

Status: Needs review » Needs work

@liuchanggang

Thank you for the update. In my comment #26,

Those methods are overlapped in CloudContentEntityTrait. Could you remove K8sFormTrait by aggregating those method? In that case, please consider the getShortEntityTypeNameUnderscore() as more generic function.

What about this refactoring? (Could you remove K8sFormTrait by aggregating those method? In that case, please consider the getShortEntityTypeNameUnderscore() as more generic function.)

liuchanggang’s picture

Status: Needs work » Needs review
FileSize
31.22 KB

@yas,
Thanks for reviewing. I misunderstood that line.

I just found that K8sFormTrait is not used anywhere in code base and all functions in K8sFormTrait have mirrors in CloudContentEntityTrait.
I have removed K8sFormTrait. Now all valid functions are in CloudContentEntityTrait.

yas’s picture

@liuchanggang

Thank you for the update. It looks good to me now. We need the test cases for the additional methods but we should create another issue.

@baldwinlouie

What do you think?

baldwinlouie’s picture

Status: Needs review » Needs work

@liuchanggang,

Thank you for the patch. I have the following comments.

  1. +++ b/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/ElasticIpAssociateForm.php
    @@ -493,7 +496,7 @@ class ElasticIpAssociateForm extends AwsDeleteForm {
    +    $cloud_name = self::convertUndersocreToWhiteSpace($module_name);
    
    +++ b/modules/cloud_service_providers/aws_cloud/src/Form/Ec2/SnapshotCreateForm.php
    @@ -159,7 +159,7 @@ class SnapshotCreateForm extends AwsCloudContentForm {
    +    $cloud_name = self::convertUndersocreToWhiteSpace($module_name);
    

    There is a typo in underscore

  2. +++ b/modules/cloud_service_providers/k8s/src/Service/K8sBatchOperations.php
    @@ -1010,7 +1012,7 @@ class K8sBatchOperations {
    +          $field_camel = lcfirst(self::getCamelCaseWithoutWhiteSpace($field));
    
    @@ -1316,7 +1318,7 @@ class K8sBatchOperations {
    +        $field_camel = lcfirst(self::getCamelCaseWithoutWhiteSpace($field));
    

    Do you think lcfirst should be an option for the getCamelCaseWithoutWhiteSpace method? That way, it can be reused in other places in the future.

liuchanggang’s picture

Status: Needs work » Needs review
FileSize
31.38 KB

@baldwinlouie @yas,

Thanks for insight. I have done following changes

Fixed underScore typo
Process lcfirst() in one function
Whitespace in one word.

yas’s picture

Status: Needs review » Needs work

@liuchanggang

Thank you for the update. It looks good to me now.

@baldwinlouie

What do you think?

yas’s picture

Status: Needs work » Needs review
baldwinlouie’s picture

Status: Needs review » Reviewed & tested by the community

@yas and @liuchanggang,

Looks good to me.

yas’s picture

@baldwinlouie

Thank you for your review.

@liuchangchang

Could you please create the patch for 8.x-1.x and 8.x-2.x?

yas’s picture

Status: Reviewed & tested by the community » Needs work
liuchanggang’s picture

liuchanggang’s picture

Status: Needs work » Needs review
yas’s picture

Status: Needs review » Reviewed & tested by the community

@liuchanggang

Thank you for the update. I'll merge the patch to 8.x-1.x, 8.x-2.x and 3.x and close this issue as Fixed.

  • yas committed 76ba81a on 8.x-1.x authored by liuchanggang
    Issue #3169818 by liuchanggang, yas, baldwinlouie: Refactor how to get...

  • yas committed e31d644 on 8.x-2.x authored by liuchanggang
    Issue #3169818 by liuchanggang, yas, baldwinlouie: Refactor how to get...

  • yas committed 3e072e4 on 3.x authored by liuchanggang
    Issue #3169818 by liuchanggang, yas, baldwinlouie: Refactor how to get...
yas’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.