1
0
Fork 0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-03-15 04:31:16 +03:00

Updated Coding style policy (markdown)

LogMANOriginal 2018-10-31 19:35:10 +01:00
parent 33583b8698
commit ad1f36d20c

@ -1,10 +1,6 @@
**WORK IN PROGRESS (by @LogMANOriginal)** Please refer to [phpcs.xml](https://github.com/RSS-Bridge/rss-bridge/blob/master/phpcs.xml) for a complete list of policies.
This page explains the coding style policy for RSS-Bridge with examples and references to external resources. Please make sure your code is compliant before opening a pull request.
***
This page explains the coding style policy for RSS-Bridge. Please make sure your code is compliant before opening a pull request.
_Notice_: RSS-Bridge uses [Travis-CI](https://travis-ci.org/) to check code quality. You will automatically be notified if issues were found in your pull request. You must fix those issues before it can be merged.
RSS-Bridge uses [Travis-CI](https://travis-ci.org/) to validate code quality. You will automatically be notified if issues were found in your pull request. You must fix those issues before the pull request will be merged. Refer to [phpcs.xml](https://github.com/RSS-Bridge/rss-bridge/blob/master/phpcs.xml) for a complete list of policies enforced by Travis-CI.
# Use tabs for indentation
@ -234,6 +230,28 @@ $text = 'This is a good idea!';
_Reference_: [`Generic.Strings.UnnecessaryStringConcat`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/Strings/UnnecessaryStringConcatSniff.php)
# Whenever possible use single quote strings
PHP supports both single quote strings and double quote strings. For pure text you must use single quote strings for consistency. Double quote strings are only allowed for special characters (i.e. `"\n"`) or inlined variables (i.e. "My name is {$name}");
<details><summary>Example</summary><div><br>
**Bad**
```PHP
echo "Hello World!";
```
**Good**
```PHP
echo 'Hello World!';
```
</div></details><br>
_Reference_: [`Squiz.Strings.DoubleQuoteUsage`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/Strings/DoubleQuoteUsageSniff.php)
# Do not write empty statements
Empty statements are considered bad practice and must be avoided.
@ -388,6 +406,28 @@ function showTitle($title, $duration = 60000) { ... }
_Reference_: [`PEAR.Functions.ValidDefaultValue`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PEAR/Sniffs/Functions/ValidDefaultValueSniff.php)
# Do not add spaces after opening or before closing bracket
Parenthesis must tightly enclose parameters.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
if( $condition ) { ... }
```
**Good**
```PHP
if($condition) { ... }
```
</div></details><br>
_Reference_: [`PSR2.ControlStructures.ControlStructureSpacing`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PSR2/Sniffs/ControlStructures/ControlStructureSpacingSniff.php)
# Use PascalCase for class names
Class names must be written in [PascalCase](http://wiki.c2.com/?PascalCase).
@ -409,3 +449,171 @@ class MySuperClass { ... }
</div></details><br>
_Reference_: [`PEAR.NamingConventions.ValidClassName`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PEAR/Sniffs/NamingConventions/ValidClassNameSniff.php)
# Add a new line at the end of a file
Each PHP/CSS/HTML file must end with a new line at the end of a file.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
{
// code here
} // This is the end of the file
```
**Good**
```PHP
{
// code here
}
// This is the end of the file
```
</div></details><br>
_Reference_: [`PSR2.Files.EndFileNewline`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PSR2/Sniffs/Files/EndFileNewlineSniff.php)
# Code blocks
Code blocks must follow a few rules.
**Add a space after closing parenthesis**
<details><summary>Example</summary><div><br>
**Bad**
```PHP
if($condition){
...
}
```
**Good**
```PHP
if($condition) {
...
}
```
</div></details><br>
**Add body into new line**
<details><summary>Example</summary><div><br>
**Bad**
```PHP
if($condition){ ... }
```
**Good**
```PHP
if($condition) {
...
}
```
</div></details><br>
**Close body in new line**
<details><summary>Example</summary><div><br>
**Bad**
```PHP
if($condition){
... }
```
**Good**
```PHP
if($condition) {
...
}
```
</div></details><br>
_Reference_: [`Squiz.ControlStructures.ControlSignature`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/ControlStructures/ControlSignatureSniff.php)
# Do not add spaces when casting
The casting type should be put into parenthesis without spaces.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
$text = ( string )$number;
```
**Good**
```PHP
$text = (string)$number;
```
</div></details><br>
_Reference_: [`Squiz.WhiteSpace.CastSpacing`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/WhiteSpace/CastSpacingSniff.php)
# Operators must have a space around them
Operators must be readable and therefore should have spaces around them.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
$text='Hello '.$name.'!';
```
**Good**
```PHP
$text = 'Hello ' . $name . '!';
```
</div></details><br>
_Reference_: [`Squiz.WhiteSpace.OperatorSpacing`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php)
# Do not add a whitespace before a semicolon
A semicolon indicates the end of a line of code. Spaces before the semicolon is unnecessary and must be removed.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
echo 'Hello World!' ;
```
**Good**
```PHP
echo 'Hello World!';
```
</div></details><br>
_Reference_: [`Squiz.WhiteSpace.SemicolonSpacing`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/WhiteSpace/SemicolonSpacingSniff.php)
# Do not add whitespace at start or end of a file or end of a line
Whitespace at the end of lines or at the start or end of a file is invisible to the reader and absolutely unnecessary. Thus it must be removed.
_Reference_: [`Squiz.WhiteSpace.SuperfluousWhitespace`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php)