-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add code sample and some more details to the CS page #508
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,60 @@ Coding Standards | |
================ | ||
|
||
When contributing code to Symfony2, you must follow its coding standards. To | ||
make a long story short, here is the golden rule: *Imitate the existing | ||
Symfony2 code*. | ||
make a long story short, here is the golden rule: **Imitate the existing | ||
Symfony2 code**. Most open-source Bundles and libraries used by Symfony2 also | ||
follow the same guidelines, and you should too. | ||
|
||
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. | ||
|
||
Since a picture - or some code - is worth a thousand words, here's a short | ||
example containing most features described below: | ||
|
||
.. code-block:: php | ||
|
||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Acme; | ||
|
||
class Foo | ||
{ | ||
const SOME_CONST = 42; | ||
|
||
private $foo; | ||
|
||
/** | ||
* @param string $dummy Some argument description | ||
*/ | ||
public function __construct($dummy) | ||
{ | ||
$this->foo = $this->transform($dummy); | ||
} | ||
|
||
/** | ||
* @param string $dummy Some argument description | ||
* @return string|null Transformed input | ||
*/ | ||
private function transform($dummy) | ||
{ | ||
if (true === $dummy) { | ||
return; | ||
} elseif ('string' === $dummy) { | ||
$dummy = substr($dummy, 0, 5); | ||
} | ||
|
||
return $dummy; | ||
} | ||
} | ||
|
||
Structure | ||
--------- | ||
|
@@ -35,8 +87,8 @@ Structure | |
* Put braces on their own line for classes, methods, and functions | ||
declaration; | ||
|
||
* Separate the conditional statement and the opening brace with a single | ||
space and no blank line; | ||
* Separate the conditional statements (`if`, `else`, ...) and the opening | ||
brace with a single space and no blank line; | ||
|
||
* Declare visibility explicitly for class, methods, and properties (usage of | ||
`var` is prohibited); | ||
|
@@ -68,9 +120,18 @@ Naming Conventions | |
|
||
* Use alphanumeric characters and underscores for file names; | ||
|
||
* Don't forget to look at the more verbose :doc:`conventions` document for | ||
more subjective naming considerations. | ||
|
||
Documentation | ||
------------- | ||
|
||
* Add PHPDoc blocks for all classes, methods, and functions; | ||
|
||
* The `@package` and `@subpackage` annotations are not used. | ||
|
||
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. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
IIRC, constants are defined first in the Sf2 code.