WC_Stripe_Connect_REST_Oauth_Init_Controller   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 58
loc 58
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A post() 21 21 3

How to fix   Duplicated Code   

Duplicated Code

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
2
3
if ( ! defined( 'ABSPATH' ) ) {
4
	exit;
5
}
6
7 View Code Duplication
if ( ! class_exists( 'WC_Stripe_Connect_REST_Oauth_Init_Controller' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
8
	/**
9
	 * Stripe Connect Oauth Init controller class.
10
	 */
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 ) {
34
35
			parent::__construct( $api );
36
37
			$this->connect = $connect;
38
		}
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 ) {
48
49
			$data     = $request->get_json_params();
0 ignored issues
show
Bug introduced by
The method get_json_params cannot be called on $request (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
50
			$response = $this->connect->get_oauth_url( isset( $data['returnUrl'] ) ? $data['returnUrl'] : '' );
51
52
			if ( is_wp_error( $response ) ) {
53
54
				WC_Stripe_Logger::log( $response, __CLASS__ );
55
56
				return new WP_Error(
57
					$response->get_error_code(),
58
					$response->get_error_message(),
59
					array( 'status' => 400 )
60
				);
61
			}
62
63
			return array(
64
				'success'  => true,
65
				'oauthUrl' => $response,
66
			);
67
		}
68
	}
69
}
70