Skip to content

Add order option to phpdoc_order #6515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2022

Conversation

paulbalandan
Copy link
Member

Description
In the past, we are stuck with the default ordering of ['param', 'throws', 'return']. Now that the fixer is configurable, this proposes to change the ordering to ['param', 'return', 'throws'].

$ vendor/bin/php-cs-fixer describe phpdoc_order
Description of phpdoc_order rule.
Annotations in PHPDoc should be ordered in defined sequence.

Fixer is configurable using following option:
* order (string[]): sequence in which annotations in PHPDoc should be ordered; defaults to ['param', 'throws', 'return']

Fixing examples:
 * Example #1. Fixing with the default configuration.
   ---------- begin diff ----------
   --- Original
   +++ New
   @@ -1,10 +1,10 @@
    <?php
    /**
     * Hello there!
     *
   - * @throws Exception|RuntimeException foo
     * @custom Test!
   - * @return int  Return the number of changes.
     * @param string $foo
     * @param bool   $bar Bar
   + * @throws Exception|RuntimeException foo
   + * @return int  Return the number of changes.
     */

   ----------- end diff -----------

 * Example #2. Fixing with configuration: ['order' => ['param', 'throws', 'return']].
   ---------- begin diff ----------
   --- Original
   +++ New
   @@ -1,10 +1,10 @@
    <?php
    /**
     * Hello there!
     *
   - * @throws Exception|RuntimeException foo
     * @custom Test!
   - * @return int  Return the number of changes.
     * @param string $foo
     * @param bool   $bar Bar
   + * @throws Exception|RuntimeException foo
   + * @return int  Return the number of changes.
     */

   ----------- end diff -----------

 * Example #3. Fixing with configuration: ['order' => ['param', 'return', 'throws']].
   ---------- begin diff ----------
   --- Original
   +++ New
   @@ -1,10 +1,10 @@
    <?php
    /**
     * Hello there!
     *
   - * @throws Exception|RuntimeException foo
     * @custom Test!
   - * @return int  Return the number of changes.
     * @param string $foo
     * @param bool   $bar Bar
   + * @return int  Return the number of changes.
   + * @throws Exception|RuntimeException foo
     */

   ----------- end diff -----------

 * Example #4. Fixing with configuration: ['order' => ['param', 'custom', 'throws', 'return']].
   ---------- begin diff ----------
   --- Original
   +++ New
   @@ -1,10 +1,10 @@
    <?php
    /**
     * Hello there!
     *
   + * @param string $foo
   + * @param bool   $bar Bar
   + * @custom Test!
     * @throws Exception|RuntimeException foo
   - * @custom Test!
     * @return int  Return the number of changes.
   - * @param string $foo
   - * @param bool   $bar Bar
     */

   ----------- end diff -----------

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

Copy link
Member

@kenjis kenjis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this order.

Copy link
Member

@MGatner MGatner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YES! Always thought this was the superior ordering 😎

@paulbalandan paulbalandan merged commit 46ddce5 into codeigniter4:develop Sep 9, 2022
@paulbalandan paulbalandan deleted the phpdoc-order branch September 9, 2022 02:12
paulbalandan added a commit to CodeIgniter/coding-standard that referenced this pull request Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants