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 AbstractClassNameSniff implements PHP_CodeSniffer_Sniff |
||
21 | { |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | const NAME = 'ZenifyCodingStandard.Naming.AbstractClassName'; |
||
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) |
|
67 | |||
68 | |||
69 | 1 | private function isClassAbstract() : bool |
|
74 | |||
75 | |||
76 | /** |
||
77 | * @return string|FALSE |
||
78 | */ |
||
79 | 1 | View Code Duplication | private function getClassName() |
88 | |||
89 | } |
||
90 |
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: