1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-08-04 23:57:29 +02:00

Updated Coding style policy (markdown)

LogMANOriginal
2018-10-30 20:24:08 +01:00
parent 9858c26dd5
commit 89515eaa57

@@ -1,62 +1,109 @@
_**WORK IN PROGRESS: nothing described here should be considered as definitive or mandatory**_ **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.
## Indentation
* Proposal 1 ***
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.
# Do not write empty statements
Empty statements are considered bad practice and must be avoided.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
if($condition) {
// empty statement
} else {
// do something here
}
```
**Good** (invert condition)
```PHP
if(!$condition) {
// do something
}
```
</div></details><br>
_Reference_: [`Generic.CodeAnalysis.EmptyStatement`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/CodeAnalysis/EmptyStatementSniff.php)
# Do not write unconditional if-statements
If-statements without conditions are considered bad practice and must be avoided.
<details><summary>Example</summary><div><br>
Use two space characters for each indentation level
```PHP ```PHP
if(true) { if(true) {
echo true;
} else{
echo false;
} }
``` ```
* Proposal 2 </div></details><br>
Use one tab per indentation level (rendered as 4 spaces in GitHub) _Reference_: [`Generic.CodeAnalysis.UnconditionalIfStatement`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/CodeAnalysis/UnconditionalIfStatementSniff.php)
```PHP
if(true){
echo true;
} else{
echo false;
}
```
## Trailing white spaces # Do not use final statements inside final classes
* Proposal 1 Final classes cannot be extended, so it doesn't make sense to add the final keyword to class members.
Lines must be trimmed of any trailing white spaces <details><summary>Example</summary><div><br>
## Line length **Bad**
* Proposal 1
Lines must be limited to 80 characters
* Proposal 2
Lines should have a length of less than 80 characters where possible. The maximum length for one line is 120 characters.
## Variables, functions, methods and class naming
* Proposal 1
```PHP ```PHP
var $thisVariable; final class MyClass {
function thisFunction(){} final public function MyFunction() {
class thisClass {
function thisMethod(){} }
} }
``` ```
* Proposal 2 **Good** (remove the final keyword from class members)
```PHP ```PHP
var $thisVariable; // camelCase final class MyClass {
function this_function(){} // lower-case & underscore ('_') public function MyFunction() {
class ThisClass { // UpperCamelCase (PascalCase)
function ThisMethod(){} // UpperCamelCase (PascalCase) }
} }
``` ```
</div></details><br>
_Reference_: [`Generic.CodeAnalysis.UnnecessaryFinalModifier`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/CodeAnalysis/UnnecessaryFinalModifierSniff.php)
# Do not override methods to call their parent
It doesn't make sense to override a method only to call their parent. When overriding methods, make sure to add some functionality to it.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
class MyClass extends BaseClass {
public function BaseFunction() {
parent::BaseFunction();
}
}
```
**Good** (don't override the function)
```PHP
class MyClass extends BaseClass {
}
```
</div></details><br>
_Reference_: [`Generic.CodeAnalysis.UselessOverridingMethod`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/CodeAnalysis/UselessOverridingMethodSniff.php)