<p>This section 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.</p>
<p>RSS-Bridge uses <ahref="https://travis-ci.org/"class="Link--external"rel="noopener noreferrer">Travis-CI</a> 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 <ahref="https://github.com/RSS-Bridge/rss-bridge/blob/master/phpcs.xml"class="Link--external"rel="noopener noreferrer">phpcs.xml</a> for a complete list of policies enforced by Travis-CI.</p>
<p>If you want to run the checks locally, make sure you have <ahref="https://github.com/squizlabs/PHP_CodeSniffer"class="Link--external"rel="noopener noreferrer"><code>phpcs</code></a> and <ahref="https://phpunit.de/"class="Link--external"rel="noopener noreferrer"><code>phpunit</code></a> installed on your machine and run following commands in the root directory of RSS-Bridge (tested on Debian):</p>
<h2><aid="add-a-new-line-at-the-end-of-a-file"href="#add-a-new-line-at-the-end-of-a-file"class="Permalink"aria-hidden="true"title="Permalink">#</a>Add a new line at the end of a file</h2>
<p>Each PHP/CSS/HTML file must end with a new line at the end of a file.</p>
<h2><aid="do-not-add-a-whitespace-before-a-semicolon"href="#do-not-add-a-whitespace-before-a-semicolon"class="Permalink"aria-hidden="true"title="Permalink">#</a>Do not add a whitespace before a semicolon</h2>
<p>A semicolon indicates the end of a line of code. Spaces before the semicolon is unnecessary and must be removed.</p>
<h2><aid="do-not-add-whitespace-at-start-or-end-of-a-file-or-end-of-a-line"href="#do-not-add-whitespace-at-start-or-end-of-a-file-or-end-of-a-line"class="Permalink"aria-hidden="true"title="Permalink">#</a>Do not add whitespace at start or end of a file or end of a line</h2>
<p>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.</p>
<h2><aid="use-tabs-for-indentation"href="#use-tabs-for-indentation"class="Permalink"aria-hidden="true"title="Permalink">#</a>Use tabs for indentation</h2>
<p>RSS-Bridge uses tabs for indentation on all PHP files in the repository (except files located in the <code>vendor</code> directory)</p>
<h1><aid="maximum-line-length"href="#maximum-line-length"class="Permalink"aria-hidden="true"title="Permalink">#</a>Maximum Line Length</h1>
<h2><aid="the-maximum-line-length-should-not-exceed-80-characters"href="#the-maximum-line-length-should-not-exceed-80-characters"class="Permalink"aria-hidden="true"title="Permalink">#</a>The maximum line length should not exceed 80 characters</h2>
<p>One line of code should have no more than <strong>80 characters</strong> (soft limit) and must never exceed <strong>120 characters</strong> (hard limit).</p>
<p><em>Notice</em>: Travis-CI enforces the hard limit of 120 characters. Maintainers may ask you to indent lines longer than 80 characters before merging. This is generally done to keep the code as readable and maintainable as possible.</p>
<p>For long conditional statements, consider indenting the statement into multiple lines.</p>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong> (the total length of the line is <strong>94</strong> characters)</p>
<p>For long text, either add line feeds, or make use of the <ahref="http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc"class="Link--external"rel="noopener noreferrer"><code>heredoc</code></a> syntax.</p>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong> (the total length of the line is <strong>340</strong> characters - from <ahref="https://www.lipsum.com/feed/html"class="Link--external"rel="noopener noreferrer">Lorem Ipsum</a>)</p>
<pre><codeclass="language-PHP">$longtext = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse condimentum nec est eget posuere. Proin at sagittis risus. Fusce faucibus lectus leo, eu ornare velit tristique eu. Curabitur elementum facilisis ultricies. Praesent dictum fermentum lectus a rhoncus. Donec vitae justo metus. Sed molestie faucibus egestas.';
</code></pre>
<p><strong>Good</strong> (use <code>heredoc</code> syntax - this will add line-breaks)</p>
<h2><aid="whenever-possible-use-single-quote-strings"href="#whenever-possible-use-single-quote-strings"class="Permalink"aria-hidden="true"title="Permalink">#</a>Whenever possible use single quote strings</h2>
<p>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. <code>"\n"</code>) or inlined variables (i.e. <code>"My name is {$name}"</code>);</p>
<h2><aid="add-spaces-around-the-concatenation-operator"href="#add-spaces-around-the-concatenation-operator"class="Permalink"aria-hidden="true"title="Permalink">#</a>Add spaces around the concatenation operator</h2>
<p>The concatenation operator should have one space on both sides in order to improve readability.</p>
<p>You may break long lines into multiple lines using the concatenation operator. That way readability can improve considerable when combining lots of variables.</p>
<h2><aid="use-a-single-string-instead-of-concatenating"href="#use-a-single-string-instead-of-concatenating"class="Permalink"aria-hidden="true"title="Permalink">#</a>Use a single string instead of concatenating</h2>
<p>While concatenation is useful for combining variables with other variables or static text. It should not be used to combine two sets of static text. See also: <ahref="#maximum-line-length">Maximum line length</a></p>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><codeclass="language-PHP">$text = 'This is' . 'a bad idea!';
</code></pre>
<p><strong>Good</strong></p>
<pre><codeclass="language-PHP">$text = 'This is a good idea!';
<h2><aid="use-uppercase-for-constants"href="#use-uppercase-for-constants"class="Permalink"aria-hidden="true"title="Permalink">#</a>Use UPPERCASE for constants</h2>
<p>As in most languages, constants should be written in UPPERCASE.</p>
<p><em>Notice</em>: This does not apply to keywords!</p>
<h2><aid="use-lowercase-for-true-false-and-null"href="#use-lowercase-for-true-false-and-null"class="Permalink"aria-hidden="true"title="Permalink">#</a>Use lowercase for <code>true</code>, <code>false</code> and <code>null</code></h2>
<p><code>true</code>, <code>false</code> and <code>null</code> must be written in lower case letters.</p>
<h2><aid="operators-must-have-a-space-around-them"href="#operators-must-have-a-space-around-them"class="Permalink"aria-hidden="true"title="Permalink">#</a>Operators must have a space around them</h2>
<p>Operators must be readable and therefore should have spaces around them.</p>
<h2><aid="parameters-with-default-values-must-appear-last-in-functions"href="#parameters-with-default-values-must-appear-last-in-functions"class="Permalink"aria-hidden="true"title="Permalink">#</a>Parameters with default values must appear last in functions</h2>
<p>It is considered good practice to make parameters with default values last in function declarations.</p>
<h2><aid="do-not-add-spaces-after-opening-or-before-closing-bracket"href="#do-not-add-spaces-after-opening-or-before-closing-bracket"class="Permalink"aria-hidden="true"title="Permalink">#</a>Do not add spaces after opening or before closing bracket</h2>
<p>Parenthesis must tightly enclose parameters.</p>
<h2><aid="structures-must-always-be-formatted-as-multi-line-blocks"href="#structures-must-always-be-formatted-as-multi-line-blocks"class="Permalink"aria-hidden="true"title="Permalink">#</a>Structures must always be formatted as multi-line blocks</h2>
<p>A structure should always be treated as if it contains a multi-line block.</p>
<p><strong>Add a space after closing parenthesis</strong></p>
<h2><aid="do-not-write-empty-statements"href="#do-not-write-empty-statements"class="Permalink"aria-hidden="true"title="Permalink">#</a>Do not write empty statements</h2>
<p>Empty statements are considered bad practice and must be avoided.</p>
<h2><aid="do-not-write-unconditional-if-statements"href="#do-not-write-unconditional-if-statements"class="Permalink"aria-hidden="true"title="Permalink">#</a>Do not write unconditional if-statements</h2>
<p>If-statements without conditions are considered bad practice and must be avoided.</p>
<h2><aid="use-pascalcase-for-class-names"href="#use-pascalcase-for-class-names"class="Permalink"aria-hidden="true"title="Permalink">#</a>Use PascalCase for class names</h2>
<p>Class names must be written in <ahref="http://wiki.c2.com/?PascalCase"class="Link--external"rel="noopener noreferrer">PascalCase</a>.</p>
<h2><aid="do-not-use-final-statements-inside-final-classes"href="#do-not-use-final-statements-inside-final-classes"class="Permalink"aria-hidden="true"title="Permalink">#</a>Do not use final statements inside final classes</h2>
<p>Final classes cannot be extended, so it doesn’t make sense to add the final keyword to class members.</p>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><codeclass="language-PHP">final class MyClass {
final public function MyFunction() {
}
}
</code></pre>
<p><strong>Good</strong> (remove the final keyword from class members)</p>
<pre><codeclass="language-PHP">final class MyClass {
<h2><aid="do-not-override-methods-to-call-their-parent"href="#do-not-override-methods-to-call-their-parent"class="Permalink"aria-hidden="true"title="Permalink">#</a>Do not override methods to call their parent</h2>
<p>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.</p>
<h2><aid="abstract-and-final-declarations-must-precede-the-visibility-declaration"href="#abstract-and-final-declarations-must-precede-the-visibility-declaration"class="Permalink"aria-hidden="true"title="Permalink">#</a>abstract and final declarations MUST precede the visibility declaration</h2>
<p>When declaring <code>abstract</code> and <code>final</code> functions, the visibility (scope) must follow after <code>abstract</code> or <code>final</code>.</p>
<h2><aid="static-declaration-must-come-after-the-visibility-declaration"href="#static-declaration-must-come-after-the-visibility-declaration"class="Permalink"aria-hidden="true"title="Permalink">#</a>static declaration MUST come after the visibility declaration</h2>
<p>The <code>static</code> keyword must come after the visibility (scope) parameter.</p>
<h2><aid="do-not-add-spaces-when-casting"href="#do-not-add-spaces-when-casting"class="Permalink"aria-hidden="true"title="Permalink">#</a>Do not add spaces when casting</h2>
<p>The casting type should be put into parenthesis without spaces.</p>
<h2><aid="always-use-the-long-array-syntax"href="#always-use-the-long-array-syntax"class="Permalink"aria-hidden="true"title="Permalink">#</a>Always use the long array syntax</h2>
<p>Arrays should be initialized using the long array syntax.</p>
window.searchTranslation = {"Search_one_result":"1 result","Search_results":"!count results","Search_no_results":"Nothing found","Search_common_words_ignored":"Common words are largely ignored","Search_too_short":"Search too short","Search_one_character_or_more":"Should be one character or more","Search_should_be_x_or_more":"Should be !min characters or more","Link_previous":"Previous","Link_next":"Next"};