Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-61594

Coding style for multiple interface implementations

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.3.4, 3.4.1, 3.5
    • Fix Version/s: None
    • Component/s: Policy
    • Labels:
      None
    • Affected Branches:
      MOODLE_33_STABLE, MOODLE_34_STABLE, MOODLE_35_STABLE

      Description

      We are beginning to use interfaces more in our code and hitting places where the line length for the class definitions exceeds the max length rules.

      We should discuss how to handle this.

      Examples:

      Option 0 Using line breaks with the Moodle indent

      With the Moodle 8-char indent.

      <?php
       
      namespace plagiarism\privacy;
       
      class provider implements
              \core_privacy\metadata\provider,
              \core_privacy\request\subsystem\provider {
        // ...
      }
      

      Option 1: Using use

      In this case we often break another code guideline of only using the use keyword if the class is used multiple times. Most interfaces are used only once.

      <?php
       
      namespace plagiarism\privacy;
       
      use \core_privacy\request\subsystem\provider as subsystem_provider;
      use \core_privacy\metadata\provider as metadata_provider;
       
      class provider implements subsystem_provider, metadata_provider {
        // ...
      }
      

      Option 2: Using line breaks with 4 space indent

      This is a pretty common style and is very clear.
      It has the added benefit of allowing for comments before each interface is listed.

      <?php
       
      namespace plagiarism\privacy;
       
      class provider implements
          \core_privacy\metadata\provider,
          \core_privacy\request\subsystem\provider
      {
        // ...
      }
      

      Example with comments:

      <?php
       
      namespace plagiarism\privacy;
       
      class provider implements
          // The Plagiarism Subsystem passes data to the plagiarism plugintype.
          \core_privacy\metadata\provider,
       
          // The plagiarism subsystem is responsible for passing requests to the plagiarism plugins.
          \core_privacy\request\subsystem\provider
      {
        // ...
      }
      

      Options 3: Using line breaks with the Moodle indent

      This is a variation upon the Moodle style, but with the opening brace on a new line

      <?php
       
      namespace plagiarism\privacy;
       
      class provider implements
              \core_privacy\metadata\provider,
              \core_privacy\request\subsystem\provider
          {
        // ...
      }
      

      Summary

      Other options are of course available.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: