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 |
||
3 | class WP_Test_REST_Controller extends WP_Test_REST_TestCase { |
||
4 | |||
5 | public function setUp() { |
||
6 | parent::setUp(); |
||
7 | $this->request = new WP_REST_Request( 'GET', '/wp/v2/testroute', array( |
||
8 | 'args' => array( |
||
9 | 'someinteger' => array( |
||
10 | 'type' => 'integer', |
||
11 | ), |
||
12 | 'someboolean' => array( |
||
13 | 'type' => 'boolean', |
||
14 | ), |
||
15 | 'somestring' => array( |
||
16 | 'type' => 'string', |
||
17 | ), |
||
18 | 'someenum' => array( |
||
19 | 'type' => 'string', |
||
20 | 'enum' => array( 'a' ), |
||
21 | ), |
||
22 | 'somedate' => array( |
||
23 | 'type' => 'string', |
||
24 | 'format' => 'date-time', |
||
25 | ), |
||
26 | 'someemail' => array( |
||
27 | 'type' => 'string', |
||
28 | 'format' => 'email', |
||
29 | ), |
||
30 | ), |
||
31 | )); |
||
32 | } |
||
33 | |||
34 | View Code Duplication | public function test_validate_schema_type_integer() { |
|
45 | |||
46 | public function test_validate_schema_type_boolean() { |
||
64 | |||
65 | View Code Duplication | public function test_validate_schema_type_string() { |
|
76 | |||
77 | public function test_validate_schema_enum() { |
||
88 | |||
89 | public function test_validate_schema_format_email() { |
||
100 | |||
101 | public function test_validate_schema_format_date_time() { |
||
112 | |||
113 | View Code Duplication | public function test_get_endpoint_args_for_item_schema_description() { |
|
119 | |||
120 | View Code Duplication | public function test_get_endpoint_args_for_item_schema_arg_options() { |
|
128 | |||
129 | public function test_get_endpoint_args_for_item_schema_default_value() { |
||
137 | } |
||
138 |