CommentFileSizeAuthor
#54 contact-coder-1533112-54.patch31.96 KBmcdruid
#49 contact-coder-1533112-49.patch31.85 KBherom
#49 interdiff-1533112-44-49.txt5.87 KBherom
#44 core-contact-coderstandards-1533112-9111357.patch28.02 KBblattmann
#40 core-make_contact_module_pass_coder_review-1533112-40.patch27.95 KBherom
#40 interdiff-bad-reroll.txt4.24 KBherom
#38 core-make_contact_module_pass_coder_review-1533112-38.patch30.21 KBherom
#38 interdiff-1533112-36-38.txt6.38 KBherom
#36 core-make_contact_module_pass_coder_review-1533112-36.patch25.76 KBherom
#36 interdiff-1533112-34-36.txt753 bytesherom
#34 core-make_contact_module_pass_coder_review-1533112-34.patch25.3 KBherom
#34 interdiff-1533112-33-34.txt3.05 KBherom
#33 core-make_contact_module_pass_coder_review-1533112-33.patch26.34 KBAnonymous (not verified)
#31 interdiff-1533112-31.txt7.44 KBmajoely
#31 core-make_contact_module_pass_coder_review-1533112-31.patch30.83 KBmajoely
#29 interdiff.txt7.18 KBmajoely
#29 core-make_contact_module_pass_coder_review-1533112-29.patch30.57 KBmajoely
#24 drupal-make_contact_module_pass_coder_review-1533112-24.patch28.83 KBJalandhar
#21 drupal8.contact-module.1533112-20.patch25.79 KBTravisCarden
#21 interdiff.txt1.42 KBTravisCarden
#18 drupal8.other_.1518116-71.patch25.56 KBTravisCarden
#18 interdiff.txt5.64 KBTravisCarden
#12 drupal8.contact-module.1533112-12.patch27.62 KBTravisCarden
#6 drupal-contact-coder-cleanup-1533112-6.patch23.94 KBramlev
#5 drupalcs.txt4.78 KBTravisCarden
#4 drupal-1533112-4.patch3.57 KBroborn
#1 drupal-1533112-1.patch3.32 KBTravisCarden
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TravisCarden’s picture

Title: Make [module or directory] pass Coder Review » Make Contact module pass Coder Review
Status: Active » Needs review
FileSize
3.32 KB

Drupal Code Sniffer reports the following, but I suspect it is to be ignored in core. (If someone can confirm, I'll file an issue against the sniffer about it.)

FILE: /home/quickstart/websites/d8.dev/core/modules/contact/contact.pages.inc
--------------------------------------------------------------------------------
FOUND 2 ERROR(S) AFFECTING 2 LINE(S)
--------------------------------------------------------------------------------
 131 | ERROR | global variables should start with a single underscore followed
     |       | by the module and another underscore
 261 | ERROR | global variables should start with a single underscore followed
     |       | by the module and another underscore
--------------------------------------------------------------------------------
NROTC_Webmaster’s picture

That is correct according to the coding standards see http://drupal.org/coding-standards#naming

Although I don't know if this should actually be changed or not.

TravisCarden’s picture

roborn’s picture

FileSize
3.57 KB

Errors in #1 don't show up anymore.
Only these:

FILE: /Sites/htdocs/d8review/core/modules/contact/contact.pages.inc
--------------------------------------------------------------------------------
FOUND 2 ERROR(S) AND 2 WARNING(S) AFFECTING 4 LINE(S)
--------------------------------------------------------------------------------
  84 | ERROR   | Expected "if (...) {\n"; found "if (...){\n"
 191 | WARNING | A comma should follow the last multiline array item. Found: ]
 248 | ERROR   | Expected "if (...) {\n"; found "if (...){\n"
 335 | WARNING | A comma should follow the last multiline array item. Found:
     |         | name
--------------------------------------------------------------------------------

Updated the patch to fix it.

TravisCarden’s picture

FileSize
4.78 KB

Thanks for the patch, @roborn.

  1. +++ b/core/modules/contact/contact.admin.inc
    @@ -40,10 +40,12 @@ function contact_category_list() {
    -    $rows[] = array(array(
    -      'data' => t('No categories available.'),
    -      'colspan' => 5,
    -    ));
    +    $rows[] = array(
    +      array(
    +        'data' => t('No categories available.'),
    +        'colspan' => 5,
    +      ),
    +    );
    

    I'm skeptical about this change. I realize I originally introduced it, but coming back to it, I don't see its necessity; so if drupalcs complains about it, I think drupalcs might need to be adjusted. What does everyone else think?

  2. +++ b/core/modules/contact/contact.admin.inc
    @@ -57,7 +59,7 @@ function contact_category_list() {
    - * @param $category
    + * @param array $category
    
    +++ b/core/modules/contact/contact.admin.inc
    @@ -186,7 +188,7 @@ function contact_category_edit_form_submit($form, &$form_state) {
    - * @param $contact
    + * @param array $contact
    

    Adding @param and @return types has been excluded from this effort, to be handled in a separate issue. See "Proposed resolution" #5 in the meta issue.

  3. Drupalcs actually has quite a few more complaints about new files in the module. (See attachment.) I know that some of them are false positives. Some of them I'm not qualified to comment on.

I'm going to leave this in "Needs review" pending comment from someone more knowledgeable than I. We may need to make further changes to the sniffer before we can productively proceed. We'll see.

ramlev’s picture

I have checked the complete contact module, and it doesn't output any codesniffer errors.

TravisCarden’s picture

Thank you, @ramlev, but this patch has the same problems. Please read comment #5.

ramlev’s picture

About #5.1. and the output of the array, i dont really see the issue here, i think it more readable as done in the patch. I can agree with you if the array is done with

$rows[] = [[x, y, z]];

#5.2 - No need for splitting it up in two issues, since we're handling the file already and it's such small a fix.

TravisCarden’s picture

Status: Needs review » Postponed

Thank you, @ramlev. We'll see what others have to say on #5.1. Concerning #5.2, the decision has been made by those who will be reviewing and committing the patches. It's not up for discussion. I'm postponing this issue for now.

Lars Toomre’s picture

When the patch for this issue is next re-rolled, please remember to include a blank line before the closing brace in the declaration of the class in the files ContactAuthenticatedUserTest.php and ContactPersonalTest.php.

sphism’s picture

Status: Postponed » Active

We have the go ahead with all these issues again, see #1518116: [meta] Make Core pass Coder Review for more details

TravisCarden’s picture

Assigned: TravisCarden » Unassigned
Status: Active » Needs review
FileSize
27.62 KB

All right, now that the codebase is wildly different, here's another patch. :) Note: It can be helpful, to reduce the "noise" in the patch review, to apply the patch to a local repository and use git diff --word-diff to show only the characters that have changed, rather than the entire lines.

sphism’s picture

I'll take a look at this and review it today

sphism’s picture

Just downloaded and applied the patch successfully.

contact.module looks good to me

contact.pages.inc looks good too

CategoryListController.php: should the function declarations within a Class have @param and @return documentation?

MessageFormController.php:

// For the e-mail message, clarify that the sender name is not verified;
// it could potentially clash with a username on this site.

not really sure what the point of the ';' is here, probably makes more sense to say "...sender name is not verified as it could potentially ..."
Other than that it's good

Message.php is good

ContactAuthenticatedUserTest.php: I'm not sure about how this stuff is meant to be written so can't really review it, but I think it's correct... OK, according to this php documentation http://php.net/manual/en/language.oop5.visibility.php if you declare a function within a class without declaring it as public, protected or private, then it IS public, so adding the keyword 'public' is probably best practice - i'd say this is all good.

ContactPersonalTest: This one is interesting.... not sure i can review it, it seems correct to me but can someone else please review

ContactSitewideTest: good

ContactUpgradePathTest: good

MessageEntityTest: good

ContactFieldsTest: good

ContactLinkTest: good

drupal-7.contact.database: good

contact_test_views: why do we need an empty file? The changes are good, but seems redundant.

When I run drupalcs on command line I still get a lot of errors, most of them seem to be due to:

/**
   * {@inheritdoc}
   */

Not starting with a capital letter, and not ending with a full stop (period). Has this been filed as an issue with Coder project?

The only other issues I see are the array declarations in ContactSitewideTest.php

I think we should split out the arrays onto multiple lines, the issues are on lines; 98, 111, 148, 219 and 276 - although I'm happy to leave these for the time being since no one's really sure what they are meant to look like :)

Great work @traviscarden, if you can convince me about those few things I'm not sure about (eg private vs protected) i'll mark it RTBC

TravisCarden’s picture

Re: class methods having @param and @return directives, yes they should, unless said methods are overriding other methods on base classes--in which case the overridden methods should have that documentation.

Re: method visibility, your assessment is correct. Unspecified methods are treated as public, so my approach has been to just explicitly mark them as such, since doing so makes no functional changes (and since this initiative is about documentation, not functionality, that's how I try to play it until a more senior contributor tells me otherwise).

Re: the empty module file, unless I'm mistaken Drupal doesn't treat something as a module unless it has a .module file--even if it's empty--so that file is necessary.

Re: the @inheritdoc comments, make sure you're using the latest version of Coder Sniffer--it has support for those. See the installation guide. I cloned the coder repo in my ~/.drush directory and git pull regularly to make sure I have the latest changes. Then I can run drush dcs . in any directory on my machine without any bash aliases or fancy business.

Re: multi-line array declarations, trust me when I say that making an issue out of that is a good way to get this initiative stalled again. :) That's been a contentious topic, and there's a separate issue for it now, so it's best to just patch Coder Sniffer per #1518116-69: [meta] Make Core pass Coder Review to omit the sniff and move forward.

sphism’s picture

Status: Needs review » Reviewed & tested by the community
jhodgdon’s picture

Status: Reviewed & tested by the community » Needs work

This change is incorrect:

+  /**
+   * {@inheritdoc}
+   */
   public static function getInfo() {

On tests, the getInfo() method does *not* get any documentation. period. Nor setUp(), or tearDown(). If Coder is saying they need docs, Coder is wrong.

I also don't think generally that we are using camelCase for member variables in classes, are we? I'd like to know whether (a) that's the standard or (b) it's generally followed in Core before we try to "fix" this all over core.

+++ b/core/modules/contact/lib/Drupal/contact/Tests/ContactPersonalTest.php
@@ -26,22 +26,25 @@ class ContactPersonalTest extends WebTestBase {
    *
    * @var object
    */
-  private $admin_user;
+  protected $adminUser;
TravisCarden’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
5.64 KB
25.56 KB
  1. Coder Sniffer does indeed complain about the absense of doc comments on getInfo(), setUp(), and tearDown() on test classes. I see there's already an issue to fix this: #1805550: Modify sniff for "Missing function doc comment" for test classes. Is there documentation of this matter that can be referenced there? How does #338403: Use {@inheritdoc} on all class methods (including tests) relate to all this? In any case, I've removed those changes from my patch.
  2. Per our Object-oriented code naming conventions, "Methods and class properties should use lowerCamel naming."

Can I set this back to RTBC?

Status: Reviewed & tested by the community » Needs work

The last submitted patch, drupal8.other_.1518116-71.patch, failed testing.

jhodgdon’s picture

RE #18:
1. Yes that other issue would be good to decide on a more consistent standard, but it isn't decided and has been sitting for months. The current standard is at https://drupal.org/node/325974

2. What I was trying to say was that camelCase for class properties is I think one of those "standards" that has been formally adopted but that most of core doesn't comply with (I think). In cases like that we need to consider whether complying with the adopted standard is a better idea than revising the standard. I'd like to see a survey of class properties in Core to see how many are camel and how many use underscores... but my guess is that we're mostly using underscores and it would be better to change the standard to match what we're doing than to try to enforce a standard that no one follows.

TravisCarden’s picture

Status: Needs work » Needs review
FileSize
1.42 KB
25.79 KB

Hmm. My IDE missed a couple of variables. (That's disconcerting.) Let's try this again.

TravisCarden’s picture

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

The patch no longer applies. For whomever rerolls it, please consider the following common issues I've been seeing in this meta issue:

Jalandhar’s picture

Assigned: Unassigned » Jalandhar
Jalandhar’s picture

Status: Needs work » Needs review
FileSize
28.83 KB

Attaching the patch which fixes all coder reviews. Please review it.

Jalandhar’s picture

Assigned: Jalandhar » Unassigned
majoely’s picture

Assigned: Unassigned » majoely
Status: Needs review » Needs work

I applied the patch and got an issue with the following:
Patch Failed
core/modules/contact/lib/Drupal/contact/Tests/ContactPersonalTest.php:50
core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php:118
patch does not apply
core/modules/contact/lib/Drupal/contact/Tests/ContactPersonalTest.php
core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php

I will look into it and repost soon.

majoely’s picture

Assigned: majoely » Unassigned

I found a couple of things that didn't tie up in the ContactPersonalTest portion of the patch that I found different to the file itself.

1. Line 58 of the 8.x file has four parameters in it were as the path only has three:

-    $this->admin_user = $this->drupalCreateUser(array('administer contact forms', 'administer users', 'administer account settings'));
$this->admin_user = $this->drupalCreateUser(array('administer contact forms', 'administer users', 'administer account settings', 'access site reports'));

2. Line 90 to 102 in the 8.x file is entirely missing from the patch

// Check there was no problems raised during sending.
    $this->drupalLogout();
    $this->drupalLogin($this->admin_user);
    // Verify that the correct watchdog message has been logged.
    $this->drupalGet('/admin/reports/dblog');
    $placeholders = array(
    '@sender_name' => $this->web_user->username,
    '@sender_email' => $this->web_user->getEmail(),
    '@recipient_name' => $this->contact_user->getUsername()
    );
    $this->assertText(String::format('@sender_name (@sender_email) sent @recipient_name an e-mail.',    $placeholders));
    }

I started throwing myself down a rabit hole so I stopped looking because I am not sure whether these are errors in the patch or a result of my naive understaing of patches.

majoely’s picture

Assigned: Unassigned » majoely

Ok so I slept on it and finished an essay and had an idea, so I will try to create a new patch by removing and redoing the bits that I have problems with.

majoely’s picture

Assigned: majoely » Unassigned
Status: Needs work » Needs review
FileSize
30.57 KB
7.18 KB

I have created a new patch for this issue by.

  • Removing the parts of the patch that were causing the issue
  • Applying the patch
  • Redoing the parts of the patch that were causing the issues
  • Finally running the coder review tool again to double check

Status: Needs review » Needs work

The last submitted patch, 29: core-make_contact_module_pass_coder_review-1533112-29.patch, failed testing.

majoely’s picture

Attempt two to pass the tests.

majoely’s picture

Status: Needs work » Needs review
Anonymous’s picture

Patch #31 needed a reroll, attaching new patch.

herom’s picture

Status: Needs review » Needs work

The last submitted patch, 34: core-make_contact_module_pass_coder_review-1533112-34.patch, failed testing.

herom’s picture

Status: Needs work » Needs review
FileSize
753 bytes
25.76 KB

missed that one.

Jalandhar’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Patch #36, no longer applies. It needs reroll.

Status: Needs review » Needs work

The last submitted patch, 38: core-make_contact_module_pass_coder_review-1533112-38.patch, failed testing.

herom’s picture

Status: Needs work » Needs review
FileSize
4.24 KB
27.95 KB

sorry, bad reroll.

Status: Needs review » Needs work

The last submitted patch, 40: core-make_contact_module_pass_coder_review-1533112-40.patch, failed testing.

Status: Needs work » Needs review
blattmann’s picture

Issue tags: +Amsterdam2014

I am reviewing/rerolling this now. Patch in #40 does not apply to HEAD right now.

blattmann’s picture

I've rerolled the patch manually.

Status: Needs review » Needs work

The last submitted patch, 44: core-contact-coderstandards-1533112-9111357.patch, failed testing.

herom’s picture

It failed with the "Too many connections" errors. I'll retest to see how it goes.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 44: core-contact-coderstandards-1533112-9111357.patch, failed testing.

herom’s picture

Fixing the test, and a couple more coder issues.

blattmann’s picture

@herom, is there anything else I can do to help on this? i.e. What needs to happen now?

herom’s picture

You can do a review by running Coder against the contact module, to see if any errors are remaining. The parent issue explains how to do that:

Clone TravisCarden's fork of Coder module, which has been modified for this initiative (git clone --branch=issue-1518116 git@github.com:TravisCarden/coder.git) and install it according to the project's instructions.
Run Coder Sniffer against the relevant directory or files, e.g., drush dcs includes/.

Just a note that Coder Sniffer might mark some /** @var lines as error, but that is a false-positive.

You can also look at the patch to see if all the changes are correct.

If you didn't find any issues with the above, you can mark the issue as RTBC.

jsobiecki’s picture

Issue tags: -Amsterdam2014 +dcwroc2014
mcdruid’s picture

Assigned: Unassigned » mcdruid
Issue tags: +Needs reroll
mcdruid’s picture

Issue tags: -Needs reroll
FileSize
31.96 KB

Re-rolled patch.

Only conflict was addition of the $third_party_settings argument to the addContactForm function:

< -  function addContactForm($id, $label, $recipients, $reply, $selected) {
< +  public function addContactForm($id, $label, $recipients, $reply, $selected) {
---
> -  function addContactForm($id, $label, $recipients, $reply, $selected, $third_party_settings = []) {
> +  public function addContactForm($id, $label, $recipients, $reply, $selected, $third_party_settings = []) {
mcdruid’s picture

Assigned: mcdruid » Unassigned
xjm’s picture

Version: 8.0.x-dev » 8.1.x-dev
Priority: Normal » Minor
Status: Needs review » Postponed
Issue tags: -Novice

Thanks for all the work here so far. See #1518116-86: [meta] Make Core pass Coder Review. This issue is postponed until the meta issue is either closed or reopened.

pfrenssen’s picture

Status: Postponed » Closed (duplicate)

Closing in favor of #2571965: [meta] Fix PHP coding standards in core. In this issue the coding standards will be fixed on a sniff-per-sniff basis rather than a module-per-module basis.