This is a sub-issue of #1800046: [META] Add missing type hinting to core docblocks, fix Drupal.Commenting.FunctionComment.Missing* focused on correctly adding @param and @return type hinting to the Filter module.

Documentation patches that include type hinting are time consuming to both review and commit because one must dig into the actual code to confirm that the type hints are both correct and complete. Hence, please be patient and try to limit type hint patches to covering only a limited number of docblocks (20-25 as a guess).

How To Review This Issue

  1. Attempt to apply the patch to see if it needs a reroll.
  2. Use the phpcs one-liner to evaluate whether all the relevant standards errors have been resolved: https://gist.github.com/paul-m/227822ac7723b0e90647
  3. Look at each change and determine whether the type hint is correct.

Related sprint issues:

Sprint Topic Sub Issue
#1518116: [meta] Make Core pass Coder Review #1533238: Make filter module pass Coder Review
#1310084: [meta] API documentation cleanup sprint #1347914: Clean up API docs for Filter module
#500866: [META] remove t() from assert message #1797272: Remove t() from asserts messages in tests for the filter module

Comments

lars toomre’s picture

Status: Active » Postponed

Marking as postponed until D8 change in #1347914: Clean up API docs for Filter module are committed to D8.

mile23’s picture

mile23’s picture

Status: Postponed » Active

#1347914: Clean up API docs for Filter module is marked fixed, and even backported to D7.

phpcs tells me there are 'Missing parameter type' errors in filter.module, FilterUnitTest.php, and filter.api.php.

So I'm setting this as active.

mile23’s picture

Status: Active » Needs review
StatusFileSize
new5.12 KB

Patch.

Status: Needs review » Needs work

The last submitted patch, 4: 1811328_4.patch, failed testing.

mile23’s picture

Status: Needs work » Needs review

The last patch only changed docblocks, so I'm going to re-run the testbot.

Mile23 queued 4: 1811328_4.patch for re-testing.

mile23’s picture

Still applies, still no missing type hinting according to phpcs.

mile23’s picture

Still applies.

mile23’s picture

Issue summary: View changes
rishikant05’s picture

Assigned: Unassigned » rishikant05
rishikant05’s picture

This patch is working.

rishikant05’s picture

Assigned: rishikant05 » Unassigned
Issue tags: +SprintWeekend2015
mile23’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Needs review » Needs work
Issue tags: +Needs reroll

Bumping to 8.1.x. Patch no longer applies.

sushyl’s picture

StatusFileSize
new4.15 KB

[8.1.x-dev] Updated Patch.

sushyl’s picture

Status: Needs work » Needs review
claudiu.cristea’s picture

Version: 8.1.x-dev » 8.0.x-dev

Sorry, I think docs-only patches should go ASAP in HEAD. That's because they are non-invasive and they cannot break anything but, in the same time, are helping a lot the developers that are porting modules and also are improving the DX in most of IDEs.

jhodgdon’s picture

Yes, should be 8.0.x for sure.

naveenvalecha’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs reroll

Patch sucessfully applied on 8.0.x
phpcs reports nothing.All looks good to be in. Thanks!


$ phpcs --standard="Drupal" --extensions="module,install,php" --report-csv core/modules/filter/ | grep -F $'Missing param\nReturn type missing'
jhodgdon’s picture

Status: Reviewed & tested by the community » Needs work

These patches need to be reviewed VERY CAREFULLY, looking at the code, to make sure that the types that are added are correct.

The review here was not quite careful enough, and this patch is not quite right:

+++ b/core/modules/filter/filter.api.php
@@ -48,7 +48,7 @@ function hook_filter_secure_image_alter(&$image) {
- * @param $format
+ * @param object $format
  *   The format object of the format being disabled.
  */
 function hook_filter_format_disable($format) {

The type here is incorrect.

$format is actually an object of type FilterFormat. So the type should be listed as

\Drupal\filter\FilterFormatInterface

not "object".

sushyl’s picture

StatusFileSize
new4.04 KB

Good catch @jhodgdon!
I see what you're talking about here. I really wonder how you could find such a small mistake. (Respect)

Fixed the patch, re-uploading.

jhodgdon’s picture

Status: Needs work » Reviewed & tested by the community

Thanks!

claudiu.cristea’s picture

Status: Reviewed & tested by the community » Needs work

Nice docs cleanup. Let's fix then the rest of module too, not only procedural functions :)

  1. \Drupal\filter\Element\TextFormat::currentUser()
      /**
       * Wraps the current user.
       *
       * \Drupal\Core\Session\AccountInterface
       */
    

    Missing the @return tag.

  2. \Drupal\filter\Plugin\FilterInterface::getHTMLRestrictions()
    @return array|FALSE
    

    Should be false (lowercase)

  3. \Drupal\filter\Tests\FilterAPITest::setUp()
    Missing doc-block. Only {@inheritdoc}
  4. \Drupal\filter\Tests\FilterCrudTest::verifyTextFormat()
      /**
       * Verifies that a text format is properly stored.
       */
    

    Missing @param and the function should be protected.

  5. \Drupal\filter\Tests\FilterDefaultConfigTest::setUp()
    Missing doc-block. Only {@inheritdoc}
  6. \Drupal\filter\Tests\FilterFormatAccessTest::setUp()
    Missing doc-block. Only {@inheritdoc}
  7. \Drupal\filter\Tests\FilterFormTest::$adminUser
    and
    \Drupal\filter\Tests\FilterFormTest::$webUser
    @var \Drupal\user\Entity\User
    

    Both should be \Drupal\user\UserInterface

  8. \Drupal\filter\Tests\FilterHtmlImageSecureTest::setUp()
    Missing doc-block. Only {@inheritdoc}
  9. \Drupal\filter\Tests\FilterSecurityTest::setUp()
    Missing doc-block. Only {@inheritdoc}
  10. \Drupal\filter\Tests\FilterUnitTest::setUp()
    Missing doc-block. Only {@inheritdoc}
  11. \Drupal\filter\Tests\FilterUnitTest::assertFilteredString()
    /**
       * Asserts multiple filter output expectations for multiple input strings.
       *
       * @param FilterInterface $filter
       *   A input filter object.
       * @param $tests
       *   An associative array, whereas each key is an arbitrary input string and
       *   each value is again an associative array whose keys are filter output
       *   strings and whose values are Booleans indicating whether the output is
       *   expected or not.
       *
    ...
       */
    

    FilterInterface should be full qualified. @param $tests missing typehint.

  12. \Drupal\filter\FilterFormatInterface::getHtmlRestrictions()
    @return array|FALSE
    Should be false (lowercase)
  13. \Drupal\filter\FilterProcessResult::setProcessedText()
    @return $this
    This is wrong. We should show the type-hint not the value. Replace $this with \Drupal\filter\FilterProcessResult
  14. \Drupal\Tests\filter\Unit\Plugin\migrate\source\d6\FilterFormatTest::PLUGIN_CLASS
    \Drupal\Tests\filter\Unit\Plugin\migrate\source\d6\FilterFormatTest::$migrationConfiguration
    \Drupal\Tests\filter\Unit\Plugin\migrate\source\d6\FilterFormatTest::$expectedResults
    Missing doc-block.
  15. \Drupal\Tests\filter\Unit\Plugin\migrate\source\d7\FilterFormatTest::PLUGIN_CLASS
    \Drupal\Tests\filter\Unit\Plugin\migrate\source\d7\FilterFormatTest::$migrationConfiguration
    \Drupal\Tests\filter\Unit\Plugin\migrate\source\d7\FilterFormatTest::$expectedResults
    Missing doc-block.
jhodgdon’s picture

Status: Needs work » Reviewed & tested by the community

Regarding #23, this issue needs to stay focused ONLY on fixing missing type hinting, not in fixing up other problems in doc blocks. See
https://www.drupal.org/core/scope

It doesn't look like the issues raised in #23 are in scope for this issue. Please open separate issues for them... although several are incorrect. For instance, we do want to have doc blocks that are just "inheritdoc" and @return $this is correct to use... Please take a look at https://www.drupal.org/node/1354 for documentation standards and read the Issue Scope page linked above before filing more issues about those items... thanks!

Meanwhile, this issue is complete for its scope. See #19 where the coder rule came up clean...

  • catch committed 16f0342 on 8.1.x
    Issue #1811328 by sushyl, Mile23: Add missing type hinting to Filter...

  • catch committed dc587e3 on 8.0.x
    Issue #1811328 by sushyl, Mile23: Add missing type hinting to Filter...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.1.x and cherry-picked to 8.0.x, thanks!

Status: Fixed » Closed (fixed)

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