-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Mention and recommend to use PHP-CS-Fixer when contributing code #8246
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
Changes from 4 commits
5c06fe0
a6fdc96
7b31773
30e9e3e
5def3f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,33 @@ | ||
Coding Standards | ||
================ | ||
|
||
When contributing code to Symfony, you must follow its coding standards. To | ||
make a long story short, here is the golden rule: **Imitate the existing | ||
Symfony code**. Most open-source Bundles and libraries used by Symfony also | ||
follow the same guidelines, and you should too. | ||
Symfony code is contributed by thousands of developers around the world. To make | ||
every piece of code look and feel familiar, Symfony defines some coding standards | ||
that all contributions must follow. | ||
|
||
Remember that the main advantage of standards is that every piece of code | ||
looks and feels familiar, it's not about this or that being more readable. | ||
These Symfony coding standards are based on the `PSR-1`_, `PSR-2`_ and `PSR-4`_ | ||
standards, so you may already know most of them. | ||
|
||
Symfony follows the standards defined in the `PSR-0`_, `PSR-1`_, `PSR-2`_ and `PSR-4`_ | ||
documents. | ||
Making your Code Follow the Coding Standards | ||
-------------------------------------------- | ||
|
||
Since a picture - or some code - is worth a thousand words, here's a short | ||
example containing most features described below: | ||
Instead of reviewing your code manually, Symfony makes it simple to ensure that | ||
your contributed code matches the expected code syntax. First, install the | ||
`PHP CS Fixer tool`_ and then, run this command to fix any problem: | ||
|
||
.. code-block:: terminal | ||
|
||
$ cd your-project/ | ||
$ php php-cs-fixer.phar fix /path/to/modified/file.php | ||
|
||
If you forget to run this command and make a pull request with any syntax issue, | ||
our automated tools will warn you about that and will provide the solution. | ||
|
||
Symfony Coding Standards in Detail | ||
---------------------------------- | ||
|
||
If you want to learn about the Symfony coding standards in detail, here's a | ||
short example containing most features described below: | ||
|
||
.. code-block:: html+php | ||
|
||
|
@@ -122,7 +136,7 @@ example containing most features described below: | |
} | ||
|
||
Structure | ||
--------- | ||
~~~~~~~~~ | ||
|
||
* Add a single space after each comma delimiter; | ||
|
||
|
@@ -181,7 +195,7 @@ Structure | |
* Do not use spaces around ``[`` offset accessor and before ``]`` offset accessor. | ||
|
||
Naming Conventions | ||
------------------ | ||
~~~~~~~~~~~~~~~~~~ | ||
|
||
* Use camelCase, not underscores, for variable, function and method | ||
names, arguments; | ||
|
@@ -223,7 +237,7 @@ Service Naming Conventions | |
* A group name uses the underscore notation. | ||
|
||
Documentation | ||
------------- | ||
~~~~~~~~~~~~~ | ||
|
||
* Add PHPDoc blocks for all classes, methods, and functions (though you may | ||
be asked to remove PHPDoc that do not add value); | ||
|
@@ -234,14 +248,17 @@ Documentation | |
|
||
* Omit the ``@return`` tag if the method does not return anything; | ||
|
||
* The ``@package`` and ``@subpackage`` annotations are not used. | ||
* The ``@package`` and ``@subpackage`` annotations are not used; | ||
|
||
* Inline the ``@inheritdoc`` tag. | ||
|
||
License | ||
------- | ||
~~~~~~~ | ||
|
||
* Symfony is released under the MIT license, and the license block has to be | ||
present at the top of every PHP file, before the namespace. | ||
|
||
.. _`PHP CS Fixer tool`: https://github.com/FriendsOfPHP/PHP-CS-Fixer | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. everywhere there is website, here you put repo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer not to change that. The http://cs.sensiolabs.org/ website looks outdated to me: the copyright says 2014, it uses a deprecated SensioLabs logo, it hasn't been moved to SensioCloud like the rest of sites, etc. Maybe @fabpot can tell us if he's planning to update or remove http://cs.sensiolabs.org/ Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. website is up to date.
I think you have quite outdated informations. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cs.sensiolabs.org was not moved as it's handled by Github now. So, all is good. |
||
.. _`PSR-0`: http://www.php-fig.org/psr/psr-0/ | ||
.. _`PSR-1`: http://www.php-fig.org/psr/psr-1/ | ||
.. _`PSR-2`: http://www.php-fig.org/psr/psr-2/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as line was modified my comment is not displayed (as it's "outdated").
yet, this command will work for most the cases, it's wrong
#8246 (comment)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry but I don't understand your last comments. Please tell me the exact command that the user must execute and I'll copy+paste it. Thank you.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 scenarios:
A. current state of PR:
cons:
B. proper command
(-v just to see changed files, progress, and so)
cons:
solution
ask user to execute later command, but before asking him that - fix the branches of Symfony to not report violations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't Fabbot already run the PHP CS fixer and fails if it reports violations? If that's the case, there cannot be any violations in the branches, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wouterj the problem is that we started using CS fixer when Symfony already had a ton of code. And we didn't execute the first time to fix the entire codebase to avoid merge conflicts and breaking all the pending PRs. So, Symfony doesn't contain CS errors for its new code, but it contains some CS issues for its oldest code ... and that's why you can't run the command.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fabbot.io run PHP CS Fixer (and few other tools) only for modified files.
@javiereguiluz the background is correct, yet a lot of effort was already made to apply CS to whole codebase (and got merged dozens of times). While not all is green indeed, there is not that much of it currently for LTS and higher versions