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 |
||
11 | class WC_Stripe_Connect_REST_Oauth_Init_Controller extends WC_Stripe_Connect_REST_Controller { |
||
12 | |||
13 | /** |
||
14 | * REST base. |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $rest_base = 'connect/stripe/oauth/init'; |
||
19 | |||
20 | /** |
||
21 | * Stripe Connect. |
||
22 | * |
||
23 | * @var WC_Stripe_Connect |
||
24 | */ |
||
25 | protected $connect; |
||
26 | |||
27 | /** |
||
28 | * Constructor. |
||
29 | * |
||
30 | * @param WC_Stripe_Connect $connect stripe connect. |
||
31 | * @param WC_Stripe_Connect_API $api stripe connect api. |
||
32 | */ |
||
33 | public function __construct( WC_Stripe_Connect $connect, WC_Stripe_Connect_API $api ) { |
||
39 | |||
40 | /** |
||
41 | * Initiate OAuth flow. |
||
42 | * |
||
43 | * @param array $request POST request. |
||
44 | * |
||
45 | * @return array|WP_Error |
||
46 | */ |
||
47 | public function post( $request ) { |
||
68 | } |
||
69 | } |
||
70 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.