diff --git a/README.md b/README.md index aa3092f8813fc960751a4ed74c3286cd2c36858e..2d69cb1fa70fbe1aca6b89e1d0a6f57f164f1dd8 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# Centreon - IT and Application monitoring software # +# Centreon - IT and Application monitoring software -## Introduction ## +## Introduction Centreon is one of the most flexible and powerful monitoring softwares on the market; it is absolutely free and Open Souce (released under GNU @@ -17,7 +17,7 @@ operational. * the [forum](http://forum.centreon.com) * the [download center](https://download.centreon.com) -## Download / Install ## +## Download / Install The fastest way to install up-to-date software from Centreon is to use our [Centreon Enterprise Server](https://www.centreon.com/en/products/centreon-enterprise-server/) @@ -26,23 +26,33 @@ Linux distribution, which comes with our software already packaged. Latest source releases can be retrieved from [Centreon download center](https://download.centreon.com). They can be installed by following the [online installation guide](https://documentation.centreon.com/docs/centreon/en/latest/installation/from_sources.html). -## Bug report / Feature request ## +## Bug report / Feature request Bug reports and feature requests are more than welcome. However if you wish to open a new issue, please read [this page](project/issues.md) first. -## Authors ## +## Coding Style Guide -### Project leaders ### +**backend** +* [PHP](https://github.com/centreon/centreon/tree/master/doc/coding-style/php) + +**frontend** +* [CSS](https://github.com/centreon/centreon/tree/master/doc/coding-style/css) +* [HTML](https://github.com/centreon/centreon/tree/master/doc/coding-style/html) +* [JS](https://github.com/centreon/centreon/tree/master/doc/coding-style/js) + +## Authors + +### Project leaders * Julien Mathis * Romain Le Merlus -### Dev team ### +### Dev team * Lionel Assepo * Maximilien Bersoult * Kevin Duret -* Toufik Mechouet +* Loic Laurent * Rabaa Ridene * Remi Werquin -* Quentin Garnier \ No newline at end of file +* Quentin Garnier diff --git a/doc/coding-style/css/README.md b/doc/coding-style/css/README.md new file mode 100644 index 0000000000000000000000000000000000000000..48efed11d80e03416378468d6d9db856de062617 --- /dev/null +++ b/doc/coding-style/css/README.md @@ -0,0 +1,86 @@ +# Coding Style Guide +## CSS +### OOCSS + +We encourage you to make use of [OOCSS](http://oocss.org/) for these reasons: + +* It helps create clear, strict relationships between CSS and HTML +* It helps us create reusable, composable components +* It allows for less nesting and lower specificity +* It helps in building scalable stylesheets + +```html +<div class="centreon centreon-block"> + <h1 class="centreon-title">Caesaribus velut parens gentium.</h1> + <div class="centreon-body_1"> + <p>Quid philosophia Epicureum quo praesertim se se ille.</p> + </div> + <div class="centreon-body_2"> + <p>Efferebantur tresque saeviore urbium saeviore incohibili.</p> + </div> +</div> +``` + +### Formatting + +* Use 4 spaces for indentation +* Prefer dashes over camelCasing in class names. + * class: .some-class-name + * id: #some-id-to-an-element +* Do not use ID selectors +* When using multiple selectors in a rule declaration, give each selector its own line. +* Put a space before the opening brace { in rule declarations +* In properties, put a space after, but not before, the : character. +* Put closing braces } of rule declarations on a new line +* Put blank lines between rule declarations + +```css +/* bad */ +.avatar{ + border-radius:50%; + border:2px solid white; } +.one,.selector,.per-line { + // ... +} + +/* good */ +.avatar { + border-radius: 50%; + border: 2px solid white; +} + +.one, +.selector, +.per-line { + // ... +} +``` + +### Border + +Use 0 instead of none to specify that a style has no border. + +```css +/* bad */ +.foo { + border: none; +} + +/* good */ +.foo { + border: 0; +} +``` +### Module + +To set a css for a module, use underscore [_] to make the separation of the module identifier and the class + +```css +.module_class-name { + color: green; +} +``` + +**[⬆ back to top](#coding-style-guide)** + +**[← back to summary](https://github.com/centreon/centreon)** \ No newline at end of file diff --git a/doc/coding-style/html/README.md b/doc/coding-style/html/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d829b0386618d84d5f7c8660fa45e8407ed8779e --- /dev/null +++ b/doc/coding-style/html/README.md @@ -0,0 +1,105 @@ +# Coding Style Guide + +## HTML + +* All tags and attributes are lowercase. +```html +//bad +<!DOCTYPE HTML> +<div CLASS="menu"> + +//good +<!doctype html> +<div class="menu"> +``` +* Close all HTML elements. +```html +//bad +<section> + <p>First paragraph. + <p>Second paragraph. +</section> + +//good +<section> + <p>First paragraph.</p> + <p>Second paragraph.</p> +</section> +``` +* Close empty HTML elements. +```html +//bad +<meta charset="utf-8"> +<input type="text"> + +//good +<meta charset="utf-8" /> +<input type="text" /> +``` +* Always add the "alt" attribute to images. +```html +//bad +<img src="centreon.gif"> + +//good +<img src="centreon.gif" alt="centreon"> +``` +* Groups entities around equal signs +```html +//bad +<link rel = "stylesheet" href = "styles.css"> + +//good +<link rel="stylesheet" href="styles.css"> +``` +* The limit on line length must be 120 characters, 80 is better. +* Indentation + * Do not add blank lines without a reason. + * For readability, add blank lines to separate large or logical code blocks. + * For readability, add 4 spaces of indentation. Do not use the tab key. + * For readability, if the text of the block is in a straight line, the indentation is unnecessary + * For readability, indent block elements, inline elements indentation is unnecessary +```html +//bad +<body> + + <h1>Cyprum itidem insulam procul</h1> + <div> + + <h2>Paphius quin etiam</h2> + <div>Cyprus ut nullius externi indigens adminiculi indigenis viribus a fundamento ipso carinae ad supremos + usque carbasos aedificet onerariam navem omnibusque armamentis instructam mari committat.</div> + </div> + + <p>Maximino sunt interfecti. pari sorte etiam procurator monetae extinctus est</p> + <p>Sericum enim et Asbolium supra dictos, quoniam cum hortaretur passim + nominare, quos vellent, adiecta religione firmarat, nullum igni vel + ferro se puniri iussurum, plumbi validis ictibus interemit. </p> + +</body> + +//good +<body> + <h1>Cyprum itidem insulam procul</h1> + <div> + <h2>Paphius quin etiam</h2> + <div> + Cyprus ut nullius externi indigens adminiculi indigenis viribus + a fundamento ipso carinae ad supremos usque carbasos aedificet onerariam + navem omnibusque armamentis instructam mari committat. + </div> + </div> + <p>Maximino sunt interfecti. pari sorte etiam procurator monetae extinctus est</p> + <p> + Sericum enim et Asbolium supra dictos, quoniam cum hortaretur passim + nominare, quos vellent, adiecta religione firmarat, nullum igni vel + ferro se puniri iussurum, plumbi validis ictibus interemit. + </p> +</body> +``` +* Do not use '``` ```' and ```<br /> ```. +* Do not use old HTML tags (```<color>```, ```<front>```, ...), make a css. + +**[⬆ back to top](#coding-style-guide)** + +**[← back to summary](https://github.com/centreon/centreon)** \ No newline at end of file diff --git a/doc/coding-style/js/README.md b/doc/coding-style/js/README.md new file mode 100644 index 0000000000000000000000000000000000000000..d45adec4fba2cab26e6573b292a3fbc3f221cb9f --- /dev/null +++ b/doc/coding-style/js/README.md @@ -0,0 +1,98 @@ +# Coding Style Guide + +## JS + +* Method and variable names must be in lowerCamelCase. +```js +var firstName = "John"; +``` +* Arrays that span across multiple lines can have a trailing comma to make sure that adding new rows does not change the previous row, as well. +```js +var myTab = []; + +var shortTab = ['first', 'second']; + +var longTab = [ + 'first', + 'second', + '...' +]; + +var assoTab = { + "val1":10, + "val2":55, + "val3":30 +}; +``` +* Use the else if statement to specify a new condition if the first condition is false. +```js +if (time < 10) { + greeting = "Good morning"; +} else if (time < 20) { + greeting = "Good day"; +} else { + greeting = "Good evening"; +} +``` +* Put spaces around operators ( = + - * / ), and after commas. +```js +var x = y + z; +var values = [1, 2, 3]; + +var i; +for (i = 0; i < 5; i++) { + x += i; +} +``` +* Prefer 4 spaces for indentation of code blocks. +```js +function hello(world) { + return world; +} +``` +* The limit on line length must be 120 characters, 80 is better. +```js +document.getElementById("world").innerHTML = + "Hello World."; +``` +* Declarations on Top +```js +// Declare at the beginning +var firstName, lastName; + +// Use later +firstName = "John"; +lastName = "Doe"; +``` +* Declarations on Top +```js +// Declare and initiate at the beginning +var firstName = "", + price = 0, + myArray = [], + myObject = {}; +``` +* Reduce Activity in Loops +```js +// bad +for (var i = 0; i < arr.length; i++) {} + +//good +var i; +var l = arr.length; +for (i = 0; i < l; i++) {} +``` +* Avoid Unnecessary Variables +```js +// Declare and initiate at the beginning +//bad +var fullName = firstName + " " + lastName; +document.getElementById("name").innerHTML = fullName; + +//good +document.getElementById("name").innerHTML = firstName + " " + lastName +``` + +**[⬆ back to top](#coding-style-guide)** + +**[← back to summary](https://github.com/centreon/centreon)** diff --git a/doc/coding-style/php/README.md b/doc/coding-style/php/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f181ffda16f4563dc2ee3528bb661e83896aca03 --- /dev/null +++ b/doc/coding-style/php/README.md @@ -0,0 +1,137 @@ +# Coding Style Guide + +## PHP + +For these projects, Centreon work on follow the [PSR-2](http://www.php-fig.org/psr/psr-2/) coding style guidelines. + +### Summary + +* Code must use an indent of 4 spaces, and must not use tabs for indenting. +* There must not be trailing whitespace at the end of non-blank lines. +* The PHP constants true, false, and null must be in lower case. +```php +//bad +public function sampleMethod ($a, $b = NULL) {} +//good +public function sampleMethod ($a, $b = null) +{ + // method body +} +``` +* For control structures( if/for/while…), the placement of parentheses, spaces, and braces; and that else and elseif are on the same line as the closing brace from the earlier body.-b +```php +//bad +if($a===$b){ + echo 'equal'; +} +//good +if ($a === $b) { + echo 'equal'; +} +``` +* The keyword elseif should be used instead of else if so that all control keywords look like single words. + +```php +namespace Vendor\Package; + +use FooInterface; +use BarClass as Bar; +use OtherVendor\OtherPackage\BazClass; + +class Foo extends Bar implements FooInterface +{ + public function sampleMethod ($a, $b = null) + { + if ($a === $b) { + bar(); + } elseif ($a > $b) { + $foo->bar($arg1); + } else { + BazClass::bar($arg2, $arg3); + } + + foreach ($iterable as $key => $value) { + // foreach body + } + + echo 'A string with ' . $someVariable . ' and ' . $otherVariable; + } + + final public static function bar() + { + // method body + } +} + +``` +* The limit on line length must be 120 characters, 80 is better. +```php +public function longLine ( + $longArgument, + $longerArgument, + $muchLongerArgument +) { + + $longArray = array( + array( + 0, + 1, + 2 + ), + 3, + 4 + ); + + $longString = 'Some String with ' . (string)$someVariable . ' and ' . + 'Concatinated'; + + if ( + ($a == $b) && + ($b == $c) || + ($c == $d) + ) { + $a = $d; + } +} +``` +* Method and variable names must be in lowerCamelCase. + +```php +//bad +$compound_name = 'compound'; +$compound-name = 'compound'; + +//good +$compoundName = 'compound'; +``` +* For the casting, please use (int)$var instead of intval($var) method. + +```php +$b = true; +$i = "1"; +$f = "1.5"; + +//bad +boolval($b); +intval($i); +floatval($f); + +//good +(bool)$b; +(int)$i; +(float)$f; +``` +### Check your code + +To check your code, you can use [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer), it is available with composer: +```bash +$ php composer.phar require --dev \ squizlabs/php_codesniffer:"*@stable" +``` +To validate the code with the [PSR-2](http://www.php-fig.org/psr/psr-2/) standard: +```bash +$ ./bin/phpcs -p --standard=PSR2 src/centreon/myFile +``` + +**[⬆ back to top](#coding-style-guide)** + +**[← back to summary](https://github.com/centreon/centreon)**