summaryrefslogtreecommitdiff
path: root/For_Developers/Coding_style_policy.html
blob: 8bfd7c89fae0682ebd0b41930c173fb42b1eb2d0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
    <title>Coding style policy - RSS-Bridge</title>
    <meta name="description" content="The RSS feed for websites missing it">
    <meta name="author" content="RSS-Bridge Contributors">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <link rel="icon" href="../themes/daux/img/favicon-blue.png" type="image/x-icon">

    <!-- Mobile -->
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <!-- JS -->
    <script>
        window.base_url = "../";
        document.documentElement.classList.remove('no-js');
    </script>

    <!-- Font -->
    
    <!-- CSS -->
            <link href='../themes/daux/css/theme-blue.min.css' rel='stylesheet' type='text/css'>
            <link href='../daux_libraries/search.css' rel='stylesheet' type='text/css'>
    </head>
<body class="">
    <div class="Columns content">
    <aside class="Columns__left Collapsible">
        <button type="button" class="Button Collapsible__trigger" aria-controls="sidebar_content" aria-expanded="false" aria-label="Toggle navigation">
            <span class="Collapsible__trigger__bar"></span>
            <span class="Collapsible__trigger__bar"></span>
            <span class="Collapsible__trigger__bar"></span>
        </button>

        <a class="Brand" href="../index.html">RSS-Bridge</a>

    <form role='search' action="/" method="get" class="Search" id="search_form">
        <label for="search_input">
            <span class='u-visuallyHidden'>Search</span>
        </label>
        <input
            type="search"
            id="search_input"
            class="Search__field"
            placeholder="Search..."
            aria-label="Search..."
            autocomplete="on"
            results=25
            autosave=text_search
        >
        <label>
            <input type="submit" class='u-visuallyHidden' />
            <span class='u-visuallyHidden'>Search...</span>
            <svg class="Search__icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 451 451">
                <path d="M447.05 428l-109.6-109.6c29.4-33.8 47.2-77.9 47.2-126.1C384.65 86.2 298.35 0 192.35 0 86.25 0 .05 86.3.05 192.3s86.3 192.3 192.3 192.3c48.2 0 92.3-17.8 126.1-47.2L428.05 447c2.6 2.6 6.1 4 9.5 4s6.9-1.3 9.5-4c5.2-5.2 5.2-13.8 0-19zM26.95 192.3c0-91.2 74.2-165.3 165.3-165.3 91.2 0 165.3 74.2 165.3 165.3s-74.1 165.4-165.3 165.4c-91.1 0-165.3-74.2-165.3-165.4z"/>
            </svg>
        </label>
    </form>

        <div class="Collapsible__content" id="sidebar_content">
            <!-- Navigation -->
            <ul class='Nav'><li class='Nav__item  has-children'><a href="../General/Project_goals.html" class="Nav__item__link"><i class="Nav__arrow">&nbsp;</i>General</a><ul class='Nav'><li class='Nav__item '><a href="../General/Project_goals.html">Project-goals</a></li><li class='Nav__item '><a href="../General/Contribute.html">Contribute</a></li><li class='Nav__item '><a href="../General/Requirements.html">Requirements</a></li><li class='Nav__item '><a href="../General/Screenshots.html">Screenshots</a></li><li class='Nav__item '><a href="../General/FAQ.html">FAQ</a></li><li class='Nav__item '><a href="../General/Public_Hosts.html">Public Hosts</a></li></ul></li><li class='Nav__item '><a href="../CLI/index.html" class="Nav__item__link"><i class="Nav__arrow">&nbsp;</i>CLI</a><ul class='Nav'></ul></li><li class='Nav__item  has-children'><a href="../For_Hosts/index.html" class="Nav__item__link"><i class="Nav__arrow">&nbsp;</i>For Hosts</a><ul class='Nav'><li class='Nav__item '><a href="../For_Hosts/Installation.html">Installation</a></li><li class='Nav__item '><a href="../For_Hosts/Updating.html">Updating</a></li><li class='Nav__item '><a href="../For_Hosts/Heroku_Installation.html">Heroku Installation</a></li><li class='Nav__item '><a href="../For_Hosts/Whitelisting.html">Whitelisting</a></li><li class='Nav__item '><a href="../For_Hosts/Authentication.html">Authentication</a></li><li class='Nav__item '><a href="../For_Hosts/Customizations.html">Customizations</a></li><li class='Nav__item '><a href="../For_Hosts/Custom_Configuration.html">Custom Configuration</a></li></ul></li><li class='Nav__item Nav__item--open has-children'><a href="../For_Developers/index.html" class="Nav__item__link"><i class="Nav__arrow">&nbsp;</i>For Developers</a><ul class='Nav'><li class='Nav__item Nav__item--active'><a href="../For_Developers/Coding_style_policy.html">Coding style policy</a></li><li class='Nav__item '><a href="../For_Developers/Pull_Request_policy.html">Pull Request policy</a></li><li class='Nav__item '><a href="../For_Developers/Folder_structure.html">Folder structure</a></li><li class='Nav__item '><a href="../For_Developers/Actions.html">Actions</a></li><li class='Nav__item '><a href="../For_Developers/Debug_mode.html">Debug mode</a></li><li class='Nav__item '><a href="../For_Developers/Github_Codespaces_Tutorial.html">Github Codespaces Tutorial</a></li><li class='Nav__item '><a href="../For_Developers/Development_Environment_Setup.html">Development Environment Setup</a></li></ul></li><li class='Nav__item  has-children'><a href="../Bridge_API/index.html" class="Nav__item__link"><i class="Nav__arrow">&nbsp;</i>Bridge API</a><ul class='Nav'><li class='Nav__item '><a href="../Bridge_API/How_to_create_a_new_bridge.html">How to create a new bridge</a></li><li class='Nav__item '><a href="../Bridge_API/BridgeAbstract.html">BridgeAbstract</a></li><li class='Nav__item '><a href="../Bridge_API/FeedExpander.html">FeedExpander</a></li><li class='Nav__item '><a href="../Bridge_API/WebDriverAbstract.html">WebDriverAbstract</a></li><li class='Nav__item '><a href="../Bridge_API/XPathAbstract.html">XPathAbstract</a></li></ul></li><li class='Nav__item '><a href="../Helper_functions/index.html" class="Nav__item__link"><i class="Nav__arrow">&nbsp;</i>Helper functions</a><ul class='Nav'></ul></li><li class='Nav__item  has-children'><a href="../Cache_API/index.html" class="Nav__item__link"><i class="Nav__arrow">&nbsp;</i>Cache API</a><ul class='Nav'><li class='Nav__item '><a href="../Cache_API/How_to_create_a_new_cache.html">How to create a new cache</a></li><li class='Nav__item '><a href="../Cache_API/CacheInterface.html">CacheInterface</a></li></ul></li><li class='Nav__item '><a href="../Technical_recommendations/index.html" class="Nav__item__link"><i class="Nav__arrow">&nbsp;</i>Technical recommendations</a><ul class='Nav'></ul></li><li class='Nav__item  has-children'><a href="../Bridge_Specific/ActivityPub_(Mastodon).html" class="Nav__item__link"><i class="Nav__arrow">&nbsp;</i>Bridge Specific</a><ul class='Nav'><li class='Nav__item '><a href="../Bridge_Specific/ActivityPub_(Mastodon).html">ActivityPub (Mastodon)</a></li><li class='Nav__item '><a href="../Bridge_Specific/Economist.html">Economist</a></li><li class='Nav__item '><a href="../Bridge_Specific/FacebookBridge.html">FacebookBridge</a></li><li class='Nav__item '><a href="../Bridge_Specific/FurAffinityBridge.html">FurAffinityBridge</a></li><li class='Nav__item '><a href="../Bridge_Specific/Furaffinityuser.html">Furaffinityuser</a></li><li class='Nav__item '><a href="../Bridge_Specific/Instagram.html">Instagram</a></li><li class='Nav__item '><a href="../Bridge_Specific/PixivBridge.html">PixivBridge</a></li><li class='Nav__item '><a href="../Bridge_Specific/Substack.html">Substack</a></li><li class='Nav__item '><a href="../Bridge_Specific/TwitterV2.html">TwitterV2</a></li><li class='Nav__item '><a href="../Bridge_Specific/Vk2.html">Vk2</a></li></ul></li></ul>
            <div class="Links">
                                    <hr/>
                                            <a href="https://github.com/RSS-Bridge/rss-bridge" target="_blank"  rel="noopener noreferrer">GitHub Repository</a>
                        <br />
                                            <a href="https://github.com/RSS-Bridge/rss-bridge/issues" target="_blank"  rel="noopener noreferrer">Help/Support/Bugs</a>
                        <br />
                                            <a href="https://github.com/RSS-Bridge/rss-bridge/pkgs/container/rss-bridge" target="_blank"  rel="noopener noreferrer">Docker Images</a>
                        <br />
                                                </div>

                            <div class="CodeToggler">
                    <hr/>
                    <label class="Checkbox">Show Code Blocks                        <input type="checkbox" class="CodeToggler__button--main" checked="checked"/>
                        <div class="Checkbox__indicator"></div>
                    </label>
                </div>
            
            <div class="DarkModeToggler">
                <hr/>
                <label class="Checkbox">Dark Mode                    <input type="checkbox" class="ColorMode__button" />
                    <div class="Checkbox__indicator"></div>
                </label>
            </div>

                
                                    <div class="PoweredBy">
                        <hr/>
                        Powered by Daux.io                    </div>
                        </div>
    </aside>
    <div class="Columns__right">
        <div class="Columns__right__content">
            <div class="doc_content">
                <article class="Page">

    <div class="Page__header">
        <h1><a href="../For_Developers/index.html">For Developers</a> <svg class="Page__header--separator" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 477.175 477.175"><path d="M360.73 229.075l-225.1-225.1c-5.3-5.3-13.8-5.3-19.1 0s-5.3 13.8 0 19.1l215.5 215.5-215.5 215.5c-5.3 5.3-5.3 13.8 0 19.1 2.6 2.6 6.1 4 9.5 4 3.4 0 6.9-1.3 9.5-4l225.1-225.1c5.3-5.2 5.3-13.8.1-19z"/></svg> <a href="../For_Developers/Coding_style_policy.html">Coding style policy</a></h1>
                <span class="ModifiedDate">
            November 3, 2024 at 9:33 AM        </span>
                        <span class="EditOn">
            <a href="https://github.com/RSS-Bridge/rss-bridge/tree/master/docs/04_For_Developers/01_Coding_style_policy.md" target="_blank">
                Edit on GitHub            </a>
        </span>
            </div>

    <div class="s-content">
        <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>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 <a href="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
<a href="https://github.com/squizlabs/PHP_CodeSniffer" class="Link--external" rel="noopener noreferrer"><code>phpcs</code></a> and
<a href="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>
<pre><code class="hljs shell">./vendor/bin/phpcs --standard=phpcs.xml --warning-severity=0 --extensions=php -p ./
./vendor/bin/phpunit
</code></pre>
<p>The following list provides an overview of all policies applied to RSS-Bridge.</p>
<h1><a id="whitespace" href="#whitespace" class="Permalink" aria-hidden="true" title="Permalink">#</a>Whitespace</h1>
<h2><a id="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>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">{
    // code here
} // This is the end of the file
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">{
    // code here
}
// This is the end of the file
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PSR2/Sniffs/Files/EndFileNewlineSniff.php" class="Link--external" rel="noopener noreferrer"><code>PSR2.Files.EndFileNewline</code></a></p>
<h2><a id="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>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">echo 'Hello World!' ;
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">echo 'Hello World!';
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/WhiteSpace/SemicolonSpacingSniff.php" class="Link--external" rel="noopener noreferrer"><code>Squiz.WhiteSpace.SemicolonSpacing</code></a></p>
<h2><a id="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>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php" class="Link--external" rel="noopener noreferrer"><code>Squiz.WhiteSpace.SuperfluousWhitespace</code></a></p>
<h1><a id="indentation" href="#indentation" class="Permalink" aria-hidden="true" title="Permalink">#</a>Indentation</h1>
<h2><a id="use-spaces-indentation" href="#use-spaces-indentation" class="Permalink" aria-hidden="true" title="Permalink">#</a>Use spaces indentation</h2>
<h1><a id="maximum-line-length" href="#maximum-line-length" class="Permalink" aria-hidden="true" title="Permalink">#</a>Maximum Line Length</h1>
<p>180</p>
<h1><a id="strings" href="#strings" class="Permalink" aria-hidden="true" title="Permalink">#</a>Strings</h1>
<h2><a id="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>&quot;\n&quot;</code>) or inlined variables (i.e. <code>&quot;My name is {$name}&quot;</code>);</p>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">echo &quot;Hello World!&quot;;
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">echo 'Hello World!';
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/Strings/DoubleQuoteUsageSniff.php" class="Link--external" rel="noopener noreferrer"><code>Squiz.Strings.DoubleQuoteUsage</code></a></p>
<h2><a id="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>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">$text = $greeting.' '.$name.'!';
</code></pre>
<p><strong>Good</strong> (add spaces)</p>
<pre><code class="language-PHP">$text = $greeting . ' ' . $name . '!';
</code></pre>
</div></details><br>
<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>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">$text = $greeting.' '.$name.'!';
</code></pre>
<p><strong>Good</strong> (split into multiple lines)</p>
<pre><code class="language-PHP">$text = $greeting
. ' '
. $name
. '!';
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/Strings/ConcatenationSpacingSniff.php" class="Link--external" rel="noopener noreferrer"><code>Squiz.Strings.ConcatenationSpacing</code></a></p>
<h2><a id="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: <a href="#maximum-line-length">Maximum line length</a></p>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">$text = 'This is' . 'a bad idea!';
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">$text = 'This is a good idea!';
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/Strings/UnnecessaryStringConcatSniff.php" class="Link--external" rel="noopener noreferrer"><code>Generic.Strings.UnnecessaryStringConcat</code></a></p>
<h1><a id="constants" href="#constants" class="Permalink" aria-hidden="true" title="Permalink">#</a>Constants</h1>
<h2><a id="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>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">const pi = 3.14;
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">const PI = 3.14;
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php" class="Link--external" rel="noopener noreferrer"><code>Generic.NamingConventions.UpperCaseConstantName</code></a></p>
<h1><a id="keywords" href="#keywords" class="Permalink" aria-hidden="true" title="Permalink">#</a>Keywords</h1>
<h2><a id="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>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">if($condition === TRUE &amp;&amp; $error === FALSE) {
    return NULL;
}
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">if($condition === true &amp;&amp; $error === false) {
    return null;
}
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/PHP/LowerCaseConstantSniff.php" class="Link--external" rel="noopener noreferrer"><code>Generic.PHP.LowerCaseConstant</code></a></p>
<h1><a id="operators" href="#operators" class="Permalink" aria-hidden="true" title="Permalink">#</a>Operators</h1>
<h2><a id="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>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">$text='Hello '.$name.'!';
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">$text = 'Hello ' . $name . '!';
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php" class="Link--external" rel="noopener noreferrer"><code>Squiz.WhiteSpace.OperatorSpacing</code></a></p>
<h1><a id="functions" href="#functions" class="Permalink" aria-hidden="true" title="Permalink">#</a>Functions</h1>
<h2><a id="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>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">function showTitle($duration = 60000, $title) { ... }
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">function showTitle($title, $duration = 60000) { ... }
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PEAR/Sniffs/Functions/ValidDefaultValueSniff.php" class="Link--external" rel="noopener noreferrer"><code>PEAR.Functions.ValidDefaultValue</code></a></p>
<h2><a id="calling-functions" href="#calling-functions" class="Permalink" aria-hidden="true" title="Permalink">#</a>Calling functions</h2>
<p>Function calls must follow a few rules in order to maintain readability throughout the project:</p>
<p><strong>Do not add whitespace before the opening parenthesis</strong></p>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">$result = my_function ($param);
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">$result = my_function($param);
</code></pre>
</div></details><br>
<p><strong>Do not add whitespace after the opening parenthesis</strong></p>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">$result = my_function( $param);
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">$result = my_function($param);
</code></pre>
</div></details><br>
<p><strong>Do not add a space before the closing parenthesis</strong></p>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">$result = my_function($param );
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">$result = my_function($param);
</code></pre>
</div></details><br>
<p><strong>Do not add a space before a comma</strong></p>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">$result = my_function($param1 ,$param2);
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">$result = my_function($param1, $param2);
</code></pre>
</div></details><br>
<p><strong>Add a space after a comma</strong></p>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">$result = my_function($param1,$param2);
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">$result = my_function($param1, $param2);
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php" class="Link--external" rel="noopener noreferrer"><code>Generic.Functions.FunctionCallArgumentSpacing</code></a></p>
<h2><a id="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>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">if( $condition ) { ... }
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">if($condition) { ... }
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PSR2/Sniffs/ControlStructures/ControlStructureSpacingSniff.php" class="Link--external" rel="noopener noreferrer"><code>PSR2.ControlStructures.ControlStructureSpacing</code></a></p>
<h1><a id="structures" href="#structures" class="Permalink" aria-hidden="true" title="Permalink">#</a>Structures</h1>
<h2><a id="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>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">if($condition){
    ...
}
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">if($condition) {
    ...
}
</code></pre>
</div></details><br>
<p><strong>Add body into new line</strong></p>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">if($condition){ ... }
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">if($condition) {
    ...
}
</code></pre>
</div></details><br>
<p><strong>Close body in new line</strong></p>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">if($condition){
    ... }
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">if($condition) {
    ...
}
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/ControlStructures/ControlSignatureSniff.php" class="Link--external" rel="noopener noreferrer"><code>Squiz.ControlStructures.ControlSignature</code></a></p>
<h1><a id="if-statements" href="#if-statements" class="Permalink" aria-hidden="true" title="Permalink">#</a>If-Statements</h1>
<h2><a id="use-elseif-instead-of-else-if" href="#use-elseif-instead-of-else-if" class="Permalink" aria-hidden="true" title="Permalink">#</a>Use <code>elseif</code> instead of <code>else if</code></h2>
<p>For sake of consistency <code>else if</code> is considered bad practice.</p>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">if($conditionA) {

} else if($conditionB) {

}
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">if($conditionA) {

} elseif($conditionB) {

}
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PSR2/Sniffs/ControlStructures/ElseIfDeclarationSniff.php" class="Link--external" rel="noopener noreferrer"><code>PSR2.ControlStructures.ElseIfDeclaration</code></a></p>
<h2><a id="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>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">if($condition) {
    // empty statement
} else {
    // do something here
}
</code></pre>
<p><strong>Good</strong> (invert condition)</p>
<pre><code class="language-PHP">if(!$condition) {
    // do something
}
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/CodeAnalysis/EmptyStatementSniff.php" class="Link--external" rel="noopener noreferrer"><code>Generic.CodeAnalysis.EmptyStatement</code></a></p>
<h2><a id="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>
<details><summary>Example</summary><div><br>
<pre><code class="language-PHP">if(true) {

}
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/CodeAnalysis/UnconditionalIfStatementSniff.php" class="Link--external" rel="noopener noreferrer"><code>Generic.CodeAnalysis.UnconditionalIfStatement</code></a></p>
<h1><a id="classes" href="#classes" class="Permalink" aria-hidden="true" title="Permalink">#</a>Classes</h1>
<h2><a id="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 <a href="http://wiki.c2.com/?PascalCase" class="Link--external" rel="noopener noreferrer">PascalCase</a>.</p>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">class mySUPERclass { ... }
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">class MySuperClass { ... }
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PEAR/Sniffs/NamingConventions/ValidClassNameSniff.php" class="Link--external" rel="noopener noreferrer"><code>PEAR.NamingConventions.ValidClassName</code></a></p>
<h2><a id="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><code class="language-PHP">final class MyClass {
    final public function MyFunction() {

    }
}
</code></pre>
<p><strong>Good</strong> (remove the final keyword from class members)</p>
<pre><code class="language-PHP">final class MyClass {
    public function MyFunction() {

    }
}
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/CodeAnalysis/UnnecessaryFinalModifierSniff.php" class="Link--external" rel="noopener noreferrer"><code>Generic.CodeAnalysis.UnnecessaryFinalModifier</code></a></p>
<h2><a id="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>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">class MyClass extends BaseClass {
    public function BaseFunction() {
        parent::BaseFunction();
    }
}
</code></pre>
<p><strong>Good</strong> (don’t override the function)</p>
<pre><code class="language-PHP">class MyClass extends BaseClass {

}
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/CodeAnalysis/UselessOverridingMethodSniff.php" class="Link--external" rel="noopener noreferrer"><code>Generic.CodeAnalysis.UselessOverridingMethod</code></a></p>
<h2><a id="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>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">class MyClass extends BaseClass {
    public abstract function AbstractFunction() { }
    public final function FinalFunction() { }
}
</code></pre>
<p><strong>Good</strong> (<code>abstract</code> and <code>final</code> before <code>public</code>)</p>
<pre><code class="language-PHP">class MyClass extends BaseClass {
    abstract public function AbstractFunction() { }
    final public function FinalFunction() { }
}
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PSR2/Sniffs/Methods/MethodDeclarationSniff.php" class="Link--external" rel="noopener noreferrer"><code>PSR2.Methods.MethodDeclaration</code></a></p>
<h2><a id="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>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">class MyClass extends BaseClass {
    static public function StaticFunction() { }
}
</code></pre>
<p><strong>Good</strong> (<code>static</code> after <code>public</code>)</p>
<pre><code class="language-PHP">class MyClass extends BaseClass {
    public static function StaticFunction() { }
}
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PSR2/Sniffs/Methods/MethodDeclarationSniff.php" class="Link--external" rel="noopener noreferrer"><code>PSR2.Methods.MethodDeclaration</code></a></p>
<h1><a id="casting" href="#casting" class="Permalink" aria-hidden="true" title="Permalink">#</a>Casting</h1>
<h2><a id="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>
<details><summary>Example</summary><div><br>
<p><strong>Bad</strong></p>
<pre><code class="language-PHP">$text = ( string )$number;
</code></pre>
<p><strong>Good</strong></p>
<pre><code class="language-PHP">$text = (string)$number;
</code></pre>
</div></details><br>
<p><em>Reference</em>: <a href="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/WhiteSpace/CastSpacingSniff.php" class="Link--external" rel="noopener noreferrer"><code>Squiz.WhiteSpace.CastSpacing</code></a></p>
<h1><a id="arrays" href="#arrays" class="Permalink" aria-hidden="true" title="Permalink">#</a>Arrays</h1>
<h2><a id="always-use-the-short-array-syntax" href="#always-use-the-short-array-syntax" class="Permalink" aria-hidden="true" title="Permalink">#</a>Always use the short array syntax</h2>
    </div>

        <nav>
        <ul class="Pager">
            <li class=Pager--prev><a href="../For_Developers/index.html">Previous</a></li>            <li class=Pager--next><a href="../For_Developers/Pull_Request_policy.html">Next</a></li>        </ul>
    </nav>
    </article>

            </div>
        </div>
    </div>
</div>

    
    <!-- JS -->
            <script src="../themes/daux/js/daux.min.js"></script>
    
        <script>
        
        window.searchLanguage = "";
        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"};
    </script>

    <!-- Search -->
    <script type="text/javascript" src="../daux_libraries/search.min.js"></script>

    <script>
        window.search({'base_url': '../'})
    </script>
</body>
</html>