post()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 21
loc 21
rs 9.584
c 0
b 0
f 0
1
<?php
2
3
if ( ! defined( 'ABSPATH' ) ) {
4
	exit;
5
}
6
7 View Code Duplication
if ( ! class_exists( 'WC_Stripe_Connect_REST_Oauth_Connect_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 Connect controller class.
10
	 */
11
	class WC_Stripe_Connect_REST_Oauth_Connect_Controller extends WC_Stripe_Connect_REST_Controller {
12
13
		/**
14
		 * REST base.
15
		 *
16
		 * @var string
17
		 */
18
		protected $rest_base = 'connect/stripe/oauth/connect';
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
		 * OAuth Connection 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->connect_oauth( $data['state'], $data['code'] );
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
				'account_id' => $response->accountId, // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
66
			);
67
		}
68
	}
69
}
70