diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b515c5348d24a4c042076a9ae5e4c764a522950f..27377de6e6acb8840aff10ebd3c8b529157c61cd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,99 +1,318 @@ -# Which code branch to use +# Contributing to ISPConfig +ISPConfig is a open source project and community contributions are very welcome. To contribute, please stick to the guidelines. -The master branch is used for code (mostly new features) that shall go into the next major release (e.g. 3.2, 3.3 and so on). The stable branch (e.g. stable-3.1, stable-3.2) is the branch for the current intermediate and bugfix releases. Bugfixes shall be committed to the current stable branch and not the master branch. The stable branch is merged to the master automatically from time to time, please do not submit bugfixes a second time against the master. +This document is under development and will be continuously improved. + +# Issues +* Before opening a new issue, use the search function to check if there isn't a bug report / feature request already. +* If you are reporting a bug, please share your OS and PHP (CLI) version. +* If you want to report several bugs or request several features, open a separate issue for each one of them. + +# Branches +* Please create an issue for each contribution you want to make. +* Do not put multiple contributions into a single branch and merge request. Each contribution should have it's own branch. +* Do not use the develop branch in your forked project for your contribution. Create a separate branch for each issue. +* Give your branch a name, e. g. `6049-update-the-contributing-doc ` where 6049 is the issue number. + +# Merge requests +Please give your merge request a description that shortly states what it is about. Merge requests without a good title or with missing description will get delayed because it is more effort for us to check the meaning of the changes made. +Once again: Do not put multiple things into a single merge request. If you for example fix two issues where one affects apache and one mail users, use separate issues and separate merge requests. +You can group multiple issues in a single merge request if they have the same specific topic, e. g. if you have one issue stating that a language entry in mail users is missing and a second issue that a language entry for server config is missing, you can put both issues into a single branch and merge request. Be sure to include all issue ids (if multiple) into the merge request's description in this case. +* Open a issue for the bug you want to fix / the feature you want to implement +* After opening the issue, commit your changes to your branch +* Note the issue # in every commit +* Update the documentation (New devs will not have access to this. Please send a email to docs@ispconfig.org) +* Add translations for every language +* Use a short title +* Write a clear description - for example, when updating the contributing guidelines with issue #6049: \ +"Update of our contributing guidelines \ +Closes #6049" +* Please be aware that we are not able to accept merge request that do not stick to the coding guidelines. We need to insist on that to keep the code clean and maintainable. # Some guidelines for web development with php. ----------------------------------------------------- -* Unix Line Breaks Only, NO windows breaks please. -* Tabs to indent lines, NO spaces -* no accidental _ no spaces before or after -* error_reporting(E_ALL|E_STRICT), yep PHP 5 -* Magic quotes is gone, get used to it now. config = magic_quotes_gpc() Everything must be quoted -* Don't use ereg, split and other old function -> gone in PHP 5.4 -* Don't use features that are not supported in PHP 5.3, for compatibility with LTS OS releases, ISPConfig must support PHP 5.3+ -* Don't use shorttags. A Shorttag is always use always use `uses() or $app->load() functions. * Classes for the server are located in server/lib/classes/ and loaded with $app->uses() or $app->load() functions. -* please mark any section that need review or work on with /* TODO: short description */ -* Make function / var names on the following way, first word lower, next word(s) first letter upper like. getFirstResult(); -* always a space but NO newline before opening braces, e. g. -``` -class abc { - public function cde() { - if($a == $b) { - return false; - } - } + +### Indentations + +Indentations are always done with tabs. Do **not** use spaces. +It is recommended to set your IDE to display tabs with a width of 4 spaces. + +### Variable and method / function names + +Methods and functions should always be written in camel-case. Variables and properties should always be lowercase instead. + +**Correct:** +```php +class MyClass { + private $issue_list = []; + + private function getMyValue() { + + } } ``` -* no spaces after function/method or control names, e. g. -``` -function abc($x, $y) { - if($condition == true) { - $x = 2; - } + +**Wrong:** +```php +class my_class { + private $IssueList = []; + + private function get_my_value() { + + } } ``` -and NOT + +### Blocks + +#### Curly braces + +Opening curly braces always have to be in the same line as the preceding condition. They are separated by a single space from the closing paranthesis. +Closing curly braces are always on a separate line after the last statement in the block. The only exception is a do-while block where the logic is inverted. + +Curly braces are **always** to be used. Do not leave them out, even if there is only a single statement in the corresponding block. + +**Correct:** +```php +if($variable === true) { + +} + +while($condition) { + +} + +do { + +} while($condition); ``` -function abc ($x, $y) { - if ( $condition == true ) { - - } + +**Wrong:** +```php +if($variable === true){ + +} + +if($variable === true) +{ + } + +if($variable === true) + $x = 'no braces'; + +while($condition) { } ``` -# Commenting style +#### Short style + +The short style of conditional assignments is allowed to be used, but it must not affect readability, e. g. they shall not be nested. + +**Allowed:** +```php +$a = 0; +if($condition === true) { + $a = 1; +} -The comments break down into the following types +$a = ($condition === true ? 1 : 0); ``` -// is uses for removing lines and debug dev etc -/* - is used to comment out blocks -*/ -/** is used to create documentaion - * thats over - * lines - */ +**Disallowed:** +```php +$x = ($condition === true ? ($further == 'foo' ? true : false) : true); ``` -If you need to block out a section then use + + +#### Spaces and paranthesis + +The rules for using spaces are: +- no space after `if`/`while` etc. and the following opening paranthesis +- single space after closing paranthesis and before opening curly brace +- no spaces at the end of a line +- no spaces after opening paranthesis and before closing paranthesis +- single space before and after comparators + +**Correct:** +```php +if($variable === $condition) { + +} + +while(($condition !== false || $condition2 === true) && $n <= 15) { + $n++; +} ``` -/* -function redundant_code(){ - something here + +**Wrong:** +```php +if ($variable===$condition) { + +} + +while(($condition!==false||$condition2===true))&&$n<=15){ + } -*/ ``` -To block out single lines use // and all // are assumed to be redundant test code and NOT comments -// print_r($foo); +#### Newlines inside of conditions + +Breaking up conditions into separate lines can be done if it positively affects readability. + +```php +if($condition === true && ($state === 'completed' || $state === 'pending') && ($processed_by !== null || $process_time < time())) { -Do not use the phpdoc on every function, eg +} ``` -/** -* Login a user -* @param string user username -* @param string password of user -*/ -function login($user, $pass){ - +can also be written as +```php +if($condition === true + && ($state === 'completed' || $state === 'pending') + && ($processed_by !== null || $process_time < time()) + ) { + } ``` -as this function is self-explaining, the following clean code will suffice +This must not be abused, e. g. the following is not allowed: + +```php +if($a == 1 + || $b == 2) { + + } ``` -function login($user, $pass){ - -} + +### Arrays + +#### Short syntax + +Please **do** use short array syntax. We have deprecated the old-style array syntax. + +**Correct**: +```php +$var = []; + +$var2 = [ + 'conf' => [ + 'setting1' => 'value1' + ] +]; ``` -# Where to store custom settings +**Wrong:** +```php +$var = array(); -## Interface settings +$var2 = array( + 'conf' => array( + 'setting1' => 'value1' + ) +); +``` + +#### Spaces and newlines + +When defining an empty array, both brackets shall be on the same line. When defining an array with values, the style depends on the values you are going to assign. + +##### List of values + +When defining an array with a list of values, e. g. numbers or names, they should be on the same line as the brackets without using new lines, as long as the line does not exceed a total number of characters of about 90. After each comma there has to be a single space. + +##### Nested array + +When defining a nested array onle the opening bracket is to be on the same line. The closing bracket has to be on a separate line indented by `tabs * level of array`. + +##### Examples + +```php +// empty array +$a = []; +// array with list of values +$array = [4, 3, 76, 12]; + +// array with long list of values +$array = [ + 'This is one entry', 'This is a second one', 'Another one', 'Further entries', 'foo', 'bar', 34, 42, $variable, // newline here for better readability + 'Next entry', 'the last entry' +]; + +// nested array +$array = [ + 'conf' => [ + 'level' => 1, + 'settings' => [ + 'window' => 'open', + 'door' => 'closed + ] + ] +]; +``` + +**Not-to-dos:** +```php +$array=[ +]; + +$array = [ + 1, + 4, + 35, + 23, + 345, + 11, + 221, + 'further', + '...' +]; + +$array=['conf'=>['settings'=>['window' => 'open', 'door' => 'closed]]]; +``` + +### Strings + +Whenever possible use single quotes `'` instead of double qoutes `"`. Try not to embedd variables in string. Concatenate them instead. + +**Correct:** +```php +// simple text +$var = 'This is a text'; + +// array index +$array['index'] = 'value'; + +// text with variables +$var = 'This is a text with ' . $value . ' values inside and at the end: ' . $sum_value; + +// dynamic array index +$idx = 'index' . $key; +$value = $array[$idx]; +``` + +**Wrong:** +```php +// simple text +$var = "This is a text"; + +// array index +$array["index"] = 'value'; + +// text with variables +$var = "This is a text with $value values inside and at the end: {$sum_value}"; + +// dynamic array index +$value = $array['index' . $key]; +$value = $array["index{$key}"]; +``` + +# Where to store custom settings +## Interface settings The recommended place to store global interface settings is the ini style global config system (see system.ini.master file in install/tpl/ to set defaults). The settings file gets stored inside the ispconfig database. Settings can be accessed with the function: @@ -109,7 +328,6 @@ fields to the file interface/web/admin/form/system_config.tform.php and the corr tempalte file in the templates subfolder of the admin module. ## Server settings - Server settings are stored in the ini style server config system (see server.ini.master template file) The settings file gets stored inside the ispconfig database in the server table. Settings can be accessed with the function $app->getconf->get_server_config(....)