Uploaded image for project: 'Moodle Community Sites'
  1. Moodle Community Sites
  2. MDLSITE-7091

Coding style: Follow PSR-12 regarding namespaced class import

XMLWordPrintable

    • Icon: Task Task
    • Resolution: Unresolved
    • Icon: Low Low
    • Coding style
    • None

      See https://www.php-fig.org/psr/psr-12/#example

      See our current policy: https://moodledev.io/general/development/policies/codingstyle#namespaces

      Examples of incorrect class importing
       
      <?php
       
      use mod_porridge\local\equipment\spoon, mod_porridge\local\equipment\bowl; // Multiple classes per line.
      

      This is pretty vague, in that it doesn't adequately address how to import multiple classes from the same namespace grouped by brackets, e.g.:

      use mod_porridge\local\equipment\{spoon, bowl};
      

      This came from a discussion with dobedobedoh, hence creating this policy issue to explicitly allow such import declarations of multiple classes from common namespace as per PSR-12

      Voting options

      The following options are suggested for voting. Note class aliasing should remain allowed for all options. Proposal is to allow only for those classes in the same namespace (open to discussion)

      Please refer to the PSR extended coding style document

      Option A

      Allow the following in new code:

      use foo\bar\baz\{
          a as bazA,
          b,
          c,
      };
      

      Option B

      Allow the following in new code:

      use foo\bar\baz\{a as bazA, b, c};
      

      Option C

      Allow both A) or B)

      Option D (status quo)

      Do not allow A) or B)

            Unassigned Unassigned
            pholden Paul Holden
            Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.