Commit cc947298 authored by MCMic's avatar MCMic
Browse files

Merge branch '9-coding-standard-examples-should-match-the-coding-standards' into 'master'

Resolve "Coding standard examples should match the coding standards"

Closes #9

See merge request !12
Showing with 21 additions and 26 deletions
+21 -26
...@@ -33,7 +33,7 @@ Indentation and line length ...@@ -33,7 +33,7 @@ Indentation and line length
As a basic style rule, please use 2 spaces instead of tabulators. This will remove problems when using "diff". As a basic style rule, please use 2 spaces instead of tabulators. This will remove problems when using "diff".
.. note:: .. note::
For VI users, this can be achieved by the following settings: For VI users, this can be achieved by the following settings:
...@@ -58,7 +58,7 @@ Use a space before affectations, around operators, before parenthesis or braces. ...@@ -58,7 +58,7 @@ Use a space before affectations, around operators, before parenthesis or braces.
$b = $value[0]; $b = $value[0];
// Readability // Readability
if ($b + 5 > foo (bar () + 4)) { if ($b + 5 > foo(bar() + 4)) {
} }
...@@ -83,7 +83,7 @@ Always use single spaces to split logical and mathematical operations: ...@@ -83,7 +83,7 @@ Always use single spaces to split logical and mathematical operations:
.. code-block:: php .. code-block:: php
<?php <?php
if ($a > 6 && $b == 17 && (foo ($b) < 1)) { if ($a > 6 && $b == 17 && (foo($b) < 1)) {
} }
...@@ -96,14 +96,14 @@ If statements with or without else clauses are formatted like this: ...@@ -96,14 +96,14 @@ If statements with or without else clauses are formatted like this:
<?php <?php
if ($value) { if ($value) {
foo (); foo();
bar (); bar();
} }
if ($value) { if ($value) {
foo (); foo();
} else { } else {
bar (); bar();
} }
Switches are formatted like this: Switches are formatted like this:
...@@ -152,7 +152,7 @@ Always use camel casing with lowercase characters in the beginning for multiword ...@@ -152,7 +152,7 @@ Always use camel casing with lowercase characters in the beginning for multiword
<?php <?php
function checkForValidity () function checkForValidity ()
{ {
$testSucceeded = false; $testSucceeded = FALSE;
... ...
} }
...@@ -175,9 +175,9 @@ Find short function names that describe what the function does, in order to make ...@@ -175,9 +175,9 @@ Find short function names that describe what the function does, in order to make
.. code-block:: php .. code-block:: php
<?php <?php
if ( configReadable ("/etc/foo.conf") ) { if (configReadable("/etc/foo.conf")) {
} }
Use uppercase for constants/defines and _ to separate if there is more than one word : Use uppercase for constants/defines and _ to separate if there is more than one word :
.. code-block:: php .. code-block:: php
...@@ -231,7 +231,6 @@ Quotes / double quotes ...@@ -231,7 +231,6 @@ Quotes / double quotes
---------------------- ----------------------
* You must use single quotes for indexes, constants declaration, translations, ... * You must use single quotes for indexes, constants declaration, translations, ...
* Use double quote in translated strings
* When you have to use tabulation character (``\t``), carriage return (``\n``) and so on, you should use double quotes. * When you have to use tabulation character (``\t``), carriage return (``\n``) and so on, you should use double quotes.
* For performances reasons since PHP7, you may avoid strings concatenation. * For performances reasons since PHP7, you may avoid strings concatenation.
...@@ -240,30 +239,30 @@ Examples: ...@@ -240,30 +239,30 @@ Examples:
.. code-block:: php .. code-block:: php
<?php <?php
//for that one, you should use double, but this is at your option... //for that one, you should use single, but this is at your option...
$a = "foo"; $a = 'foo';
//use double quotes here, for $foo to be interpreted //use double quotes here, for $foo to be interpreted
// => with double quotes, $a will be "Hello bar" if $foo = 'bar' // => with double quotes, $a will be "Hello bar" if $foo = 'bar'
// => with single quotes, $a will be "Hello $foo" // => with single quotes, $a will be "Hello $foo"
$a = "Hello $foo"; $a = "Hello $foo";
//use single quotes for array keys //use single quotes for array keys
$tab = [ $tab = array(
'lastname' => 'john', 'lastname' => 'john',
'firstname' => 'doe' 'firstname' => 'doe'
]; );
//Do not use concatenation to optimize PHP7 //Do not use concatenation to optimize PHP7
//note that you cannot use functions call in {} //note that you cannot use functions call in {}
$a = "Hello {$tab['firstname']}"; $a = "Hello {$tab['firstname']}";
//single quote translations //single quote translations
$str = __('My string to translate'); $str = _('My string to translate');
//Double quote for special characters //Double quote for special characters
$html = "<p>One paragraph</p>\n<p>Another one</p>"; $html = "<p>One paragraph</p>\n<p>Another one</p>";
//single quote cases //single quote cases
switch ($a) { switch ($a) {
case 'foo' : //use single quote here case 'foo' : //use single quote here
...@@ -277,10 +276,6 @@ Files Format ...@@ -277,10 +276,6 @@ Files Format
------------ ------------
* UTF-8, LF - not CR LF * UTF-8, LF - not CR LF
* Name in lower case.
* Maximum line length: 80 characters
* Indentation: 2 spaces
Checking standards Checking standards
------------------ ------------------
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment