Skip to content
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

[0.x] Add Fixers for Laravel specific PHPDocs #3

Merged
merged 10 commits into from
Jun 23, 2022

Conversation

Jubeki
Copy link
Contributor

@Jubeki Jubeki commented Jun 22, 2022

Fixes #1

The Laravel Code Style has the following style throughout the source code, which currently can not be described with PHP-CS-Fixer alone. This PR adds three new custom fixers for the laravel preset, which of course can be added to psr12 or symfony if the user wants to.

The Fixers are mostly copies with changes from the PHP-CS-Fixer Source Code.

Laravel/laravel_phpdoc_alignment

After @param should be two spaces then a type-hint then another two spaces and then the $variable

  /**
   * Here is a description for what the function does
-  * @param string $foo
+  * @param  string  $foo
   * @return string
   */
  public function bar($foo) {}

Laravel/laravel_phpdoc_order

First should be the description after that @param then @return and at last @throws
The default rule phpdoc_order has a different order: description, @param, @throws, @return

  /**
   * Here is a description for what the function does
   * @param string $foo
   * @param  string  $foo
-  * @throws \Exception
   * @return string
+  * @throws \Exception
   */
  public function bar($foo) {}

Laravel/laravel_phpdoc_seperation

Between each group of tags should be an empty line for seperation. @param and @return are always of the same group and are not to be seperated with an empty line.
The default behaviour for phpdoc_seperation is also an empty line between @param and @return.

  /**
   * Here is a description for what the function does
+  *
   * @param string $foo
   * @param  string  $foo
-  *
   * @return string
+  *
   * @throws \Exception
   */
  public function bar($foo) {}

Additional Note:

There is still some Fixers which need to be implemented, e.g. that in the PHPDoc is full quantified class name is used, which also cannot be described by PHP-CS-Fixer alone:
You may take a look at https://github.com/adamwojs/php-cs-fixer-phpdoc-force-fqcn
though the complex type formatting is not tagged yet and there are still some problems with classes which are in the same namespace.

@nunomaduro nunomaduro changed the title Add Fixers for Laravel specific PHPDocs [0.x] Add Fixers for Laravel specific PHPDocs Jun 22, 2022
@nunomaduro nunomaduro marked this pull request as draft June 23, 2022 08:19
@nunomaduro
Copy link
Member

Can you test fix the test suite, and in general adjust the coding style of the pull request? No final classes, no types, etc.

@Jubeki
Copy link
Contributor Author

Jubeki commented Jun 23, 2022

I am sorry, but the types are defined in https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/src/Fixer/FixerInterface.php and need to be added.

I of course can remove them in PhpdocTagComparator.

@Jubeki
Copy link
Contributor Author

Jubeki commented Jun 23, 2022

I will remove the types from the protected and private methods which are not from the interface.

@Jubeki Jubeki force-pushed the add-custom-laravel-fixers branch from f22291d to 1012d02 Compare June 23, 2022 09:15
@Jubeki Jubeki marked this pull request as ready for review June 23, 2022 09:16
@nunomaduro nunomaduro merged commit 0a846c6 into laravel:main Jun 23, 2022
@Jubeki Jubeki deleted the add-custom-laravel-fixers branch June 23, 2022 13:17
ablancobarreda added a commit to ablancobarreda/pint that referenced this pull request Jan 5, 2023
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.

Incorrect PHPDoc Formatting
3 participants