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
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
|
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.
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 [phpcs.xml](https://github.com/RSS-Bridge/rss-bridge/blob/master/phpcs.xml) for a complete list of policies enforced by Travis-CI.
If you want to run the checks locally, make sure you have
[`phpcs`](https://github.com/squizlabs/PHP_CodeSniffer) and
[`phpunit`](https://phpunit.de/) installed on your machine and run following commands in the root directory of RSS-Bridge (tested on Debian):
```console
./vendor/bin/phpcs --standard=phpcs.xml --warning-severity=0 --extensions=php -p ./
./vendor/bin/phpunit
```
The following list provides an overview of all policies applied to RSS-Bridge.
# Whitespace
## Add a new line at the end of a file
Each PHP/CSS/HTML file must end with a new line at the end of a file.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
{
// code here
} // This is the end of the file
```
**Good**
```PHP
{
// code here
}
// This is the end of the file
```
</div></details><br>
_Reference_: [`PSR2.Files.EndFileNewline`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PSR2/Sniffs/Files/EndFileNewlineSniff.php)
## Do not add a whitespace before a semicolon
A semicolon indicates the end of a line of code. Spaces before the semicolon is unnecessary and must be removed.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
echo 'Hello World!' ;
```
**Good**
```PHP
echo 'Hello World!';
```
</div></details><br>
_Reference_: [`Squiz.WhiteSpace.SemicolonSpacing`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/WhiteSpace/SemicolonSpacingSniff.php)
## Do not add whitespace at start or end of a file or end of a line
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.
_Reference_: [`Squiz.WhiteSpace.SuperfluousWhitespace`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php)
# Indentation
## Use spaces indentation
# Maximum Line Length
180
# Strings
## Whenever possible use single quote strings
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. `"\n"`) or inlined variables (i.e. `"My name is {$name}"`);
<details><summary>Example</summary><div><br>
**Bad**
```PHP
echo "Hello World!";
```
**Good**
```PHP
echo 'Hello World!';
```
</div></details><br>
_Reference_: [`Squiz.Strings.DoubleQuoteUsage`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/Strings/DoubleQuoteUsageSniff.php)
## Add spaces around the concatenation operator
The concatenation operator should have one space on both sides in order to improve readability.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
$text = $greeting.' '.$name.'!';
```
**Good** (add spaces)
```PHP
$text = $greeting . ' ' . $name . '!';
```
</div></details><br>
You may break long lines into multiple lines using the concatenation operator. That way readability can improve considerable when combining lots of variables.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
$text = $greeting.' '.$name.'!';
```
**Good** (split into multiple lines)
```PHP
$text = $greeting
. ' '
. $name
. '!';
```
</div></details><br>
_Reference_: [`Squiz.Strings.ConcatenationSpacing`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/Strings/ConcatenationSpacingSniff.php)
## Use a single string instead of concatenating
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: [Maximum line length](#maximum-line-length)
<details><summary>Example</summary><div><br>
**Bad**
```PHP
$text = 'This is' . 'a bad idea!';
```
**Good**
```PHP
$text = 'This is a good idea!';
```
</div></details><br>
_Reference_: [`Generic.Strings.UnnecessaryStringConcat`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/Strings/UnnecessaryStringConcatSniff.php)
# Constants
## Use UPPERCASE for constants
As in most languages, constants should be written in UPPERCASE.
_Notice_: This does not apply to keywords!
<details><summary>Example</summary><div><br>
**Bad**
```PHP
const pi = 3.14;
```
**Good**
```PHP
const PI = 3.14;
```
</div></details><br>
_Reference_: [`Generic.NamingConventions.UpperCaseConstantName`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/NamingConventions/UpperCaseConstantNameSniff.php)
# Keywords
## Use lowercase for `true`, `false` and `null`
`true`, `false` and `null` must be written in lower case letters.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
if($condition === TRUE && $error === FALSE) {
return NULL;
}
```
**Good**
```PHP
if($condition === true && $error === false) {
return null;
}
```
</div></details><br>
_Reference_: [`Generic.PHP.LowerCaseConstant`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/PHP/LowerCaseConstantSniff.php)
# Operators
## Operators must have a space around them
Operators must be readable and therefore should have spaces around them.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
$text='Hello '.$name.'!';
```
**Good**
```PHP
$text = 'Hello ' . $name . '!';
```
</div></details><br>
_Reference_: [`Squiz.WhiteSpace.OperatorSpacing`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/WhiteSpace/OperatorSpacingSniff.php)
# Functions
## Parameters with default values must appear last in functions
It is considered good practice to make parameters with default values last in function declarations.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
function showTitle($duration = 60000, $title) { ... }
```
**Good**
```PHP
function showTitle($title, $duration = 60000) { ... }
```
</div></details><br>
_Reference_: [`PEAR.Functions.ValidDefaultValue`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PEAR/Sniffs/Functions/ValidDefaultValueSniff.php)
## Calling functions
Function calls must follow a few rules in order to maintain readability throughout the project:
**Do not add whitespace before the opening parenthesis**
<details><summary>Example</summary><div><br>
**Bad**
```PHP
$result = my_function ($param);
```
**Good**
```PHP
$result = my_function($param);
```
</div></details><br>
**Do not add whitespace after the opening parenthesis**
<details><summary>Example</summary><div><br>
**Bad**
```PHP
$result = my_function( $param);
```
**Good**
```PHP
$result = my_function($param);
```
</div></details><br>
**Do not add a space before the closing parenthesis**
<details><summary>Example</summary><div><br>
**Bad**
```PHP
$result = my_function($param );
```
**Good**
```PHP
$result = my_function($param);
```
</div></details><br>
**Do not add a space before a comma**
<details><summary>Example</summary><div><br>
**Bad**
```PHP
$result = my_function($param1 ,$param2);
```
**Good**
```PHP
$result = my_function($param1, $param2);
```
</div></details><br>
**Add a space after a comma**
<details><summary>Example</summary><div><br>
**Bad**
```PHP
$result = my_function($param1,$param2);
```
**Good**
```PHP
$result = my_function($param1, $param2);
```
</div></details><br>
_Reference_: [`Generic.Functions.FunctionCallArgumentSpacing`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/Functions/FunctionCallArgumentSpacingSniff.php)
## Do not add spaces after opening or before closing bracket
Parenthesis must tightly enclose parameters.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
if( $condition ) { ... }
```
**Good**
```PHP
if($condition) { ... }
```
</div></details><br>
_Reference_: [`PSR2.ControlStructures.ControlStructureSpacing`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PSR2/Sniffs/ControlStructures/ControlStructureSpacingSniff.php)
# Structures
## Structures must always be formatted as multi-line blocks
A structure should always be treated as if it contains a multi-line block.
**Add a space after closing parenthesis**
<details><summary>Example</summary><div><br>
**Bad**
```PHP
if($condition){
...
}
```
**Good**
```PHP
if($condition) {
...
}
```
</div></details><br>
**Add body into new line**
<details><summary>Example</summary><div><br>
**Bad**
```PHP
if($condition){ ... }
```
**Good**
```PHP
if($condition) {
...
}
```
</div></details><br>
**Close body in new line**
<details><summary>Example</summary><div><br>
**Bad**
```PHP
if($condition){
... }
```
**Good**
```PHP
if($condition) {
...
}
```
</div></details><br>
_Reference_: [`Squiz.ControlStructures.ControlSignature`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/ControlStructures/ControlSignatureSniff.php)
# If-Statements
## Use `elseif` instead of `else if`
For sake of consistency `else if` is considered bad practice.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
if($conditionA) {
} else if($conditionB) {
}
```
**Good**
```PHP
if($conditionA) {
} elseif($conditionB) {
}
```
</div></details><br>
_Reference_: [`PSR2.ControlStructures.ElseIfDeclaration`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PSR2/Sniffs/ControlStructures/ElseIfDeclarationSniff.php)
## Do not write empty statements
Empty statements are considered bad practice and must be avoided.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
if($condition) {
// empty statement
} else {
// do something here
}
```
**Good** (invert condition)
```PHP
if(!$condition) {
// do something
}
```
</div></details><br>
_Reference_: [`Generic.CodeAnalysis.EmptyStatement`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/CodeAnalysis/EmptyStatementSniff.php)
## Do not write unconditional if-statements
If-statements without conditions are considered bad practice and must be avoided.
<details><summary>Example</summary><div><br>
```PHP
if(true) {
}
```
</div></details><br>
_Reference_: [`Generic.CodeAnalysis.UnconditionalIfStatement`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/CodeAnalysis/UnconditionalIfStatementSniff.php)
# Classes
## Use PascalCase for class names
Class names must be written in [PascalCase](http://wiki.c2.com/?PascalCase).
<details><summary>Example</summary><div><br>
**Bad**
```PHP
class mySUPERclass { ... }
```
**Good**
```PHP
class MySuperClass { ... }
```
</div></details><br>
_Reference_: [`PEAR.NamingConventions.ValidClassName`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PEAR/Sniffs/NamingConventions/ValidClassNameSniff.php)
## Do not use final statements inside final classes
Final classes cannot be extended, so it doesn't make sense to add the final keyword to class members.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
final class MyClass {
final public function MyFunction() {
}
}
```
**Good** (remove the final keyword from class members)
```PHP
final class MyClass {
public function MyFunction() {
}
}
```
</div></details><br>
_Reference_: [`Generic.CodeAnalysis.UnnecessaryFinalModifier`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/CodeAnalysis/UnnecessaryFinalModifierSniff.php)
## Do not override methods to call their parent
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.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
class MyClass extends BaseClass {
public function BaseFunction() {
parent::BaseFunction();
}
}
```
**Good** (don't override the function)
```PHP
class MyClass extends BaseClass {
}
```
</div></details><br>
_Reference_: [`Generic.CodeAnalysis.UselessOverridingMethod`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Generic/Sniffs/CodeAnalysis/UselessOverridingMethodSniff.php)
## abstract and final declarations MUST precede the visibility declaration
When declaring `abstract` and `final` functions, the visibility (scope) must follow after `abstract` or `final`.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
class MyClass extends BaseClass {
public abstract function AbstractFunction() { }
public final function FinalFunction() { }
}
```
**Good** (`abstract` and `final` before `public`)
```PHP
class MyClass extends BaseClass {
abstract public function AbstractFunction() { }
final public function FinalFunction() { }
}
```
</div></details><br>
_Reference_: [`PSR2.Methods.MethodDeclaration`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PSR2/Sniffs/Methods/MethodDeclarationSniff.php)
## static declaration MUST come after the visibility declaration
The `static` keyword must come after the visibility (scope) parameter.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
class MyClass extends BaseClass {
static public function StaticFunction() { }
}
```
**Good** (`static` after `public`)
```PHP
class MyClass extends BaseClass {
public static function StaticFunction() { }
}
```
</div></details><br>
_Reference_: [`PSR2.Methods.MethodDeclaration`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/PSR2/Sniffs/Methods/MethodDeclarationSniff.php)
# Casting
## Do not add spaces when casting
The casting type should be put into parenthesis without spaces.
<details><summary>Example</summary><div><br>
**Bad**
```PHP
$text = ( string )$number;
```
**Good**
```PHP
$text = (string)$number;
```
</div></details><br>
_Reference_: [`Squiz.WhiteSpace.CastSpacing`](https://github.com/squizlabs/PHP_CodeSniffer/blob/master/src/Standards/Squiz/Sniffs/WhiteSpace/CastSpacingSniff.php)
# Arrays
## Always use the short array syntax
|