Problem/Motivation

The code of the Gettext component is not consistent with the current Drupal coding and documentation standards.

Proposed resolution

Fix the docblock comments of the Gettext related files in Locale module.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sutharsan created an issue. See original summary.

Sutharsan’s picture

Assigned: Sutharsan » Unassigned
Status: Active » Needs review
FileSize
10.49 KB

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

This patch still applies (but not cleanly) and everything that is being changed in it looks solid.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/locale/src/LocaleDefaultConfigStorage.php
    @@ -56,6 +56,8 @@ class LocaleDefaultConfigStorage {
    +   * @param $install_profile
    

    @param string $install_profile

  2. +++ b/core/modules/locale/src/LocaleDefaultConfigStorage.php
    @@ -98,7 +100,7 @@ public function read($name) {
    -   *   List of configuration in install storage and current languages.
    +   *   List of configuration names.
    
    @@ -142,7 +144,7 @@ public function getComponentNames($type, array $list) {
    -   *   The list of configuration names that match predefined languages.
    +   *   List of configuration names.
    

    I don't really understand how this improves the documentation.

  3. +++ b/core/modules/locale/src/PoDatabaseReader.php
    @@ -71,6 +74,11 @@ public function getOptions() {
    +   * @see self::options
    

    Whilst there are other examples in core this doesn't work in PHPStorm or on https://api.drupal.org/api/drupal/core%21modules%21book%21src%21Form%21B...

    Should be a fully qualified class name here.

  4. +++ b/core/modules/locale/src/StringDatabaseStorage.php
    @@ -314,8 +314,8 @@ protected function dbStringKeys($string) {
    -   * @return \Drupal\locale\StringInterface[]
    -   *   Array of objects of the class requested.
    +   * @return array
    +   *   Array of objects of the requested class.
    

    This looks like a regression too. In fact we probably ought to assert that class implements StringInterface since we rely on it.

Sutharsan’s picture

A re-reroll to begin with...

Sutharsan’s picture

Status: Needs work » Needs review
FileSize
2.71 KB
8.99 KB

Comments in #5 addressed:

@param string $install_profile

Yes. Corrected.

I don't really understand how this improves the documentation.

I prefer keep my @param and @return short and not to copy (too much of) the function description. But not important enough, so reverted.

* @see self::options

Removed from the patch. No other getters and setters in this class use an @see referencing to their property (any more?).

This looks like a regression too

Agree, removed from the patch.

we probably ought to assert that class implements StringInterface since we rely on it

Agree, but not in this issue. It is about documentation.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

The changes look solid, and I agree that the assertion is something that we should do in a followup. Can you open a followup for that @Sutharsan?

Sutharsan’s picture

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/locale/src/StringDatabaseStorage.php
@@ -533,6 +533,13 @@ protected function dbDelete($table, $keys) {
+   * @return \Drupal\Core\Database\StatementInterface|int|null

This needs a comment, other than that, looks good to me

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Sutharsan’s picture

Re-rolled the #7 patch.

Sutharsan’s picture

Status: Needs work » Needs review
FileSize
752 bytes
9.02 KB

Comment added as per #11.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

joachim’s picture

Status: Needs review » Reviewed & tested by the community

LGTM.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

xjm’s picture

Title: Complete docblock comments in Gettext related files in Locale module. » Add missing parameter and return documentation for Gettext
Version: 9.1.x-dev » 8.8.x-dev
Status: Reviewed & tested by the community » Needs work

Thanks for your work on this.

Typically, we shouldn't fix "all the problems" in one module. We should fix the individual kinds of errors, across all of core, and then enable the phpcs rule for that kind of error to avoid the rule regressing. This patch includes a grab-bag of the following kinds of coding standards issues:

  • Missing @param
  • Missing @throws
  • Missing @return
  • Missing blank lines
  • Incorrect data types in docblock typehints
  • Adding the s to the one-summary verb
  • Grammatical errors

Now, writing new @param and @return documentation requires humans reading and understanding the code, so it makes sense to add them together in one patch for a given API. However, it makes less sense to mix in rewrites of existing parameter documentation, whitespace fixes, etc. I have to open all the files in this patch to review the changes (in order to verify that the added documentation is correct), so mixing in other sorts of changes and other APIs increases the reviewer burden a bit.

For more information, see: https://www.drupal.org/core/scope

Alright, now that I got the obligatory scope discussion out of the way:

  1. +++ b/core/modules/locale/src/Gettext.php
    @@ -37,6 +37,10 @@ class Gettext {
    +   *   Thrown when the header is missing, malformed or the translations can not
    +   *   be written to the database.
    

    This isn't quite a sentence. I'd suggest:

    Thrown when the header is missing or malformed, or when the translation cannot be written to the database.

    (Note that "cannot" is one word in our content standards.)

  2. +++ b/core/modules/locale/src/PoDatabaseReader.php
    @@ -64,6 +64,9 @@ public function setLangcode($langcode) {
    +   * @return array
    +   *   The read options.
    
    @@ -71,6 +74,9 @@ public function getOptions() {
    +   * @param array $options
    +   *   The options to set.
    

    Things are rarely just array; we can usually be more specific. They are usually string[], bool[], array[], etc. Even mixed[] gives more info. What kind of array is it?

    Also "the read options" and "The options to set" don't really explain what "options" are. It needs a reference to wherever the structure of these options is defined.

  3. +++ b/core/modules/locale/src/PoDatabaseReader.php
    @@ -100,6 +103,9 @@ public function setHeader(PoHeader $header) {
    +   * @return \Drupal\locale\StringStorageInterface[]
    +   *   String storage objects.
    

    "String storage objects" isn't adding information beyond the typehint. What string storage objects?

  4. +++ b/core/modules/locale/src/PoDatabaseReader.php
    @@ -148,6 +154,9 @@ private function loadStrings() {
    +   *   String storage object.
    

    I'm guessing this means the string storage object for the given language and options? Let's say that. Otherwise it's confusing .

  5. +++ b/core/modules/locale/src/PoDatabaseWriter.php
    @@ -78,6 +78,9 @@ public function setLangcode($langcode) {
    +   * @return array
    
    @@ -102,6 +105,9 @@ public function setReport($report = []) {
    +   * @return array
    

    What shape of array?

  6. +++ b/core/modules/locale/src/PoDatabaseWriter.php
    @@ -78,6 +78,9 @@ public function setLangcode($langcode) {
    +   *   The write result report.
    

    What is a write result report? Where is its structure defined? What references should I look at to know about it?

  7. +++ b/core/modules/locale/src/PoDatabaseWriter.php
    @@ -102,6 +105,9 @@ public function setReport($report = []) {
    +   *   The writer options.
    

    What are writer options?

  8. +++ b/core/modules/locale/src/StringDatabaseStorage.php
    @@ -315,7 +315,7 @@ protected function dbStringKeys($string) {
    -   *   Array of objects of the class requested.
    +   *   Array of objects of the requested class.
    

    Either is correct, I think.

  9. +++ b/core/modules/locale/src/StringStorageInterface.php
    @@ -24,8 +24,8 @@
    +   *   The source strings.
    

    Maybe "The matching source strings"? "The source strings" isn't very helpful.

Thanks!

Also, setting to 8.8.x, since docs fixes are eligible for backport to the production branch.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.