Changing from abc_xyz() to getAbcXyz()

We focus on only "ERROR | Public method name abc_xyz is not in lowerCamel format" in this issue.

Comments

Xiaohua Guan created an issue. See original summary.

shidat’s picture

StatusFileSize
new202.14 KB

Add a big patch.

I changed owner() in entity classes such as Image to getFieldOwner(). The reason I didn’t changed it to getOwner() is that the method getOwner() has already existed in the interface EntityOwnerInterface which the class Image’s parent class CloudContentEntityBase implemented.

xiaohua guan’s picture

Status: Active » Needs review
deepanker_bhalla’s picture

Status: Needs review » Needs work

@shidat: Good work. I can confirm the patch #2 is applying cleanly. Here is the output:

❯ cloud/ 8.x-1.x* git apply -v 3017877-2.patch
Checking patch cloud.module...
Checking patch modules/cloud_server_template/cloud_server_template.module...
Checking patch modules/cloud_server_template/src/Controller/CloudServerTemplateAccessControlHandler.php...
Checking patch modules/cloud_server_template/src/Controller/CloudServerTemplateController.php...
...and more....
Applied patch cloud.module cleanly.
Applied patch modules/cloud_server_template/cloud_server_template.module cleanly.
Applied patch modules/cloud_server_template/src/Controller/CloudServerTemplateAccessControlHandler.php cleanly.
Applied patch modules/cloud_server_template/src/Controller/CloudServerTemplateController.php cleanly.
..and more...
_________________________________________________________________________________________________________

But after checking with phpcs --standard=Drupal cloud/....... I am getting some more issues i.e.

FILE: /var/www/html/tolearn/modules/git/cloud/css/cloud.css
-------------------------------------------------------------------------
FOUND 8 ERRORS AFFECTING 6 LINES
-------------------------------------------------------------------------
  13 | ERROR | [x] Whitespace found at end of line
 303 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 1
 303 | ERROR | [x] Whitespace found at end of line
 319 | ERROR | [x] Line indented incorrectly; expected 0 spaces, found 1
 319 | ERROR | [x] Whitespace found at end of line
 332 | ERROR | [x] Whitespace found at end of line
 343 | ERROR | [x] Expected 1 newline at end of file; 2 found
 344 | ERROR | [x] Additional whitespace found at end of file
-------------------------------------------------------------------------

FILE: /var/www/html/tolearn/modules/git/cloud/css/bootstrap.overrides.min.css
-----------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------
 1 | WARNING | File appears to be minified and cannot be processed
-----------------------------------------------------------------------------


FILE: /var/www/html/tolearn/modules/git/cloud/src/CloudContextInterface.php
----------------------------------------------------------------------------------------------------------------------
FOUND 10 ERRORS AFFECTING 9 LINES
----------------------------------------------------------------------------------------------------------------------
  3 | ERROR | [x] Namespaced classes, interfaces and traits should not begin with a file doc comment
  5 | ERROR | [ ] Doc comment short description must be on a single line, further text should be a separate paragraph
  7 | ERROR | [x] There must be one blank line after the namespace declaration
 10 | ERROR | [x] Missing interface doc comment
 13 | ERROR | [x] Doc comment short description must end with a full stop
 16 | ERROR | [x] Return comment indentation must be 3 spaces, found 2 spaces
 21 | ERROR | [x] Doc comment short description must end with a full stop
 24 | ERROR | [x] Parameter comment must end with a full stop
 27 | ERROR | [x] Expected 1 newline at end of file; 0 found
 27 | ERROR | [x] The closing brace for the interface must have an empty line before it
----------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/tolearn/modules/git/cloud/src/Form/CloudConfigForm.php
----------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------------------
 69 | WARNING | [x] A comma should follow the last multiline array item. Found: ]
----------------------------------------------------------------------------------\..

and many more............

yas’s picture

Issue summary: View changes
Status: Needs work » Needs review

@deepanker_bhalla

Thank you for your comment. Our team is fixing the coding standard error one by one, this issue makes lots of code changes, other than coding standard, therefore we decided to separate this refactoring task from the other coding standard errors. We focused on only "ERROR | Public method name "abc_xyz" is not in lowerCamel format" in this issue. I updated the description in this issue, too.

FYI, we won't fix *.css.

yas’s picture

@shidat

I reviewed the patch. You refactored getFieldOwner() however the method is used the only following code:

ImageDeleteForm.php

    $owner = $this->cloudConfigPluginManager->loadConfigEntity()->get('field_user_id')->value;

     // If the image isn't owned by the aws user, the calling for deregisterImage will be skipped.
    if($entity->getFieldOwner() != $owner || $this->awsEc2Service->deregisterImage([
      'ImageId' => $entity->getImageId()
    ]) != NULL) {

ImageEditForm.php

      '#default_value' => $entity->getFieldOwner(),

ImageListBuilder.php

    $row['owner'] = $entity->getFieldOwner();

In this case,

  1. getFieldOwner() is not used in the other class other than Drupal\aws_cloud\Form\Ec2\Image* class. Therefore can we remove getFieldOwner() EXCEPT Drupal\aws_cloud\Form\Ec2\Image* class?
  2. In Image* class, can we change field_user_id to aws_user_id? (field〜 is a prefix for Fields in Drupal web application framework? If not, can we change it to to aws_user_id?
yas’s picture

@shidat

Here is a typo inInstance.php

  public function setIsMonitoring($is_monitoring = FASE) {
yas’s picture

I prefer a combination of setSomething and isSomething as the naming convention. e.g.

  /**
   * {@inheritdoc}
   */
  public function isMonitoring() {
    return $this->get('is_monitoring')->value;
  }

  /**
   * {@inheritdoc}
   */
  public function setMonitoring($is_monitoring = FALSE) {
    return $this->set('is_monitoring', $is_monitoring);
  }
yas’s picture

Status: Needs review » Needs work
baldwinlouie’s picture

For the owner field, I think we can following AWS convention. In the AwsEc2Service.php file, when an Image is imported, we are actually looking for an "OwnerId" field. See this url: https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-images.html

Can we change it to getOwnerId(), setOwnerId($owner_id)?

shidat’s picture

StatusFileSize
new202.06 KB

@yas-san @baldwinlouie @deepanker_bhalla

Thanks for your reviews.

> I prefer a combination of setSomething and isSomething as the naming convention. e.g.
I changed code as you said.

> Therefore can we remove getFieldOwner() EXCEPT Drupal\aws_cloud\Form\Ec2\Image* class?
I removed the getFieldOwner() except Image* class.

> In Image* class, can we change field_user_id to aws_user_id?
Yes, I can changed the field name. But if I changed it, I think the existing drupal sites using cloud module can’t work. Do you have any idea about it?
And in the new patch file, I didn’t change the field name.

Please take a look at the new patch.

yas’s picture

@baldwinlouie

How about changing to getImageOwnerId() and setImageOwnerId($owner_id) to avoid the confusion since getOwnerId() and setOwnerId($owner_id) are already existing in Drupal APIs? Or can it be overlapped (merge) in between AWS Image owner-id and Drupal API owner id?

shidat’s picture

StatusFileSize
new202.07 KB

yas-san

> How about changing to getImageOwnerId() and setImageOwnerId($owner_id)
I changed method name from getFieldOwner and setFieldOwner to getImageOwnerId and setImageOwnerId.

Please take a look at the new patch file. Thanks.

xiaohua guan’s picture

xiaohua guan’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 13: 3017877-13.patch, failed testing. View results

shidat’s picture

StatusFileSize
new202.61 KB

Due to the other commit, the old patch file couldn’t be applied. Therefore I provide a new one. Please take a look, thanks.

xiaohua guan’s picture

xiaohua guan’s picture

Status: Needs work » Needs review
yas’s picture

Status: Needs review » Needs work

@shidat

As I mentioned at comment #7, here is a typo inInstance.php

  public function setIsMonitoring($is_monitoring = FASE) {
shidat’s picture

StatusFileSize
new202.61 KB

Oops, sorry for my miss.

xiaohua guan’s picture

xiaohua guan’s picture

Status: Needs work » Needs review

  • yas committed 210cd85 on 8.x-1.x authored by shidat
    Issue #3017877 by shidat, Xiaohua Guan, yas, baldwinlouie: Fix code...
yas’s picture

Status: Needs review » Fixed

@shidat

Thank you for fixing it. I merged the patch and closed this issue.

Status: Fixed » Closed (fixed)

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