Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
20 | final class InterfaceNameSniff implements PHP_CodeSniffer_Sniff |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | const NAME = 'ZenifyCodingStandard.Naming.InterfaceName'; |
||
27 | |||
28 | /** |
||
29 | * @var PHP_CodeSniffer_File |
||
30 | */ |
||
31 | private $file; |
||
32 | |||
33 | /** |
||
34 | * @var int |
||
35 | */ |
||
36 | private $position; |
||
37 | |||
38 | |||
39 | /** |
||
40 | * @return int[] |
||
41 | */ |
||
42 | 1 | public function register() : array |
|
46 | |||
47 | |||
48 | /** |
||
49 | * @param PHP_CodeSniffer_File $file |
||
50 | * @param int $position |
||
51 | */ |
||
52 | 1 | public function process(PHP_CodeSniffer_File $file, $position) |
|
64 | |||
65 | |||
66 | /** |
||
67 | * @return string|FALSE |
||
68 | */ |
||
69 | 1 | View Code Duplication | private function getInterfaceName() |
78 | |||
79 | } |
||
80 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: