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 |
||
13 | class ar_http_cookieStore extends arBase implements arKeyValueStoreInterface { |
||
14 | |||
15 | public $values = array(); |
||
16 | protected $name = 'ARUserCookie'; |
||
17 | protected $configuration = array( |
||
18 | 'expire' => null, |
||
19 | 'path' => '/', |
||
20 | 'domain' => '', |
||
21 | 'secure' => false |
||
22 | ); |
||
23 | |||
24 | public function __construct( $name = 'ARUserCookie', $cookie = null, $configuration = array() ) { |
||
39 | |||
40 | public function __set( $name, $value ) { |
||
43 | |||
44 | public function __get( $name ) { |
||
47 | |||
48 | public function putvar( $name, $value ) { |
||
51 | |||
52 | public function getvar( $name ) { |
||
55 | |||
56 | View Code Duplication | public function configure( $name, $value = null ) { |
|
63 | |||
64 | public function save( $name = null ) { |
||
74 | |||
75 | } |
||
76 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: