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 |
||
8 | class IpCheck |
||
|
|||
9 | { |
||
10 | public $ipin; |
||
11 | public $ipout; |
||
12 | public $ipver; |
||
13 | |||
14 | // Return IP type. 4 for IPv4, 6 for IPv6, 0 for bad IP. |
||
15 | |||
16 | /** |
||
17 | * @param $ipValue |
||
18 | */ |
||
19 | public function address_type($ipValue) |
||
56 | |||
57 | /** Check whether the given address is an IP address |
||
58 | * |
||
59 | * @param string $ip Given IP address |
||
60 | * |
||
61 | * @return string A if IPv4, AAAA if IPv6 or 0 if invalid |
||
62 | */ |
||
63 | public function isValidIpAddress($ip) |
||
74 | } |
||
75 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.