Passed
Push — main ( aaef5c...e4c121 )
by TARIQ
71:39
created
woocommerce/packages/woocommerce-blocks/src/StoreApi/Authentication.php 2 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -5,54 +5,54 @@
 block discarded – undo
5 5
  * Authentication class.
6 6
  */
7 7
 class Authentication {
8
-	/**
9
-	 * Hook into WP lifecycle events.
10
-	 */
11
-	public function init() {
12
-		add_filter( 'rest_authentication_errors', array( $this, 'check_authentication' ) );
13
-		add_action( 'set_logged_in_cookie', array( $this, 'set_logged_in_cookie' ) );
14
-	}
8
+    /**
9
+     * Hook into WP lifecycle events.
10
+     */
11
+    public function init() {
12
+        add_filter( 'rest_authentication_errors', array( $this, 'check_authentication' ) );
13
+        add_action( 'set_logged_in_cookie', array( $this, 'set_logged_in_cookie' ) );
14
+    }
15 15
 
16
-	/**
17
-	 * The Store API does not require authentication.
18
-	 *
19
-	 * @param \WP_Error|mixed $result Error from another authentication handler, null if we should handle it, or another value if not.
20
-	 * @return \WP_Error|null|bool
21
-	 */
22
-	public function check_authentication( $result ) {
23
-		if ( ! empty( $result ) ) {
24
-			return $result;
25
-		}
16
+    /**
17
+     * The Store API does not require authentication.
18
+     *
19
+     * @param \WP_Error|mixed $result Error from another authentication handler, null if we should handle it, or another value if not.
20
+     * @return \WP_Error|null|bool
21
+     */
22
+    public function check_authentication( $result ) {
23
+        if ( ! empty( $result ) ) {
24
+            return $result;
25
+        }
26 26
 
27
-		if ( $this->is_request_to_store_api() ) {
28
-			return true;
29
-		}
27
+        if ( $this->is_request_to_store_api() ) {
28
+            return true;
29
+        }
30 30
 
31
-		return $result;
32
-	}
31
+        return $result;
32
+    }
33 33
 
34
-	/**
35
-	 * When the login cookies are set, they are not available until the next page reload. For the Store API, specifically
36
-	 * for returning updated nonces, we need this to be available immediately.
37
-	 *
38
-	 * @param string $logged_in_cookie The value for the logged in cookie.
39
-	 */
40
-	public function set_logged_in_cookie( $logged_in_cookie ) {
41
-		if ( ! defined( 'LOGGED_IN_COOKIE' ) || ! $this->is_request_to_store_api() ) {
42
-			return;
43
-		}
44
-		$_COOKIE[ LOGGED_IN_COOKIE ] = $logged_in_cookie;
45
-	}
34
+    /**
35
+     * When the login cookies are set, they are not available until the next page reload. For the Store API, specifically
36
+     * for returning updated nonces, we need this to be available immediately.
37
+     *
38
+     * @param string $logged_in_cookie The value for the logged in cookie.
39
+     */
40
+    public function set_logged_in_cookie( $logged_in_cookie ) {
41
+        if ( ! defined( 'LOGGED_IN_COOKIE' ) || ! $this->is_request_to_store_api() ) {
42
+            return;
43
+        }
44
+        $_COOKIE[ LOGGED_IN_COOKIE ] = $logged_in_cookie;
45
+    }
46 46
 
47
-	/**
48
-	 * Check if is request to the Store API.
49
-	 *
50
-	 * @return bool
51
-	 */
52
-	protected function is_request_to_store_api() {
53
-		if ( empty( $GLOBALS['wp']->query_vars['rest_route'] ) ) {
54
-			return false;
55
-		}
56
-		return 0 === strpos( $GLOBALS['wp']->query_vars['rest_route'], '/wc/store/' );
57
-	}
47
+    /**
48
+     * Check if is request to the Store API.
49
+     *
50
+     * @return bool
51
+     */
52
+    protected function is_request_to_store_api() {
53
+        if ( empty( $GLOBALS['wp']->query_vars['rest_route'] ) ) {
54
+            return false;
55
+        }
56
+        return 0 === strpos( $GLOBALS['wp']->query_vars['rest_route'], '/wc/store/' );
57
+    }
58 58
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -9,8 +9,8 @@  discard block
 block discarded – undo
9 9
 	 * Hook into WP lifecycle events.
10 10
 	 */
11 11
 	public function init() {
12
-		add_filter( 'rest_authentication_errors', array( $this, 'check_authentication' ) );
13
-		add_action( 'set_logged_in_cookie', array( $this, 'set_logged_in_cookie' ) );
12
+		add_filter('rest_authentication_errors', array($this, 'check_authentication'));
13
+		add_action('set_logged_in_cookie', array($this, 'set_logged_in_cookie'));
14 14
 	}
15 15
 
16 16
 	/**
@@ -19,12 +19,12 @@  discard block
 block discarded – undo
19 19
 	 * @param \WP_Error|mixed $result Error from another authentication handler, null if we should handle it, or another value if not.
20 20
 	 * @return \WP_Error|null|bool
21 21
 	 */
22
-	public function check_authentication( $result ) {
23
-		if ( ! empty( $result ) ) {
22
+	public function check_authentication($result) {
23
+		if (!empty($result)) {
24 24
 			return $result;
25 25
 		}
26 26
 
27
-		if ( $this->is_request_to_store_api() ) {
27
+		if ($this->is_request_to_store_api()) {
28 28
 			return true;
29 29
 		}
30 30
 
@@ -37,11 +37,11 @@  discard block
 block discarded – undo
37 37
 	 *
38 38
 	 * @param string $logged_in_cookie The value for the logged in cookie.
39 39
 	 */
40
-	public function set_logged_in_cookie( $logged_in_cookie ) {
41
-		if ( ! defined( 'LOGGED_IN_COOKIE' ) || ! $this->is_request_to_store_api() ) {
40
+	public function set_logged_in_cookie($logged_in_cookie) {
41
+		if (!defined('LOGGED_IN_COOKIE') || !$this->is_request_to_store_api()) {
42 42
 			return;
43 43
 		}
44
-		$_COOKIE[ LOGGED_IN_COOKIE ] = $logged_in_cookie;
44
+		$_COOKIE[LOGGED_IN_COOKIE] = $logged_in_cookie;
45 45
 	}
46 46
 
47 47
 	/**
@@ -50,9 +50,9 @@  discard block
 block discarded – undo
50 50
 	 * @return bool
51 51
 	 */
52 52
 	protected function is_request_to_store_api() {
53
-		if ( empty( $GLOBALS['wp']->query_vars['rest_route'] ) ) {
53
+		if (empty($GLOBALS['wp']->query_vars['rest_route'])) {
54 54
 			return false;
55 55
 		}
56
-		return 0 === strpos( $GLOBALS['wp']->query_vars['rest_route'], '/wc/store/' );
56
+		return 0 === strpos($GLOBALS['wp']->query_vars['rest_route'], '/wc/store/');
57 57
 	}
58 58
 }
Please login to merge, or discard this patch.
woocommerce/packages/woocommerce-blocks/src/StoreApi/SchemaController.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -8,68 +8,68 @@
 block discarded – undo
8 8
  */
9 9
 class SchemaController {
10 10
 
11
-	/**
12
-	 * Stores schema class instances.
13
-	 *
14
-	 * @var Schemas\V1\AbstractSchema[]
15
-	 */
16
-	protected $schemas = [];
11
+    /**
12
+     * Stores schema class instances.
13
+     *
14
+     * @var Schemas\V1\AbstractSchema[]
15
+     */
16
+    protected $schemas = [];
17 17
 
18
-	/**
19
-	 * Stores Rest Extending instance
20
-	 *
21
-	 * @var ExtendSchema
22
-	 */
23
-	private $extend;
18
+    /**
19
+     * Stores Rest Extending instance
20
+     *
21
+     * @var ExtendSchema
22
+     */
23
+    private $extend;
24 24
 
25
-	/**
26
-	 * Constructor.
27
-	 *
28
-	 * @param ExtendSchema $extend Rest Extending instance.
29
-	 */
30
-	public function __construct( ExtendSchema $extend ) {
31
-		$this->extend  = $extend;
32
-		$this->schemas = [
33
-			'v1' => [
34
-				Schemas\V1\BatchSchema::IDENTIFIER         => Schemas\V1\BatchSchema::class,
35
-				Schemas\V1\ErrorSchema::IDENTIFIER         => Schemas\V1\ErrorSchema::class,
36
-				Schemas\V1\ImageAttachmentSchema::IDENTIFIER => Schemas\V1\ImageAttachmentSchema::class,
37
-				Schemas\V1\TermSchema::IDENTIFIER          => Schemas\V1\TermSchema::class,
38
-				Schemas\V1\BillingAddressSchema::IDENTIFIER => Schemas\V1\BillingAddressSchema::class,
39
-				Schemas\V1\ShippingAddressSchema::IDENTIFIER => Schemas\V1\ShippingAddressSchema::class,
40
-				Schemas\V1\CartShippingRateSchema::IDENTIFIER => Schemas\V1\CartShippingRateSchema::class,
41
-				Schemas\V1\CartShippingRateSchema::IDENTIFIER => Schemas\V1\CartShippingRateSchema::class,
42
-				Schemas\V1\CartCouponSchema::IDENTIFIER    => Schemas\V1\CartCouponSchema::class,
43
-				Schemas\V1\CartFeeSchema::IDENTIFIER       => Schemas\V1\CartFeeSchema::class,
44
-				Schemas\V1\CartItemSchema::IDENTIFIER      => Schemas\V1\CartItemSchema::class,
45
-				Schemas\V1\CartSchema::IDENTIFIER          => Schemas\V1\CartSchema::class,
46
-				Schemas\V1\CartExtensionsSchema::IDENTIFIER => Schemas\V1\CartExtensionsSchema::class,
47
-				Schemas\V1\CheckoutSchema::IDENTIFIER      => Schemas\V1\CheckoutSchema::class,
48
-				Schemas\V1\ProductSchema::IDENTIFIER       => Schemas\V1\ProductSchema::class,
49
-				Schemas\V1\ProductAttributeSchema::IDENTIFIER => Schemas\V1\ProductAttributeSchema::class,
50
-				Schemas\V1\ProductCategorySchema::IDENTIFIER => Schemas\V1\ProductCategorySchema::class,
51
-				Schemas\V1\ProductCollectionDataSchema::IDENTIFIER => Schemas\V1\ProductCollectionDataSchema::class,
52
-				Schemas\V1\ProductReviewSchema::IDENTIFIER => Schemas\V1\ProductReviewSchema::class,
53
-			],
54
-		];
55
-	}
25
+    /**
26
+     * Constructor.
27
+     *
28
+     * @param ExtendSchema $extend Rest Extending instance.
29
+     */
30
+    public function __construct( ExtendSchema $extend ) {
31
+        $this->extend  = $extend;
32
+        $this->schemas = [
33
+            'v1' => [
34
+                Schemas\V1\BatchSchema::IDENTIFIER         => Schemas\V1\BatchSchema::class,
35
+                Schemas\V1\ErrorSchema::IDENTIFIER         => Schemas\V1\ErrorSchema::class,
36
+                Schemas\V1\ImageAttachmentSchema::IDENTIFIER => Schemas\V1\ImageAttachmentSchema::class,
37
+                Schemas\V1\TermSchema::IDENTIFIER          => Schemas\V1\TermSchema::class,
38
+                Schemas\V1\BillingAddressSchema::IDENTIFIER => Schemas\V1\BillingAddressSchema::class,
39
+                Schemas\V1\ShippingAddressSchema::IDENTIFIER => Schemas\V1\ShippingAddressSchema::class,
40
+                Schemas\V1\CartShippingRateSchema::IDENTIFIER => Schemas\V1\CartShippingRateSchema::class,
41
+                Schemas\V1\CartShippingRateSchema::IDENTIFIER => Schemas\V1\CartShippingRateSchema::class,
42
+                Schemas\V1\CartCouponSchema::IDENTIFIER    => Schemas\V1\CartCouponSchema::class,
43
+                Schemas\V1\CartFeeSchema::IDENTIFIER       => Schemas\V1\CartFeeSchema::class,
44
+                Schemas\V1\CartItemSchema::IDENTIFIER      => Schemas\V1\CartItemSchema::class,
45
+                Schemas\V1\CartSchema::IDENTIFIER          => Schemas\V1\CartSchema::class,
46
+                Schemas\V1\CartExtensionsSchema::IDENTIFIER => Schemas\V1\CartExtensionsSchema::class,
47
+                Schemas\V1\CheckoutSchema::IDENTIFIER      => Schemas\V1\CheckoutSchema::class,
48
+                Schemas\V1\ProductSchema::IDENTIFIER       => Schemas\V1\ProductSchema::class,
49
+                Schemas\V1\ProductAttributeSchema::IDENTIFIER => Schemas\V1\ProductAttributeSchema::class,
50
+                Schemas\V1\ProductCategorySchema::IDENTIFIER => Schemas\V1\ProductCategorySchema::class,
51
+                Schemas\V1\ProductCollectionDataSchema::IDENTIFIER => Schemas\V1\ProductCollectionDataSchema::class,
52
+                Schemas\V1\ProductReviewSchema::IDENTIFIER => Schemas\V1\ProductReviewSchema::class,
53
+            ],
54
+        ];
55
+    }
56 56
 
57
-	/**
58
-	 * Get a schema class instance.
59
-	 *
60
-	 * @throws \Exception If the schema does not exist.
61
-	 *
62
-	 * @param string $name Name of schema.
63
-	 * @param int    $version API Version being requested.
64
-	 * @return Schemas\V1\AbstractSchema A new instance of the requested schema.
65
-	 */
66
-	public function get( $name, $version = 1 ) {
67
-		$schema = $this->schemas[ "v${version}" ][ $name ] ?? false;
57
+    /**
58
+     * Get a schema class instance.
59
+     *
60
+     * @throws \Exception If the schema does not exist.
61
+     *
62
+     * @param string $name Name of schema.
63
+     * @param int    $version API Version being requested.
64
+     * @return Schemas\V1\AbstractSchema A new instance of the requested schema.
65
+     */
66
+    public function get( $name, $version = 1 ) {
67
+        $schema = $this->schemas[ "v${version}" ][ $name ] ?? false;
68 68
 
69
-		if ( ! $schema ) {
70
-			throw new \Exception( "${name} v{$version} schema does not exist" );
71
-		}
69
+        if ( ! $schema ) {
70
+            throw new \Exception( "${name} v{$version} schema does not exist" );
71
+        }
72 72
 
73
-		return new $schema( $this->extend, $this );
74
-	}
73
+        return new $schema( $this->extend, $this );
74
+    }
75 75
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	 *
28 28
 	 * @param ExtendSchema $extend Rest Extending instance.
29 29
 	 */
30
-	public function __construct( ExtendSchema $extend ) {
30
+	public function __construct(ExtendSchema $extend) {
31 31
 		$this->extend  = $extend;
32 32
 		$this->schemas = [
33 33
 			'v1' => [
@@ -63,13 +63,13 @@  discard block
 block discarded – undo
63 63
 	 * @param int    $version API Version being requested.
64 64
 	 * @return Schemas\V1\AbstractSchema A new instance of the requested schema.
65 65
 	 */
66
-	public function get( $name, $version = 1 ) {
67
-		$schema = $this->schemas[ "v${version}" ][ $name ] ?? false;
66
+	public function get($name, $version = 1) {
67
+		$schema = $this->schemas["v${version}"][$name] ?? false;
68 68
 
69
-		if ( ! $schema ) {
70
-			throw new \Exception( "${name} v{$version} schema does not exist" );
69
+		if (!$schema) {
70
+			throw new \Exception("${name} v{$version} schema does not exist");
71 71
 		}
72 72
 
73
-		return new $schema( $this->extend, $this );
73
+		return new $schema($this->extend, $this);
74 74
 	}
75 75
 }
Please login to merge, or discard this patch.
woocommerce-blocks/src/StoreApi/Exceptions/InvalidCartException.php 2 patches
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -9,66 +9,66 @@
 block discarded – undo
9 9
  * @internal This exception is thrown if the cart is in an erroneous state.
10 10
  */
11 11
 class InvalidCartException extends \Exception {
12
-	/**
13
-	 * Sanitized error code.
14
-	 *
15
-	 * @var string
16
-	 */
17
-	public $error_code;
12
+    /**
13
+     * Sanitized error code.
14
+     *
15
+     * @var string
16
+     */
17
+    public $error_code;
18 18
 
19
-	/**
20
-	 * Additional error data.
21
-	 *
22
-	 * @var array
23
-	 */
24
-	public $additional_data = [];
19
+    /**
20
+     * Additional error data.
21
+     *
22
+     * @var array
23
+     */
24
+    public $additional_data = [];
25 25
 
26
-	/**
27
-	 * All errors to display to the user.
28
-	 *
29
-	 * @var WP_Error
30
-	 */
31
-	public $error;
26
+    /**
27
+     * All errors to display to the user.
28
+     *
29
+     * @var WP_Error
30
+     */
31
+    public $error;
32 32
 
33
-	/**
34
-	 * Setup exception.
35
-	 *
36
-	 * @param string   $error_code      Machine-readable error code, e.g `woocommerce_invalid_product_id`.
37
-	 * @param WP_Error $error           The WP_Error object containing all errors relating to stock availability.
38
-	 * @param array    $additional_data Extra data (key value pairs) to expose in the error response.
39
-	 */
40
-	public function __construct( $error_code, WP_Error $error, $additional_data = [] ) {
41
-		$this->error_code      = $error_code;
42
-		$this->error           = $error;
43
-		$this->additional_data = array_filter( (array) $additional_data );
44
-		parent::__construct( '', 409 );
45
-	}
33
+    /**
34
+     * Setup exception.
35
+     *
36
+     * @param string   $error_code      Machine-readable error code, e.g `woocommerce_invalid_product_id`.
37
+     * @param WP_Error $error           The WP_Error object containing all errors relating to stock availability.
38
+     * @param array    $additional_data Extra data (key value pairs) to expose in the error response.
39
+     */
40
+    public function __construct( $error_code, WP_Error $error, $additional_data = [] ) {
41
+        $this->error_code      = $error_code;
42
+        $this->error           = $error;
43
+        $this->additional_data = array_filter( (array) $additional_data );
44
+        parent::__construct( '', 409 );
45
+    }
46 46
 
47
-	/**
48
-	 * Returns the error code.
49
-	 *
50
-	 * @return string
51
-	 */
52
-	public function getErrorCode() {
53
-		return $this->error_code;
54
-	}
47
+    /**
48
+     * Returns the error code.
49
+     *
50
+     * @return string
51
+     */
52
+    public function getErrorCode() {
53
+        return $this->error_code;
54
+    }
55 55
 
56
-	/**
57
-	 * Returns the list of messages.
58
-	 *
59
-	 * @return WP_Error
60
-	 */
61
-	public function getError() {
62
-		return $this->error;
63
-	}
56
+    /**
57
+     * Returns the list of messages.
58
+     *
59
+     * @return WP_Error
60
+     */
61
+    public function getError() {
62
+        return $this->error;
63
+    }
64 64
 
65
-	/**
66
-	 * Returns additional error data.
67
-	 *
68
-	 * @return array
69
-	 */
70
-	public function getAdditionalData() {
71
-		return $this->additional_data;
72
-	}
65
+    /**
66
+     * Returns additional error data.
67
+     *
68
+     * @return array
69
+     */
70
+    public function getAdditionalData() {
71
+        return $this->additional_data;
72
+    }
73 73
 
74 74
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -37,11 +37,11 @@
 block discarded – undo
37 37
 	 * @param WP_Error $error           The WP_Error object containing all errors relating to stock availability.
38 38
 	 * @param array    $additional_data Extra data (key value pairs) to expose in the error response.
39 39
 	 */
40
-	public function __construct( $error_code, WP_Error $error, $additional_data = [] ) {
40
+	public function __construct($error_code, WP_Error $error, $additional_data = []) {
41 41
 		$this->error_code      = $error_code;
42 42
 		$this->error           = $error;
43
-		$this->additional_data = array_filter( (array) $additional_data );
44
-		parent::__construct( '', 409 );
43
+		$this->additional_data = array_filter((array) $additional_data);
44
+		parent::__construct('', 409);
45 45
 	}
46 46
 
47 47
 	/**
Please login to merge, or discard this patch.
src/StoreApi/Exceptions/InvalidStockLevelsInCartException.php 2 patches
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -9,65 +9,65 @@
 block discarded – undo
9 9
  * This exception is thrown if any items are out of stock after each product on a draft order has been stock checked.
10 10
  */
11 11
 class InvalidStockLevelsInCartException extends \Exception {
12
-	/**
13
-	 * Sanitized error code.
14
-	 *
15
-	 * @var string
16
-	 */
17
-	public $error_code;
12
+    /**
13
+     * Sanitized error code.
14
+     *
15
+     * @var string
16
+     */
17
+    public $error_code;
18 18
 
19
-	/**
20
-	 * Additional error data.
21
-	 *
22
-	 * @var array
23
-	 */
24
-	public $additional_data = [];
19
+    /**
20
+     * Additional error data.
21
+     *
22
+     * @var array
23
+     */
24
+    public $additional_data = [];
25 25
 
26
-	/**
27
-	 * All errors to display to the user.
28
-	 *
29
-	 * @var WP_Error
30
-	 */
31
-	public $error;
26
+    /**
27
+     * All errors to display to the user.
28
+     *
29
+     * @var WP_Error
30
+     */
31
+    public $error;
32 32
 
33
-	/**
34
-	 * Setup exception.
35
-	 *
36
-	 * @param string   $error_code      Machine-readable error code, e.g `woocommerce_invalid_product_id`.
37
-	 * @param WP_Error $error           The WP_Error object containing all errors relating to stock availability.
38
-	 * @param array    $additional_data Extra data (key value pairs) to expose in the error response.
39
-	 */
40
-	public function __construct( $error_code, $error, $additional_data = [] ) {
41
-		$this->error_code      = $error_code;
42
-		$this->error           = $error;
43
-		$this->additional_data = array_filter( (array) $additional_data );
44
-		parent::__construct( '', 409 );
45
-	}
33
+    /**
34
+     * Setup exception.
35
+     *
36
+     * @param string   $error_code      Machine-readable error code, e.g `woocommerce_invalid_product_id`.
37
+     * @param WP_Error $error           The WP_Error object containing all errors relating to stock availability.
38
+     * @param array    $additional_data Extra data (key value pairs) to expose in the error response.
39
+     */
40
+    public function __construct( $error_code, $error, $additional_data = [] ) {
41
+        $this->error_code      = $error_code;
42
+        $this->error           = $error;
43
+        $this->additional_data = array_filter( (array) $additional_data );
44
+        parent::__construct( '', 409 );
45
+    }
46 46
 
47
-	/**
48
-	 * Returns the error code.
49
-	 *
50
-	 * @return string
51
-	 */
52
-	public function getErrorCode() {
53
-		return $this->error_code;
54
-	}
47
+    /**
48
+     * Returns the error code.
49
+     *
50
+     * @return string
51
+     */
52
+    public function getErrorCode() {
53
+        return $this->error_code;
54
+    }
55 55
 
56
-	/**
57
-	 * Returns the list of messages.
58
-	 *
59
-	 * @return WP_Error
60
-	 */
61
-	public function getError() {
62
-		return $this->error;
63
-	}
56
+    /**
57
+     * Returns the list of messages.
58
+     *
59
+     * @return WP_Error
60
+     */
61
+    public function getError() {
62
+        return $this->error;
63
+    }
64 64
 
65
-	/**
66
-	 * Returns additional error data.
67
-	 *
68
-	 * @return array
69
-	 */
70
-	public function getAdditionalData() {
71
-		return $this->additional_data;
72
-	}
65
+    /**
66
+     * Returns additional error data.
67
+     *
68
+     * @return array
69
+     */
70
+    public function getAdditionalData() {
71
+        return $this->additional_data;
72
+    }
73 73
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -37,11 +37,11 @@
 block discarded – undo
37 37
 	 * @param WP_Error $error           The WP_Error object containing all errors relating to stock availability.
38 38
 	 * @param array    $additional_data Extra data (key value pairs) to expose in the error response.
39 39
 	 */
40
-	public function __construct( $error_code, $error, $additional_data = [] ) {
40
+	public function __construct($error_code, $error, $additional_data = []) {
41 41
 		$this->error_code      = $error_code;
42 42
 		$this->error           = $error;
43
-		$this->additional_data = array_filter( (array) $additional_data );
44
-		parent::__construct( '', 409 );
43
+		$this->additional_data = array_filter((array) $additional_data);
44
+		parent::__construct('', 409);
45 45
 	}
46 46
 
47 47
 	/**
Please login to merge, or discard this patch.
packages/woocommerce-blocks/src/StoreApi/Exceptions/RouteException.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -5,49 +5,49 @@
 block discarded – undo
5 5
  * RouteException class.
6 6
  */
7 7
 class RouteException extends \Exception {
8
-	/**
9
-	 * Sanitized error code.
10
-	 *
11
-	 * @var string
12
-	 */
13
-	public $error_code;
8
+    /**
9
+     * Sanitized error code.
10
+     *
11
+     * @var string
12
+     */
13
+    public $error_code;
14 14
 
15
-	/**
16
-	 * Additional error data.
17
-	 *
18
-	 * @var array
19
-	 */
20
-	public $additional_data = [];
15
+    /**
16
+     * Additional error data.
17
+     *
18
+     * @var array
19
+     */
20
+    public $additional_data = [];
21 21
 
22
-	/**
23
-	 * Setup exception.
24
-	 *
25
-	 * @param string $error_code       Machine-readable error code, e.g `woocommerce_invalid_product_id`.
26
-	 * @param string $message          User-friendly translated error message, e.g. 'Product ID is invalid'.
27
-	 * @param int    $http_status_code Proper HTTP status code to respond with, e.g. 400.
28
-	 * @param array  $additional_data  Extra data (key value pairs) to expose in the error response.
29
-	 */
30
-	public function __construct( $error_code, $message, $http_status_code = 400, $additional_data = [] ) {
31
-		$this->error_code      = $error_code;
32
-		$this->additional_data = array_filter( (array) $additional_data );
33
-		parent::__construct( $message, $http_status_code );
34
-	}
22
+    /**
23
+     * Setup exception.
24
+     *
25
+     * @param string $error_code       Machine-readable error code, e.g `woocommerce_invalid_product_id`.
26
+     * @param string $message          User-friendly translated error message, e.g. 'Product ID is invalid'.
27
+     * @param int    $http_status_code Proper HTTP status code to respond with, e.g. 400.
28
+     * @param array  $additional_data  Extra data (key value pairs) to expose in the error response.
29
+     */
30
+    public function __construct( $error_code, $message, $http_status_code = 400, $additional_data = [] ) {
31
+        $this->error_code      = $error_code;
32
+        $this->additional_data = array_filter( (array) $additional_data );
33
+        parent::__construct( $message, $http_status_code );
34
+    }
35 35
 
36
-	/**
37
-	 * Returns the error code.
38
-	 *
39
-	 * @return string
40
-	 */
41
-	public function getErrorCode() {
42
-		return $this->error_code;
43
-	}
36
+    /**
37
+     * Returns the error code.
38
+     *
39
+     * @return string
40
+     */
41
+    public function getErrorCode() {
42
+        return $this->error_code;
43
+    }
44 44
 
45
-	/**
46
-	 * Returns additional error data.
47
-	 *
48
-	 * @return array
49
-	 */
50
-	public function getAdditionalData() {
51
-		return $this->additional_data;
52
-	}
45
+    /**
46
+     * Returns additional error data.
47
+     *
48
+     * @return array
49
+     */
50
+    public function getAdditionalData() {
51
+        return $this->additional_data;
52
+    }
53 53
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -27,10 +27,10 @@
 block discarded – undo
27 27
 	 * @param int    $http_status_code Proper HTTP status code to respond with, e.g. 400.
28 28
 	 * @param array  $additional_data  Extra data (key value pairs) to expose in the error response.
29 29
 	 */
30
-	public function __construct( $error_code, $message, $http_status_code = 400, $additional_data = [] ) {
30
+	public function __construct($error_code, $message, $http_status_code = 400, $additional_data = []) {
31 31
 		$this->error_code      = $error_code;
32
-		$this->additional_data = array_filter( (array) $additional_data );
33
-		parent::__construct( $message, $http_status_code );
32
+		$this->additional_data = array_filter((array) $additional_data);
33
+		parent::__construct($message, $http_status_code);
34 34
 	}
35 35
 
36 36
 	/**
Please login to merge, or discard this patch.
woocommerce-blocks/src/StoreApi/Exceptions/StockAvailabilityException.php 2 patches
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -7,66 +7,66 @@
 block discarded – undo
7 7
  * This exception is thrown when more than one of a product that can only be purchased individually is in a cart.
8 8
  */
9 9
 class StockAvailabilityException extends \Exception {
10
-	/**
11
-	 * Sanitized error code.
12
-	 *
13
-	 * @var string
14
-	 */
15
-	public $error_code;
10
+    /**
11
+     * Sanitized error code.
12
+     *
13
+     * @var string
14
+     */
15
+    public $error_code;
16 16
 
17
-	/**
18
-	 * The name of the product that can only be purchased individually.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	public $product_name;
17
+    /**
18
+     * The name of the product that can only be purchased individually.
19
+     *
20
+     * @var string
21
+     */
22
+    public $product_name;
23 23
 
24
-	/**
25
-	 * Additional error data.
26
-	 *
27
-	 * @var array
28
-	 */
29
-	public $additional_data = [];
24
+    /**
25
+     * Additional error data.
26
+     *
27
+     * @var array
28
+     */
29
+    public $additional_data = [];
30 30
 
31
-	/**
32
-	 * Setup exception.
33
-	 *
34
-	 * @param string $error_code       Machine-readable error code, e.g `woocommerce_invalid_product_id`.
35
-	 * @param string $product_name     The name of the product that can only be purchased individually.
36
-	 * @param array  $additional_data  Extra data (key value pairs) to expose in the error response.
37
-	 */
38
-	public function __construct( $error_code, $product_name, $additional_data = [] ) {
39
-		$this->error_code      = $error_code;
40
-		$this->product_name    = $product_name;
41
-		$this->additional_data = array_filter( (array) $additional_data );
42
-		parent::__construct();
43
-	}
31
+    /**
32
+     * Setup exception.
33
+     *
34
+     * @param string $error_code       Machine-readable error code, e.g `woocommerce_invalid_product_id`.
35
+     * @param string $product_name     The name of the product that can only be purchased individually.
36
+     * @param array  $additional_data  Extra data (key value pairs) to expose in the error response.
37
+     */
38
+    public function __construct( $error_code, $product_name, $additional_data = [] ) {
39
+        $this->error_code      = $error_code;
40
+        $this->product_name    = $product_name;
41
+        $this->additional_data = array_filter( (array) $additional_data );
42
+        parent::__construct();
43
+    }
44 44
 
45
-	/**
46
-	 * Returns the error code.
47
-	 *
48
-	 * @return string
49
-	 */
50
-	public function getErrorCode() {
51
-		return $this->error_code;
52
-	}
45
+    /**
46
+     * Returns the error code.
47
+     *
48
+     * @return string
49
+     */
50
+    public function getErrorCode() {
51
+        return $this->error_code;
52
+    }
53 53
 
54
-	/**
55
-	 * Returns additional error data.
56
-	 *
57
-	 * @return array
58
-	 */
59
-	public function getAdditionalData() {
60
-		return $this->additional_data;
61
-	}
54
+    /**
55
+     * Returns additional error data.
56
+     *
57
+     * @return array
58
+     */
59
+    public function getAdditionalData() {
60
+        return $this->additional_data;
61
+    }
62 62
 
63
-	/**
64
-	 * Returns the product name.
65
-	 *
66
-	 * @return string
67
-	 */
68
-	public function getProductName() {
69
-		return $this->product_name;
70
-	}
63
+    /**
64
+     * Returns the product name.
65
+     *
66
+     * @return string
67
+     */
68
+    public function getProductName() {
69
+        return $this->product_name;
70
+    }
71 71
 
72 72
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -35,10 +35,10 @@
 block discarded – undo
35 35
 	 * @param string $product_name     The name of the product that can only be purchased individually.
36 36
 	 * @param array  $additional_data  Extra data (key value pairs) to expose in the error response.
37 37
 	 */
38
-	public function __construct( $error_code, $product_name, $additional_data = [] ) {
38
+	public function __construct($error_code, $product_name, $additional_data = []) {
39 39
 		$this->error_code      = $error_code;
40 40
 		$this->product_name    = $product_name;
41
-		$this->additional_data = array_filter( (array) $additional_data );
41
+		$this->additional_data = array_filter((array) $additional_data);
42 42
 		parent::__construct();
43 43
 	}
44 44
 
Please login to merge, or discard this patch.
packages/woocommerce-blocks/src/StoreApi/Schemas/ExtendSchema.php 2 patches
Indentation   +328 added lines, -328 removed lines patch added patch discarded remove patch
@@ -18,332 +18,332 @@
 block discarded – undo
18 18
  * @see woocommerce_store_api_get_formatter()
19 19
  */
20 20
 final class ExtendSchema {
21
-	/**
22
-	 * List of Store API schema that is allowed to be extended by extensions.
23
-	 *
24
-	 * @var string[]
25
-	 */
26
-	private $endpoints = [
27
-		CartItemSchema::IDENTIFIER,
28
-		CartSchema::IDENTIFIER,
29
-		CheckoutSchema::IDENTIFIER,
30
-		ProductSchema::IDENTIFIER,
31
-	];
32
-
33
-	/**
34
-	 * Holds the formatters class instance.
35
-	 *
36
-	 * @var Formatters
37
-	 */
38
-	private $formatters;
39
-
40
-	/**
41
-	 * Data to be extended
42
-	 *
43
-	 * @var array
44
-	 */
45
-	private $extend_data = [];
46
-
47
-	/**
48
-	 * Data to be extended
49
-	 *
50
-	 * @var array
51
-	 */
52
-	private $callback_methods = [];
53
-
54
-	/**
55
-	 * Array of payment requirements
56
-	 *
57
-	 * @var array
58
-	 */
59
-	private $payment_requirements = [];
60
-
61
-	/**
62
-	 * Constructor
63
-	 *
64
-	 * @param Formatters $formatters An instance of the formatters class.
65
-	 */
66
-	public function __construct( Formatters $formatters ) {
67
-		$this->formatters = $formatters;
68
-	}
69
-
70
-	/**
71
-	 * Register endpoint data under a specified namespace
72
-	 *
73
-	 * @param array $args {
74
-	 *     An array of elements that make up a post to update or insert.
75
-	 *
76
-	 *     @type string   $endpoint Required. The endpoint to extend.
77
-	 *     @type string   $namespace Required. Plugin namespace.
78
-	 *     @type callable $schema_callback Callback executed to add schema data.
79
-	 *     @type callable $data_callback Callback executed to add endpoint data.
80
-	 *     @type string   $schema_type The type of data, object or array.
81
-	 * }
82
-	 *
83
-	 * @throws \Exception On failure to register.
84
-	 */
85
-	public function register_endpoint_data( $args ) {
86
-		$args = wp_parse_args(
87
-			$args,
88
-			[
89
-				'endpoint'        => '',
90
-				'namespace'       => '',
91
-				'schema_callback' => null,
92
-				'data_callback'   => null,
93
-				'schema_type'     => ARRAY_A,
94
-			]
95
-		);
96
-
97
-		if ( ! is_string( $args['namespace'] ) || empty( $args['namespace'] ) ) {
98
-			$this->throw_exception( 'You must provide a plugin namespace when extending a Store REST endpoint.' );
99
-		}
100
-
101
-		if ( ! in_array( $args['endpoint'], $this->endpoints, true ) ) {
102
-			$this->throw_exception(
103
-				sprintf( 'You must provide a valid Store REST endpoint to extend, valid endpoints are: %1$s. You provided %2$s.', implode( ', ', $this->endpoints ), $args['endpoint'] )
104
-			);
105
-		}
106
-
107
-		if ( ! is_null( $args['schema_callback'] ) && ! is_callable( $args['schema_callback'] ) ) {
108
-			$this->throw_exception( '$schema_callback must be a callable function.' );
109
-		}
110
-
111
-		if ( ! is_null( $args['data_callback'] ) && ! is_callable( $args['data_callback'] ) ) {
112
-			$this->throw_exception( '$data_callback must be a callable function.' );
113
-		}
114
-
115
-		if ( ! in_array( $args['schema_type'], [ ARRAY_N, ARRAY_A ], true ) ) {
116
-			$this->throw_exception(
117
-				sprintf( 'Data type must be either ARRAY_N for a numeric array or ARRAY_A for an object like array. You provided %1$s.', $args['schema_type'] )
118
-			);
119
-		}
120
-
121
-		$this->extend_data[ $args['endpoint'] ][ $args['namespace'] ] = [
122
-			'schema_callback' => $args['schema_callback'],
123
-			'data_callback'   => $args['data_callback'],
124
-			'schema_type'     => $args['schema_type'],
125
-		];
126
-	}
127
-
128
-	/**
129
-	 * Add callback functions that can be executed by the cart/extensions endpoint.
130
-	 *
131
-	 * @param array $args {
132
-	 *     An array of elements that make up the callback configuration.
133
-	 *
134
-	 *     @type string   $namespace Required. Plugin namespace.
135
-	 *     @type callable $callback Required. The function/callable to execute.
136
-	 * }
137
-	 *
138
-	 * @throws \Exception On failure to register.
139
-	 */
140
-	public function register_update_callback( $args ) {
141
-		$args = wp_parse_args(
142
-			$args,
143
-			[
144
-				'namespace' => '',
145
-				'callback'  => null,
146
-			]
147
-		);
148
-
149
-		if ( ! is_string( $args['namespace'] ) || empty( $args['namespace'] ) ) {
150
-			throw new \Exception( 'You must provide a plugin namespace when extending a Store REST endpoint.' );
151
-		}
152
-
153
-		if ( ! is_callable( $args['callback'] ) ) {
154
-			throw new \Exception( 'There is no valid callback supplied to register_update_callback.' );
155
-		}
156
-
157
-		$this->callback_methods[ $args['namespace'] ] = $args;
158
-	}
159
-
160
-	/**
161
-	 * Registers and validates payment requirements callbacks.
162
-	 *
163
-	 * @param array $args {
164
-	 *     Array of registration data.
165
-	 *
166
-	 *     @type callable $data_callback Required. Callback executed to add payment requirements data.
167
-	 * }
168
-	 *
169
-	 * @throws \Exception On failure to register.
170
-	 */
171
-	public function register_payment_requirements( $args ) {
172
-		if ( empty( $args['data_callback'] ) || ! is_callable( $args['data_callback'] ) ) {
173
-			$this->throw_exception( '$data_callback must be a callable function.' );
174
-		}
175
-		$this->payment_requirements[] = $args['data_callback'];
176
-	}
177
-
178
-	/**
179
-	 * Returns a formatter instance.
180
-	 *
181
-	 * @param string $name Formatter name.
182
-	 * @return FormatterInterface
183
-	 */
184
-	public function get_formatter( $name ) {
185
-		return $this->formatters->$name;
186
-	}
187
-
188
-	/**
189
-	 * Get callback for a specific endpoint and namespace.
190
-	 *
191
-	 * @param string $namespace The namespace to get callbacks for.
192
-	 *
193
-	 * @return callable The callback registered by the extension.
194
-	 * @throws \Exception When callback is not callable or parameters are incorrect.
195
-	 */
196
-	public function get_update_callback( $namespace ) {
197
-		if ( ! is_string( $namespace ) ) {
198
-			throw new \Exception( 'You must provide a plugin namespace when extending a Store REST endpoint.' );
199
-		}
200
-
201
-		if ( ! array_key_exists( $namespace, $this->callback_methods ) ) {
202
-			throw new \Exception( sprintf( 'There is no such namespace registered: %1$s.', $namespace ) );
203
-		}
204
-
205
-		if ( ! array_key_exists( 'callback', $this->callback_methods[ $namespace ] ) || ! is_callable( $this->callback_methods[ $namespace ]['callback'] ) ) {
206
-			throw new \Exception( sprintf( 'There is no valid callback registered for: %1$s.', $namespace ) );
207
-		}
208
-
209
-		return $this->callback_methods[ $namespace ]['callback'];
210
-	}
211
-
212
-	/**
213
-	 * Returns the registered endpoint data
214
-	 *
215
-	 * @param string $endpoint    A valid identifier.
216
-	 * @param array  $passed_args Passed arguments from the Schema class.
217
-	 * @return object Returns an casted object with registered endpoint data.
218
-	 * @throws \Exception If a registered callback throws an error, or silently logs it.
219
-	 */
220
-	public function get_endpoint_data( $endpoint, array $passed_args = [] ) {
221
-		$registered_data = [];
222
-
223
-		if ( isset( $this->extend_data[ $endpoint ] ) ) {
224
-			foreach ( $this->extend_data[ $endpoint ] as $namespace => $callbacks ) {
225
-				if ( is_null( $callbacks['data_callback'] ) ) {
226
-					continue;
227
-				}
228
-				try {
229
-					$data = $callbacks['data_callback']( ...$passed_args );
230
-
231
-					if ( ! is_array( $data ) ) {
232
-						$data = [];
233
-						throw new \Exception( '$data_callback must return an array.' );
234
-					}
235
-				} catch ( \Throwable $e ) {
236
-					$this->throw_exception( $e );
237
-				}
238
-
239
-				$registered_data[ $namespace ] = $data;
240
-			}
241
-		}
242
-
243
-		return (object) $registered_data;
244
-	}
245
-
246
-	/**
247
-	 * Returns the registered endpoint schema
248
-	 *
249
-	 * @param string $endpoint    A valid identifier.
250
-	 * @param array  $passed_args Passed arguments from the Schema class.
251
-	 * @return object Returns an array with registered schema data.
252
-	 * @throws \Exception If a registered callback throws an error, or silently logs it.
253
-	 */
254
-	public function get_endpoint_schema( $endpoint, array $passed_args = [] ) {
255
-		$registered_schema = [];
256
-
257
-		if ( isset( $this->extend_data[ $endpoint ] ) ) {
258
-			foreach ( $this->extend_data[ $endpoint ] as $namespace => $callbacks ) {
259
-				if ( is_null( $callbacks['schema_callback'] ) ) {
260
-					continue;
261
-				}
262
-				try {
263
-					$schema = $callbacks['schema_callback']( ...$passed_args );
264
-
265
-					if ( ! is_array( $schema ) ) {
266
-						$schema = [];
267
-						throw new \Exception( '$schema_callback must return an array.' );
268
-					}
269
-				} catch ( \Throwable $e ) {
270
-					$this->throw_exception( $e );
271
-				}
272
-
273
-				$registered_schema[ $namespace ] = $this->format_extensions_properties( $namespace, $schema, $callbacks['schema_type'] );
274
-			}
275
-		}
276
-
277
-		return (object) $registered_schema;
278
-	}
279
-
280
-	/**
281
-	 * Returns the additional payment requirements for the cart which are required to make payments. Values listed here
282
-	 * are compared against each Payment Gateways "supports" flag.
283
-	 *
284
-	 * @param array $requirements list of requirements that should be added to the collected requirements.
285
-	 * @return array Returns a list of payment requirements.
286
-	 * @throws \Exception If a registered callback throws an error, or silently logs it.
287
-	 */
288
-	public function get_payment_requirements( array $requirements = [ 'products' ] ) {
289
-		if ( ! empty( $this->payment_requirements ) ) {
290
-			foreach ( $this->payment_requirements as $callback ) {
291
-				try {
292
-					$data = $callback();
293
-
294
-					if ( ! is_array( $data ) ) {
295
-						throw new \Exception( '$data_callback must return an array.' );
296
-					}
297
-
298
-					$requirements = array_unique( array_merge( $requirements, $data ) );
299
-				} catch ( \Throwable $e ) {
300
-					$this->throw_exception( $e );
301
-				}
302
-			}
303
-		}
304
-		return $requirements;
305
-	}
306
-
307
-	/**
308
-	 * Throws error and/or silently logs it.
309
-	 *
310
-	 * @param string|\Throwable $exception_or_error Error message or \Exception.
311
-	 * @throws \Exception An error to throw if we have debug enabled and user is admin.
312
-	 */
313
-	private function throw_exception( $exception_or_error ) {
314
-		$exception = is_string( $exception_or_error ) ? new \Exception( $exception_or_error ) : $exception_or_error;
315
-
316
-		wc_caught_exception( $exception );
317
-
318
-		if ( defined( 'WP_DEBUG' ) && WP_DEBUG && current_user_can( 'manage_woocommerce' ) ) {
319
-			throw $exception;
320
-		}
321
-	}
322
-
323
-	/**
324
-	 * Format schema for an extension.
325
-	 *
326
-	 * @param string $namespace Error message or \Exception.
327
-	 * @param array  $schema An error to throw if we have debug enabled and user is admin.
328
-	 * @param string $schema_type How should data be shaped.
329
-	 * @return array Formatted schema.
330
-	 */
331
-	private function format_extensions_properties( $namespace, $schema, $schema_type ) {
332
-		if ( ARRAY_N === $schema_type ) {
333
-			return [
334
-				/* translators: %s: extension namespace */
335
-				'description' => sprintf( __( 'Extension data registered by %s', 'woocommerce' ), $namespace ),
336
-				'type'        => 'array',
337
-				'context'     => [ 'view', 'edit' ],
338
-				'items'       => $schema,
339
-			];
340
-		}
341
-		return [
342
-			/* translators: %s: extension namespace */
343
-			'description' => sprintf( __( 'Extension data registered by %s', 'woocommerce' ), $namespace ),
344
-			'type'        => 'object',
345
-			'context'     => [ 'view', 'edit' ],
346
-			'properties'  => $schema,
347
-		];
348
-	}
21
+    /**
22
+     * List of Store API schema that is allowed to be extended by extensions.
23
+     *
24
+     * @var string[]
25
+     */
26
+    private $endpoints = [
27
+        CartItemSchema::IDENTIFIER,
28
+        CartSchema::IDENTIFIER,
29
+        CheckoutSchema::IDENTIFIER,
30
+        ProductSchema::IDENTIFIER,
31
+    ];
32
+
33
+    /**
34
+     * Holds the formatters class instance.
35
+     *
36
+     * @var Formatters
37
+     */
38
+    private $formatters;
39
+
40
+    /**
41
+     * Data to be extended
42
+     *
43
+     * @var array
44
+     */
45
+    private $extend_data = [];
46
+
47
+    /**
48
+     * Data to be extended
49
+     *
50
+     * @var array
51
+     */
52
+    private $callback_methods = [];
53
+
54
+    /**
55
+     * Array of payment requirements
56
+     *
57
+     * @var array
58
+     */
59
+    private $payment_requirements = [];
60
+
61
+    /**
62
+     * Constructor
63
+     *
64
+     * @param Formatters $formatters An instance of the formatters class.
65
+     */
66
+    public function __construct( Formatters $formatters ) {
67
+        $this->formatters = $formatters;
68
+    }
69
+
70
+    /**
71
+     * Register endpoint data under a specified namespace
72
+     *
73
+     * @param array $args {
74
+     *     An array of elements that make up a post to update or insert.
75
+     *
76
+     *     @type string   $endpoint Required. The endpoint to extend.
77
+     *     @type string   $namespace Required. Plugin namespace.
78
+     *     @type callable $schema_callback Callback executed to add schema data.
79
+     *     @type callable $data_callback Callback executed to add endpoint data.
80
+     *     @type string   $schema_type The type of data, object or array.
81
+     * }
82
+     *
83
+     * @throws \Exception On failure to register.
84
+     */
85
+    public function register_endpoint_data( $args ) {
86
+        $args = wp_parse_args(
87
+            $args,
88
+            [
89
+                'endpoint'        => '',
90
+                'namespace'       => '',
91
+                'schema_callback' => null,
92
+                'data_callback'   => null,
93
+                'schema_type'     => ARRAY_A,
94
+            ]
95
+        );
96
+
97
+        if ( ! is_string( $args['namespace'] ) || empty( $args['namespace'] ) ) {
98
+            $this->throw_exception( 'You must provide a plugin namespace when extending a Store REST endpoint.' );
99
+        }
100
+
101
+        if ( ! in_array( $args['endpoint'], $this->endpoints, true ) ) {
102
+            $this->throw_exception(
103
+                sprintf( 'You must provide a valid Store REST endpoint to extend, valid endpoints are: %1$s. You provided %2$s.', implode( ', ', $this->endpoints ), $args['endpoint'] )
104
+            );
105
+        }
106
+
107
+        if ( ! is_null( $args['schema_callback'] ) && ! is_callable( $args['schema_callback'] ) ) {
108
+            $this->throw_exception( '$schema_callback must be a callable function.' );
109
+        }
110
+
111
+        if ( ! is_null( $args['data_callback'] ) && ! is_callable( $args['data_callback'] ) ) {
112
+            $this->throw_exception( '$data_callback must be a callable function.' );
113
+        }
114
+
115
+        if ( ! in_array( $args['schema_type'], [ ARRAY_N, ARRAY_A ], true ) ) {
116
+            $this->throw_exception(
117
+                sprintf( 'Data type must be either ARRAY_N for a numeric array or ARRAY_A for an object like array. You provided %1$s.', $args['schema_type'] )
118
+            );
119
+        }
120
+
121
+        $this->extend_data[ $args['endpoint'] ][ $args['namespace'] ] = [
122
+            'schema_callback' => $args['schema_callback'],
123
+            'data_callback'   => $args['data_callback'],
124
+            'schema_type'     => $args['schema_type'],
125
+        ];
126
+    }
127
+
128
+    /**
129
+     * Add callback functions that can be executed by the cart/extensions endpoint.
130
+     *
131
+     * @param array $args {
132
+     *     An array of elements that make up the callback configuration.
133
+     *
134
+     *     @type string   $namespace Required. Plugin namespace.
135
+     *     @type callable $callback Required. The function/callable to execute.
136
+     * }
137
+     *
138
+     * @throws \Exception On failure to register.
139
+     */
140
+    public function register_update_callback( $args ) {
141
+        $args = wp_parse_args(
142
+            $args,
143
+            [
144
+                'namespace' => '',
145
+                'callback'  => null,
146
+            ]
147
+        );
148
+
149
+        if ( ! is_string( $args['namespace'] ) || empty( $args['namespace'] ) ) {
150
+            throw new \Exception( 'You must provide a plugin namespace when extending a Store REST endpoint.' );
151
+        }
152
+
153
+        if ( ! is_callable( $args['callback'] ) ) {
154
+            throw new \Exception( 'There is no valid callback supplied to register_update_callback.' );
155
+        }
156
+
157
+        $this->callback_methods[ $args['namespace'] ] = $args;
158
+    }
159
+
160
+    /**
161
+     * Registers and validates payment requirements callbacks.
162
+     *
163
+     * @param array $args {
164
+     *     Array of registration data.
165
+     *
166
+     *     @type callable $data_callback Required. Callback executed to add payment requirements data.
167
+     * }
168
+     *
169
+     * @throws \Exception On failure to register.
170
+     */
171
+    public function register_payment_requirements( $args ) {
172
+        if ( empty( $args['data_callback'] ) || ! is_callable( $args['data_callback'] ) ) {
173
+            $this->throw_exception( '$data_callback must be a callable function.' );
174
+        }
175
+        $this->payment_requirements[] = $args['data_callback'];
176
+    }
177
+
178
+    /**
179
+     * Returns a formatter instance.
180
+     *
181
+     * @param string $name Formatter name.
182
+     * @return FormatterInterface
183
+     */
184
+    public function get_formatter( $name ) {
185
+        return $this->formatters->$name;
186
+    }
187
+
188
+    /**
189
+     * Get callback for a specific endpoint and namespace.
190
+     *
191
+     * @param string $namespace The namespace to get callbacks for.
192
+     *
193
+     * @return callable The callback registered by the extension.
194
+     * @throws \Exception When callback is not callable or parameters are incorrect.
195
+     */
196
+    public function get_update_callback( $namespace ) {
197
+        if ( ! is_string( $namespace ) ) {
198
+            throw new \Exception( 'You must provide a plugin namespace when extending a Store REST endpoint.' );
199
+        }
200
+
201
+        if ( ! array_key_exists( $namespace, $this->callback_methods ) ) {
202
+            throw new \Exception( sprintf( 'There is no such namespace registered: %1$s.', $namespace ) );
203
+        }
204
+
205
+        if ( ! array_key_exists( 'callback', $this->callback_methods[ $namespace ] ) || ! is_callable( $this->callback_methods[ $namespace ]['callback'] ) ) {
206
+            throw new \Exception( sprintf( 'There is no valid callback registered for: %1$s.', $namespace ) );
207
+        }
208
+
209
+        return $this->callback_methods[ $namespace ]['callback'];
210
+    }
211
+
212
+    /**
213
+     * Returns the registered endpoint data
214
+     *
215
+     * @param string $endpoint    A valid identifier.
216
+     * @param array  $passed_args Passed arguments from the Schema class.
217
+     * @return object Returns an casted object with registered endpoint data.
218
+     * @throws \Exception If a registered callback throws an error, or silently logs it.
219
+     */
220
+    public function get_endpoint_data( $endpoint, array $passed_args = [] ) {
221
+        $registered_data = [];
222
+
223
+        if ( isset( $this->extend_data[ $endpoint ] ) ) {
224
+            foreach ( $this->extend_data[ $endpoint ] as $namespace => $callbacks ) {
225
+                if ( is_null( $callbacks['data_callback'] ) ) {
226
+                    continue;
227
+                }
228
+                try {
229
+                    $data = $callbacks['data_callback']( ...$passed_args );
230
+
231
+                    if ( ! is_array( $data ) ) {
232
+                        $data = [];
233
+                        throw new \Exception( '$data_callback must return an array.' );
234
+                    }
235
+                } catch ( \Throwable $e ) {
236
+                    $this->throw_exception( $e );
237
+                }
238
+
239
+                $registered_data[ $namespace ] = $data;
240
+            }
241
+        }
242
+
243
+        return (object) $registered_data;
244
+    }
245
+
246
+    /**
247
+     * Returns the registered endpoint schema
248
+     *
249
+     * @param string $endpoint    A valid identifier.
250
+     * @param array  $passed_args Passed arguments from the Schema class.
251
+     * @return object Returns an array with registered schema data.
252
+     * @throws \Exception If a registered callback throws an error, or silently logs it.
253
+     */
254
+    public function get_endpoint_schema( $endpoint, array $passed_args = [] ) {
255
+        $registered_schema = [];
256
+
257
+        if ( isset( $this->extend_data[ $endpoint ] ) ) {
258
+            foreach ( $this->extend_data[ $endpoint ] as $namespace => $callbacks ) {
259
+                if ( is_null( $callbacks['schema_callback'] ) ) {
260
+                    continue;
261
+                }
262
+                try {
263
+                    $schema = $callbacks['schema_callback']( ...$passed_args );
264
+
265
+                    if ( ! is_array( $schema ) ) {
266
+                        $schema = [];
267
+                        throw new \Exception( '$schema_callback must return an array.' );
268
+                    }
269
+                } catch ( \Throwable $e ) {
270
+                    $this->throw_exception( $e );
271
+                }
272
+
273
+                $registered_schema[ $namespace ] = $this->format_extensions_properties( $namespace, $schema, $callbacks['schema_type'] );
274
+            }
275
+        }
276
+
277
+        return (object) $registered_schema;
278
+    }
279
+
280
+    /**
281
+     * Returns the additional payment requirements for the cart which are required to make payments. Values listed here
282
+     * are compared against each Payment Gateways "supports" flag.
283
+     *
284
+     * @param array $requirements list of requirements that should be added to the collected requirements.
285
+     * @return array Returns a list of payment requirements.
286
+     * @throws \Exception If a registered callback throws an error, or silently logs it.
287
+     */
288
+    public function get_payment_requirements( array $requirements = [ 'products' ] ) {
289
+        if ( ! empty( $this->payment_requirements ) ) {
290
+            foreach ( $this->payment_requirements as $callback ) {
291
+                try {
292
+                    $data = $callback();
293
+
294
+                    if ( ! is_array( $data ) ) {
295
+                        throw new \Exception( '$data_callback must return an array.' );
296
+                    }
297
+
298
+                    $requirements = array_unique( array_merge( $requirements, $data ) );
299
+                } catch ( \Throwable $e ) {
300
+                    $this->throw_exception( $e );
301
+                }
302
+            }
303
+        }
304
+        return $requirements;
305
+    }
306
+
307
+    /**
308
+     * Throws error and/or silently logs it.
309
+     *
310
+     * @param string|\Throwable $exception_or_error Error message or \Exception.
311
+     * @throws \Exception An error to throw if we have debug enabled and user is admin.
312
+     */
313
+    private function throw_exception( $exception_or_error ) {
314
+        $exception = is_string( $exception_or_error ) ? new \Exception( $exception_or_error ) : $exception_or_error;
315
+
316
+        wc_caught_exception( $exception );
317
+
318
+        if ( defined( 'WP_DEBUG' ) && WP_DEBUG && current_user_can( 'manage_woocommerce' ) ) {
319
+            throw $exception;
320
+        }
321
+    }
322
+
323
+    /**
324
+     * Format schema for an extension.
325
+     *
326
+     * @param string $namespace Error message or \Exception.
327
+     * @param array  $schema An error to throw if we have debug enabled and user is admin.
328
+     * @param string $schema_type How should data be shaped.
329
+     * @return array Formatted schema.
330
+     */
331
+    private function format_extensions_properties( $namespace, $schema, $schema_type ) {
332
+        if ( ARRAY_N === $schema_type ) {
333
+            return [
334
+                /* translators: %s: extension namespace */
335
+                'description' => sprintf( __( 'Extension data registered by %s', 'woocommerce' ), $namespace ),
336
+                'type'        => 'array',
337
+                'context'     => [ 'view', 'edit' ],
338
+                'items'       => $schema,
339
+            ];
340
+        }
341
+        return [
342
+            /* translators: %s: extension namespace */
343
+            'description' => sprintf( __( 'Extension data registered by %s', 'woocommerce' ), $namespace ),
344
+            'type'        => 'object',
345
+            'context'     => [ 'view', 'edit' ],
346
+            'properties'  => $schema,
347
+        ];
348
+    }
349 349
 }
Please login to merge, or discard this patch.
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 *
64 64
 	 * @param Formatters $formatters An instance of the formatters class.
65 65
 	 */
66
-	public function __construct( Formatters $formatters ) {
66
+	public function __construct(Formatters $formatters) {
67 67
 		$this->formatters = $formatters;
68 68
 	}
69 69
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 	 *
83 83
 	 * @throws \Exception On failure to register.
84 84
 	 */
85
-	public function register_endpoint_data( $args ) {
85
+	public function register_endpoint_data($args) {
86 86
 		$args = wp_parse_args(
87 87
 			$args,
88 88
 			[
@@ -94,31 +94,31 @@  discard block
 block discarded – undo
94 94
 			]
95 95
 		);
96 96
 
97
-		if ( ! is_string( $args['namespace'] ) || empty( $args['namespace'] ) ) {
98
-			$this->throw_exception( 'You must provide a plugin namespace when extending a Store REST endpoint.' );
97
+		if (!is_string($args['namespace']) || empty($args['namespace'])) {
98
+			$this->throw_exception('You must provide a plugin namespace when extending a Store REST endpoint.');
99 99
 		}
100 100
 
101
-		if ( ! in_array( $args['endpoint'], $this->endpoints, true ) ) {
101
+		if (!in_array($args['endpoint'], $this->endpoints, true)) {
102 102
 			$this->throw_exception(
103
-				sprintf( 'You must provide a valid Store REST endpoint to extend, valid endpoints are: %1$s. You provided %2$s.', implode( ', ', $this->endpoints ), $args['endpoint'] )
103
+				sprintf('You must provide a valid Store REST endpoint to extend, valid endpoints are: %1$s. You provided %2$s.', implode(', ', $this->endpoints), $args['endpoint'])
104 104
 			);
105 105
 		}
106 106
 
107
-		if ( ! is_null( $args['schema_callback'] ) && ! is_callable( $args['schema_callback'] ) ) {
108
-			$this->throw_exception( '$schema_callback must be a callable function.' );
107
+		if (!is_null($args['schema_callback']) && !is_callable($args['schema_callback'])) {
108
+			$this->throw_exception('$schema_callback must be a callable function.');
109 109
 		}
110 110
 
111
-		if ( ! is_null( $args['data_callback'] ) && ! is_callable( $args['data_callback'] ) ) {
112
-			$this->throw_exception( '$data_callback must be a callable function.' );
111
+		if (!is_null($args['data_callback']) && !is_callable($args['data_callback'])) {
112
+			$this->throw_exception('$data_callback must be a callable function.');
113 113
 		}
114 114
 
115
-		if ( ! in_array( $args['schema_type'], [ ARRAY_N, ARRAY_A ], true ) ) {
115
+		if (!in_array($args['schema_type'], [ARRAY_N, ARRAY_A], true)) {
116 116
 			$this->throw_exception(
117
-				sprintf( 'Data type must be either ARRAY_N for a numeric array or ARRAY_A for an object like array. You provided %1$s.', $args['schema_type'] )
117
+				sprintf('Data type must be either ARRAY_N for a numeric array or ARRAY_A for an object like array. You provided %1$s.', $args['schema_type'])
118 118
 			);
119 119
 		}
120 120
 
121
-		$this->extend_data[ $args['endpoint'] ][ $args['namespace'] ] = [
121
+		$this->extend_data[$args['endpoint']][$args['namespace']] = [
122 122
 			'schema_callback' => $args['schema_callback'],
123 123
 			'data_callback'   => $args['data_callback'],
124 124
 			'schema_type'     => $args['schema_type'],
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	 *
138 138
 	 * @throws \Exception On failure to register.
139 139
 	 */
140
-	public function register_update_callback( $args ) {
140
+	public function register_update_callback($args) {
141 141
 		$args = wp_parse_args(
142 142
 			$args,
143 143
 			[
@@ -146,15 +146,15 @@  discard block
 block discarded – undo
146 146
 			]
147 147
 		);
148 148
 
149
-		if ( ! is_string( $args['namespace'] ) || empty( $args['namespace'] ) ) {
150
-			throw new \Exception( 'You must provide a plugin namespace when extending a Store REST endpoint.' );
149
+		if (!is_string($args['namespace']) || empty($args['namespace'])) {
150
+			throw new \Exception('You must provide a plugin namespace when extending a Store REST endpoint.');
151 151
 		}
152 152
 
153
-		if ( ! is_callable( $args['callback'] ) ) {
154
-			throw new \Exception( 'There is no valid callback supplied to register_update_callback.' );
153
+		if (!is_callable($args['callback'])) {
154
+			throw new \Exception('There is no valid callback supplied to register_update_callback.');
155 155
 		}
156 156
 
157
-		$this->callback_methods[ $args['namespace'] ] = $args;
157
+		$this->callback_methods[$args['namespace']] = $args;
158 158
 	}
159 159
 
160 160
 	/**
@@ -168,9 +168,9 @@  discard block
 block discarded – undo
168 168
 	 *
169 169
 	 * @throws \Exception On failure to register.
170 170
 	 */
171
-	public function register_payment_requirements( $args ) {
172
-		if ( empty( $args['data_callback'] ) || ! is_callable( $args['data_callback'] ) ) {
173
-			$this->throw_exception( '$data_callback must be a callable function.' );
171
+	public function register_payment_requirements($args) {
172
+		if (empty($args['data_callback']) || !is_callable($args['data_callback'])) {
173
+			$this->throw_exception('$data_callback must be a callable function.');
174 174
 		}
175 175
 		$this->payment_requirements[] = $args['data_callback'];
176 176
 	}
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	 * @param string $name Formatter name.
182 182
 	 * @return FormatterInterface
183 183
 	 */
184
-	public function get_formatter( $name ) {
184
+	public function get_formatter($name) {
185 185
 		return $this->formatters->$name;
186 186
 	}
187 187
 
@@ -193,20 +193,20 @@  discard block
 block discarded – undo
193 193
 	 * @return callable The callback registered by the extension.
194 194
 	 * @throws \Exception When callback is not callable or parameters are incorrect.
195 195
 	 */
196
-	public function get_update_callback( $namespace ) {
197
-		if ( ! is_string( $namespace ) ) {
198
-			throw new \Exception( 'You must provide a plugin namespace when extending a Store REST endpoint.' );
196
+	public function get_update_callback($namespace) {
197
+		if (!is_string($namespace)) {
198
+			throw new \Exception('You must provide a plugin namespace when extending a Store REST endpoint.');
199 199
 		}
200 200
 
201
-		if ( ! array_key_exists( $namespace, $this->callback_methods ) ) {
202
-			throw new \Exception( sprintf( 'There is no such namespace registered: %1$s.', $namespace ) );
201
+		if (!array_key_exists($namespace, $this->callback_methods)) {
202
+			throw new \Exception(sprintf('There is no such namespace registered: %1$s.', $namespace));
203 203
 		}
204 204
 
205
-		if ( ! array_key_exists( 'callback', $this->callback_methods[ $namespace ] ) || ! is_callable( $this->callback_methods[ $namespace ]['callback'] ) ) {
206
-			throw new \Exception( sprintf( 'There is no valid callback registered for: %1$s.', $namespace ) );
205
+		if (!array_key_exists('callback', $this->callback_methods[$namespace]) || !is_callable($this->callback_methods[$namespace]['callback'])) {
206
+			throw new \Exception(sprintf('There is no valid callback registered for: %1$s.', $namespace));
207 207
 		}
208 208
 
209
-		return $this->callback_methods[ $namespace ]['callback'];
209
+		return $this->callback_methods[$namespace]['callback'];
210 210
 	}
211 211
 
212 212
 	/**
@@ -217,26 +217,26 @@  discard block
 block discarded – undo
217 217
 	 * @return object Returns an casted object with registered endpoint data.
218 218
 	 * @throws \Exception If a registered callback throws an error, or silently logs it.
219 219
 	 */
220
-	public function get_endpoint_data( $endpoint, array $passed_args = [] ) {
220
+	public function get_endpoint_data($endpoint, array $passed_args = []) {
221 221
 		$registered_data = [];
222 222
 
223
-		if ( isset( $this->extend_data[ $endpoint ] ) ) {
224
-			foreach ( $this->extend_data[ $endpoint ] as $namespace => $callbacks ) {
225
-				if ( is_null( $callbacks['data_callback'] ) ) {
223
+		if (isset($this->extend_data[$endpoint])) {
224
+			foreach ($this->extend_data[$endpoint] as $namespace => $callbacks) {
225
+				if (is_null($callbacks['data_callback'])) {
226 226
 					continue;
227 227
 				}
228 228
 				try {
229
-					$data = $callbacks['data_callback']( ...$passed_args );
229
+					$data = $callbacks['data_callback'](...$passed_args);
230 230
 
231
-					if ( ! is_array( $data ) ) {
231
+					if (!is_array($data)) {
232 232
 						$data = [];
233
-						throw new \Exception( '$data_callback must return an array.' );
233
+						throw new \Exception('$data_callback must return an array.');
234 234
 					}
235
-				} catch ( \Throwable $e ) {
236
-					$this->throw_exception( $e );
235
+				} catch (\Throwable $e) {
236
+					$this->throw_exception($e);
237 237
 				}
238 238
 
239
-				$registered_data[ $namespace ] = $data;
239
+				$registered_data[$namespace] = $data;
240 240
 			}
241 241
 		}
242 242
 
@@ -251,26 +251,26 @@  discard block
 block discarded – undo
251 251
 	 * @return object Returns an array with registered schema data.
252 252
 	 * @throws \Exception If a registered callback throws an error, or silently logs it.
253 253
 	 */
254
-	public function get_endpoint_schema( $endpoint, array $passed_args = [] ) {
254
+	public function get_endpoint_schema($endpoint, array $passed_args = []) {
255 255
 		$registered_schema = [];
256 256
 
257
-		if ( isset( $this->extend_data[ $endpoint ] ) ) {
258
-			foreach ( $this->extend_data[ $endpoint ] as $namespace => $callbacks ) {
259
-				if ( is_null( $callbacks['schema_callback'] ) ) {
257
+		if (isset($this->extend_data[$endpoint])) {
258
+			foreach ($this->extend_data[$endpoint] as $namespace => $callbacks) {
259
+				if (is_null($callbacks['schema_callback'])) {
260 260
 					continue;
261 261
 				}
262 262
 				try {
263
-					$schema = $callbacks['schema_callback']( ...$passed_args );
263
+					$schema = $callbacks['schema_callback'](...$passed_args);
264 264
 
265
-					if ( ! is_array( $schema ) ) {
265
+					if (!is_array($schema)) {
266 266
 						$schema = [];
267
-						throw new \Exception( '$schema_callback must return an array.' );
267
+						throw new \Exception('$schema_callback must return an array.');
268 268
 					}
269
-				} catch ( \Throwable $e ) {
270
-					$this->throw_exception( $e );
269
+				} catch (\Throwable $e) {
270
+					$this->throw_exception($e);
271 271
 				}
272 272
 
273
-				$registered_schema[ $namespace ] = $this->format_extensions_properties( $namespace, $schema, $callbacks['schema_type'] );
273
+				$registered_schema[$namespace] = $this->format_extensions_properties($namespace, $schema, $callbacks['schema_type']);
274 274
 			}
275 275
 		}
276 276
 
@@ -285,19 +285,19 @@  discard block
 block discarded – undo
285 285
 	 * @return array Returns a list of payment requirements.
286 286
 	 * @throws \Exception If a registered callback throws an error, or silently logs it.
287 287
 	 */
288
-	public function get_payment_requirements( array $requirements = [ 'products' ] ) {
289
-		if ( ! empty( $this->payment_requirements ) ) {
290
-			foreach ( $this->payment_requirements as $callback ) {
288
+	public function get_payment_requirements(array $requirements = ['products']) {
289
+		if (!empty($this->payment_requirements)) {
290
+			foreach ($this->payment_requirements as $callback) {
291 291
 				try {
292 292
 					$data = $callback();
293 293
 
294
-					if ( ! is_array( $data ) ) {
295
-						throw new \Exception( '$data_callback must return an array.' );
294
+					if (!is_array($data)) {
295
+						throw new \Exception('$data_callback must return an array.');
296 296
 					}
297 297
 
298
-					$requirements = array_unique( array_merge( $requirements, $data ) );
299
-				} catch ( \Throwable $e ) {
300
-					$this->throw_exception( $e );
298
+					$requirements = array_unique(array_merge($requirements, $data));
299
+				} catch (\Throwable $e) {
300
+					$this->throw_exception($e);
301 301
 				}
302 302
 			}
303 303
 		}
@@ -310,12 +310,12 @@  discard block
 block discarded – undo
310 310
 	 * @param string|\Throwable $exception_or_error Error message or \Exception.
311 311
 	 * @throws \Exception An error to throw if we have debug enabled and user is admin.
312 312
 	 */
313
-	private function throw_exception( $exception_or_error ) {
314
-		$exception = is_string( $exception_or_error ) ? new \Exception( $exception_or_error ) : $exception_or_error;
313
+	private function throw_exception($exception_or_error) {
314
+		$exception = is_string($exception_or_error) ? new \Exception($exception_or_error) : $exception_or_error;
315 315
 
316
-		wc_caught_exception( $exception );
316
+		wc_caught_exception($exception);
317 317
 
318
-		if ( defined( 'WP_DEBUG' ) && WP_DEBUG && current_user_can( 'manage_woocommerce' ) ) {
318
+		if (defined('WP_DEBUG') && WP_DEBUG && current_user_can('manage_woocommerce')) {
319 319
 			throw $exception;
320 320
 		}
321 321
 	}
@@ -328,21 +328,21 @@  discard block
 block discarded – undo
328 328
 	 * @param string $schema_type How should data be shaped.
329 329
 	 * @return array Formatted schema.
330 330
 	 */
331
-	private function format_extensions_properties( $namespace, $schema, $schema_type ) {
332
-		if ( ARRAY_N === $schema_type ) {
331
+	private function format_extensions_properties($namespace, $schema, $schema_type) {
332
+		if (ARRAY_N === $schema_type) {
333 333
 			return [
334 334
 				/* translators: %s: extension namespace */
335
-				'description' => sprintf( __( 'Extension data registered by %s', 'woocommerce' ), $namespace ),
335
+				'description' => sprintf(__('Extension data registered by %s', 'woocommerce'), $namespace),
336 336
 				'type'        => 'array',
337
-				'context'     => [ 'view', 'edit' ],
337
+				'context'     => ['view', 'edit'],
338 338
 				'items'       => $schema,
339 339
 			];
340 340
 		}
341 341
 		return [
342 342
 			/* translators: %s: extension namespace */
343
-			'description' => sprintf( __( 'Extension data registered by %s', 'woocommerce' ), $namespace ),
343
+			'description' => sprintf(__('Extension data registered by %s', 'woocommerce'), $namespace),
344 344
 			'type'        => 'object',
345
-			'context'     => [ 'view', 'edit' ],
345
+			'context'     => ['view', 'edit'],
346 346
 			'properties'  => $schema,
347 347
 		];
348 348
 	}
Please login to merge, or discard this patch.
woocommerce-blocks/src/StoreApi/Schemas/V1/BillingAddressSchema.php 2 patches
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -9,120 +9,120 @@
 block discarded – undo
9 9
  * Provides a generic billing address schema for composition in other schemas.
10 10
  */
11 11
 class BillingAddressSchema extends AbstractAddressSchema {
12
-	/**
13
-	 * The schema item name.
14
-	 *
15
-	 * @var string
16
-	 */
17
-	protected $title = 'billing_address';
12
+    /**
13
+     * The schema item name.
14
+     *
15
+     * @var string
16
+     */
17
+    protected $title = 'billing_address';
18 18
 
19
-	/**
20
-	 * The schema item identifier.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	const IDENTIFIER = 'billing-address';
19
+    /**
20
+     * The schema item identifier.
21
+     *
22
+     * @var string
23
+     */
24
+    const IDENTIFIER = 'billing-address';
25 25
 
26
-	/**
27
-	 * Term properties.
28
-	 *
29
-	 * @return array
30
-	 */
31
-	public function get_properties() {
32
-		$properties = parent::get_properties();
33
-		return array_merge(
34
-			$properties,
35
-			[
36
-				'email' => [
37
-					'description' => __( 'Email', 'woocommerce' ),
38
-					'type'        => 'string',
39
-					'context'     => [ 'view', 'edit' ],
40
-					'required'    => true,
41
-				],
42
-			]
43
-		);
44
-	}
26
+    /**
27
+     * Term properties.
28
+     *
29
+     * @return array
30
+     */
31
+    public function get_properties() {
32
+        $properties = parent::get_properties();
33
+        return array_merge(
34
+            $properties,
35
+            [
36
+                'email' => [
37
+                    'description' => __( 'Email', 'woocommerce' ),
38
+                    'type'        => 'string',
39
+                    'context'     => [ 'view', 'edit' ],
40
+                    'required'    => true,
41
+                ],
42
+            ]
43
+        );
44
+    }
45 45
 
46
-	/**
47
-	 * Sanitize and format the given address object.
48
-	 *
49
-	 * @param array            $address Value being sanitized.
50
-	 * @param \WP_REST_Request $request The Request.
51
-	 * @param string           $param The param being sanitized.
52
-	 * @return array
53
-	 */
54
-	public function sanitize_callback( $address, $request, $param ) {
55
-		$address          = parent::sanitize_callback( $address, $request, $param );
56
-		$address['email'] = wc_clean( wp_unslash( $address['email'] ) );
57
-		return $address;
58
-	}
46
+    /**
47
+     * Sanitize and format the given address object.
48
+     *
49
+     * @param array            $address Value being sanitized.
50
+     * @param \WP_REST_Request $request The Request.
51
+     * @param string           $param The param being sanitized.
52
+     * @return array
53
+     */
54
+    public function sanitize_callback( $address, $request, $param ) {
55
+        $address          = parent::sanitize_callback( $address, $request, $param );
56
+        $address['email'] = wc_clean( wp_unslash( $address['email'] ) );
57
+        return $address;
58
+    }
59 59
 
60
-	/**
61
-	 * Validate the given address object.
62
-	 *
63
-	 * @param array            $address Value being sanitized.
64
-	 * @param \WP_REST_Request $request The Request.
65
-	 * @param string           $param The param being sanitized.
66
-	 * @return true|\WP_Error
67
-	 */
68
-	public function validate_callback( $address, $request, $param ) {
69
-		$errors  = parent::validate_callback( $address, $request, $param );
70
-		$address = $this->sanitize_callback( $address, $request, $param );
71
-		$errors  = is_wp_error( $errors ) ? $errors : new \WP_Error();
60
+    /**
61
+     * Validate the given address object.
62
+     *
63
+     * @param array            $address Value being sanitized.
64
+     * @param \WP_REST_Request $request The Request.
65
+     * @param string           $param The param being sanitized.
66
+     * @return true|\WP_Error
67
+     */
68
+    public function validate_callback( $address, $request, $param ) {
69
+        $errors  = parent::validate_callback( $address, $request, $param );
70
+        $address = $this->sanitize_callback( $address, $request, $param );
71
+        $errors  = is_wp_error( $errors ) ? $errors : new \WP_Error();
72 72
 
73
-		if ( ! empty( $address['email'] ) && ! is_email( $address['email'] ) ) {
74
-			$errors->add(
75
-				'invalid_email',
76
-				__( 'The provided email address is not valid', 'woocommerce' )
77
-			);
78
-		}
73
+        if ( ! empty( $address['email'] ) && ! is_email( $address['email'] ) ) {
74
+            $errors->add(
75
+                'invalid_email',
76
+                __( 'The provided email address is not valid', 'woocommerce' )
77
+            );
78
+        }
79 79
 
80
-		return $errors->has_errors( $errors ) ? $errors : true;
81
-	}
80
+        return $errors->has_errors( $errors ) ? $errors : true;
81
+    }
82 82
 
83
-	/**
84
-	 * Convert a term object into an object suitable for the response.
85
-	 *
86
-	 * @param \WC_Order|\WC_Customer $address An object with billing address.
87
-	 *
88
-	 * @throws RouteException When the invalid object types are provided.
89
-	 * @return stdClass
90
-	 */
91
-	public function get_item_response( $address ) {
92
-		if ( ( $address instanceof \WC_Customer || $address instanceof \WC_Order ) ) {
93
-			$billing_country = $address->get_billing_country();
94
-			$billing_state   = $address->get_billing_state();
83
+    /**
84
+     * Convert a term object into an object suitable for the response.
85
+     *
86
+     * @param \WC_Order|\WC_Customer $address An object with billing address.
87
+     *
88
+     * @throws RouteException When the invalid object types are provided.
89
+     * @return stdClass
90
+     */
91
+    public function get_item_response( $address ) {
92
+        if ( ( $address instanceof \WC_Customer || $address instanceof \WC_Order ) ) {
93
+            $billing_country = $address->get_billing_country();
94
+            $billing_state   = $address->get_billing_state();
95 95
 
96
-			if ( ! $this->validate_state( $billing_state, $billing_country ) ) {
97
-				$billing_state = '';
98
-			}
96
+            if ( ! $this->validate_state( $billing_state, $billing_country ) ) {
97
+                $billing_state = '';
98
+            }
99 99
 
100
-			return (object) $this->prepare_html_response(
101
-				[
102
-					'first_name' => $address->get_billing_first_name(),
103
-					'last_name'  => $address->get_billing_last_name(),
104
-					'company'    => $address->get_billing_company(),
105
-					'address_1'  => $address->get_billing_address_1(),
106
-					'address_2'  => $address->get_billing_address_2(),
107
-					'city'       => $address->get_billing_city(),
108
-					'state'      => $billing_state,
109
-					'postcode'   => $address->get_billing_postcode(),
110
-					'country'    => $billing_country,
111
-					'email'      => $address->get_billing_email(),
112
-					'phone'      => $address->get_billing_phone(),
113
-				]
114
-			);
115
-		}
116
-		throw new RouteException(
117
-			'invalid_object_type',
118
-			sprintf(
119
-				/* translators: Placeholders are class and method names */
120
-				__( '%1$s requires an instance of %2$s or %3$s for the address', 'woocommerce' ),
121
-				'BillingAddressSchema::get_item_response',
122
-				'WC_Customer',
123
-				'WC_Order'
124
-			),
125
-			500
126
-		);
127
-	}
100
+            return (object) $this->prepare_html_response(
101
+                [
102
+                    'first_name' => $address->get_billing_first_name(),
103
+                    'last_name'  => $address->get_billing_last_name(),
104
+                    'company'    => $address->get_billing_company(),
105
+                    'address_1'  => $address->get_billing_address_1(),
106
+                    'address_2'  => $address->get_billing_address_2(),
107
+                    'city'       => $address->get_billing_city(),
108
+                    'state'      => $billing_state,
109
+                    'postcode'   => $address->get_billing_postcode(),
110
+                    'country'    => $billing_country,
111
+                    'email'      => $address->get_billing_email(),
112
+                    'phone'      => $address->get_billing_phone(),
113
+                ]
114
+            );
115
+        }
116
+        throw new RouteException(
117
+            'invalid_object_type',
118
+            sprintf(
119
+                /* translators: Placeholders are class and method names */
120
+                __( '%1$s requires an instance of %2$s or %3$s for the address', 'woocommerce' ),
121
+                'BillingAddressSchema::get_item_response',
122
+                'WC_Customer',
123
+                'WC_Order'
124
+            ),
125
+            500
126
+        );
127
+    }
128 128
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -34,9 +34,9 @@  discard block
 block discarded – undo
34 34
 			$properties,
35 35
 			[
36 36
 				'email' => [
37
-					'description' => __( 'Email', 'woocommerce' ),
37
+					'description' => __('Email', 'woocommerce'),
38 38
 					'type'        => 'string',
39
-					'context'     => [ 'view', 'edit' ],
39
+					'context'     => ['view', 'edit'],
40 40
 					'required'    => true,
41 41
 				],
42 42
 			]
@@ -51,9 +51,9 @@  discard block
 block discarded – undo
51 51
 	 * @param string           $param The param being sanitized.
52 52
 	 * @return array
53 53
 	 */
54
-	public function sanitize_callback( $address, $request, $param ) {
55
-		$address          = parent::sanitize_callback( $address, $request, $param );
56
-		$address['email'] = wc_clean( wp_unslash( $address['email'] ) );
54
+	public function sanitize_callback($address, $request, $param) {
55
+		$address          = parent::sanitize_callback($address, $request, $param);
56
+		$address['email'] = wc_clean(wp_unslash($address['email']));
57 57
 		return $address;
58 58
 	}
59 59
 
@@ -65,19 +65,19 @@  discard block
 block discarded – undo
65 65
 	 * @param string           $param The param being sanitized.
66 66
 	 * @return true|\WP_Error
67 67
 	 */
68
-	public function validate_callback( $address, $request, $param ) {
69
-		$errors  = parent::validate_callback( $address, $request, $param );
70
-		$address = $this->sanitize_callback( $address, $request, $param );
71
-		$errors  = is_wp_error( $errors ) ? $errors : new \WP_Error();
68
+	public function validate_callback($address, $request, $param) {
69
+		$errors  = parent::validate_callback($address, $request, $param);
70
+		$address = $this->sanitize_callback($address, $request, $param);
71
+		$errors  = is_wp_error($errors) ? $errors : new \WP_Error();
72 72
 
73
-		if ( ! empty( $address['email'] ) && ! is_email( $address['email'] ) ) {
73
+		if (!empty($address['email']) && !is_email($address['email'])) {
74 74
 			$errors->add(
75 75
 				'invalid_email',
76
-				__( 'The provided email address is not valid', 'woocommerce' )
76
+				__('The provided email address is not valid', 'woocommerce')
77 77
 			);
78 78
 		}
79 79
 
80
-		return $errors->has_errors( $errors ) ? $errors : true;
80
+		return $errors->has_errors($errors) ? $errors : true;
81 81
 	}
82 82
 
83 83
 	/**
@@ -88,12 +88,12 @@  discard block
 block discarded – undo
88 88
 	 * @throws RouteException When the invalid object types are provided.
89 89
 	 * @return stdClass
90 90
 	 */
91
-	public function get_item_response( $address ) {
92
-		if ( ( $address instanceof \WC_Customer || $address instanceof \WC_Order ) ) {
91
+	public function get_item_response($address) {
92
+		if (($address instanceof \WC_Customer || $address instanceof \WC_Order)) {
93 93
 			$billing_country = $address->get_billing_country();
94 94
 			$billing_state   = $address->get_billing_state();
95 95
 
96
-			if ( ! $this->validate_state( $billing_state, $billing_country ) ) {
96
+			if (!$this->validate_state($billing_state, $billing_country)) {
97 97
 				$billing_state = '';
98 98
 			}
99 99
 
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 			'invalid_object_type',
118 118
 			sprintf(
119 119
 				/* translators: Placeholders are class and method names */
120
-				__( '%1$s requires an instance of %2$s or %3$s for the address', 'woocommerce' ),
120
+				__('%1$s requires an instance of %2$s or %3$s for the address', 'woocommerce'),
121 121
 				'BillingAddressSchema::get_item_response',
122 122
 				'WC_Customer',
123 123
 				'WC_Order'
Please login to merge, or discard this patch.
woocommerce-blocks/src/StoreApi/Schemas/V1/ProductAttributeSchema.php 2 patches
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -5,87 +5,87 @@
 block discarded – undo
5 5
  * ProductAttributeSchema class.
6 6
  */
7 7
 class ProductAttributeSchema extends AbstractSchema {
8
-	/**
9
-	 * The schema item name.
10
-	 *
11
-	 * @var string
12
-	 */
13
-	protected $title = 'product_attribute';
8
+    /**
9
+     * The schema item name.
10
+     *
11
+     * @var string
12
+     */
13
+    protected $title = 'product_attribute';
14 14
 
15
-	/**
16
-	 * The schema item identifier.
17
-	 *
18
-	 * @var string
19
-	 */
20
-	const IDENTIFIER = 'product-attribute';
15
+    /**
16
+     * The schema item identifier.
17
+     *
18
+     * @var string
19
+     */
20
+    const IDENTIFIER = 'product-attribute';
21 21
 
22
-	/**
23
-	 * Term properties.
24
-	 *
25
-	 * @return array
26
-	 */
27
-	public function get_properties() {
28
-		return [
29
-			'id'           => array(
30
-				'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
31
-				'type'        => 'integer',
32
-				'context'     => array( 'view', 'edit' ),
33
-				'readonly'    => true,
34
-			),
35
-			'name'         => array(
36
-				'description' => __( 'Attribute name.', 'woocommerce' ),
37
-				'type'        => 'string',
38
-				'context'     => array( 'view', 'edit' ),
39
-				'readonly'    => true,
40
-			),
41
-			'taxonomy'     => array(
42
-				'description' => __( 'The attribute taxonomy name.', 'woocommerce' ),
43
-				'type'        => 'string',
44
-				'context'     => array( 'view', 'edit' ),
45
-				'readonly'    => true,
46
-			),
47
-			'type'         => array(
48
-				'description' => __( 'Attribute type.', 'woocommerce' ),
49
-				'type'        => 'string',
50
-				'context'     => array( 'view', 'edit' ),
51
-				'readonly'    => true,
52
-			),
53
-			'order'        => array(
54
-				'description' => __( 'How terms in this attribute are sorted by default.', 'woocommerce' ),
55
-				'type'        => 'string',
56
-				'context'     => array( 'view', 'edit' ),
57
-				'readonly'    => true,
58
-			),
59
-			'has_archives' => array(
60
-				'description' => __( 'If this attribute has term archive pages.', 'woocommerce' ),
61
-				'type'        => 'boolean',
62
-				'context'     => array( 'view', 'edit' ),
63
-				'readonly'    => true,
64
-			),
65
-			'count'        => array(
66
-				'description' => __( 'Number of terms in the attribute taxonomy.', 'woocommerce' ),
67
-				'type'        => 'integer',
68
-				'context'     => array( 'view', 'edit' ),
69
-				'readonly'    => true,
70
-			),
71
-		];
72
-	}
22
+    /**
23
+     * Term properties.
24
+     *
25
+     * @return array
26
+     */
27
+    public function get_properties() {
28
+        return [
29
+            'id'           => array(
30
+                'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
31
+                'type'        => 'integer',
32
+                'context'     => array( 'view', 'edit' ),
33
+                'readonly'    => true,
34
+            ),
35
+            'name'         => array(
36
+                'description' => __( 'Attribute name.', 'woocommerce' ),
37
+                'type'        => 'string',
38
+                'context'     => array( 'view', 'edit' ),
39
+                'readonly'    => true,
40
+            ),
41
+            'taxonomy'     => array(
42
+                'description' => __( 'The attribute taxonomy name.', 'woocommerce' ),
43
+                'type'        => 'string',
44
+                'context'     => array( 'view', 'edit' ),
45
+                'readonly'    => true,
46
+            ),
47
+            'type'         => array(
48
+                'description' => __( 'Attribute type.', 'woocommerce' ),
49
+                'type'        => 'string',
50
+                'context'     => array( 'view', 'edit' ),
51
+                'readonly'    => true,
52
+            ),
53
+            'order'        => array(
54
+                'description' => __( 'How terms in this attribute are sorted by default.', 'woocommerce' ),
55
+                'type'        => 'string',
56
+                'context'     => array( 'view', 'edit' ),
57
+                'readonly'    => true,
58
+            ),
59
+            'has_archives' => array(
60
+                'description' => __( 'If this attribute has term archive pages.', 'woocommerce' ),
61
+                'type'        => 'boolean',
62
+                'context'     => array( 'view', 'edit' ),
63
+                'readonly'    => true,
64
+            ),
65
+            'count'        => array(
66
+                'description' => __( 'Number of terms in the attribute taxonomy.', 'woocommerce' ),
67
+                'type'        => 'integer',
68
+                'context'     => array( 'view', 'edit' ),
69
+                'readonly'    => true,
70
+            ),
71
+        ];
72
+    }
73 73
 
74
-	/**
75
-	 * Convert an attribute object into an object suitable for the response.
76
-	 *
77
-	 * @param object $attribute Attribute object.
78
-	 * @return array
79
-	 */
80
-	public function get_item_response( $attribute ) {
81
-		return [
82
-			'id'           => (int) $attribute->id,
83
-			'name'         => $this->prepare_html_response( $attribute->name ),
84
-			'taxonomy'     => $attribute->slug,
85
-			'type'         => $attribute->type,
86
-			'order'        => $attribute->order_by,
87
-			'has_archives' => $attribute->has_archives,
88
-			'count'        => (int) \wp_count_terms( $attribute->slug ),
89
-		];
90
-	}
74
+    /**
75
+     * Convert an attribute object into an object suitable for the response.
76
+     *
77
+     * @param object $attribute Attribute object.
78
+     * @return array
79
+     */
80
+    public function get_item_response( $attribute ) {
81
+        return [
82
+            'id'           => (int) $attribute->id,
83
+            'name'         => $this->prepare_html_response( $attribute->name ),
84
+            'taxonomy'     => $attribute->slug,
85
+            'type'         => $attribute->type,
86
+            'order'        => $attribute->order_by,
87
+            'has_archives' => $attribute->has_archives,
88
+            'count'        => (int) \wp_count_terms( $attribute->slug ),
89
+        ];
90
+    }
91 91
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -27,45 +27,45 @@  discard block
 block discarded – undo
27 27
 	public function get_properties() {
28 28
 		return [
29 29
 			'id'           => array(
30
-				'description' => __( 'Unique identifier for the resource.', 'woocommerce' ),
30
+				'description' => __('Unique identifier for the resource.', 'woocommerce'),
31 31
 				'type'        => 'integer',
32
-				'context'     => array( 'view', 'edit' ),
32
+				'context'     => array('view', 'edit'),
33 33
 				'readonly'    => true,
34 34
 			),
35 35
 			'name'         => array(
36
-				'description' => __( 'Attribute name.', 'woocommerce' ),
36
+				'description' => __('Attribute name.', 'woocommerce'),
37 37
 				'type'        => 'string',
38
-				'context'     => array( 'view', 'edit' ),
38
+				'context'     => array('view', 'edit'),
39 39
 				'readonly'    => true,
40 40
 			),
41 41
 			'taxonomy'     => array(
42
-				'description' => __( 'The attribute taxonomy name.', 'woocommerce' ),
42
+				'description' => __('The attribute taxonomy name.', 'woocommerce'),
43 43
 				'type'        => 'string',
44
-				'context'     => array( 'view', 'edit' ),
44
+				'context'     => array('view', 'edit'),
45 45
 				'readonly'    => true,
46 46
 			),
47 47
 			'type'         => array(
48
-				'description' => __( 'Attribute type.', 'woocommerce' ),
48
+				'description' => __('Attribute type.', 'woocommerce'),
49 49
 				'type'        => 'string',
50
-				'context'     => array( 'view', 'edit' ),
50
+				'context'     => array('view', 'edit'),
51 51
 				'readonly'    => true,
52 52
 			),
53 53
 			'order'        => array(
54
-				'description' => __( 'How terms in this attribute are sorted by default.', 'woocommerce' ),
54
+				'description' => __('How terms in this attribute are sorted by default.', 'woocommerce'),
55 55
 				'type'        => 'string',
56
-				'context'     => array( 'view', 'edit' ),
56
+				'context'     => array('view', 'edit'),
57 57
 				'readonly'    => true,
58 58
 			),
59 59
 			'has_archives' => array(
60
-				'description' => __( 'If this attribute has term archive pages.', 'woocommerce' ),
60
+				'description' => __('If this attribute has term archive pages.', 'woocommerce'),
61 61
 				'type'        => 'boolean',
62
-				'context'     => array( 'view', 'edit' ),
62
+				'context'     => array('view', 'edit'),
63 63
 				'readonly'    => true,
64 64
 			),
65 65
 			'count'        => array(
66
-				'description' => __( 'Number of terms in the attribute taxonomy.', 'woocommerce' ),
66
+				'description' => __('Number of terms in the attribute taxonomy.', 'woocommerce'),
67 67
 				'type'        => 'integer',
68
-				'context'     => array( 'view', 'edit' ),
68
+				'context'     => array('view', 'edit'),
69 69
 				'readonly'    => true,
70 70
 			),
71 71
 		];
@@ -77,15 +77,15 @@  discard block
 block discarded – undo
77 77
 	 * @param object $attribute Attribute object.
78 78
 	 * @return array
79 79
 	 */
80
-	public function get_item_response( $attribute ) {
80
+	public function get_item_response($attribute) {
81 81
 		return [
82 82
 			'id'           => (int) $attribute->id,
83
-			'name'         => $this->prepare_html_response( $attribute->name ),
83
+			'name'         => $this->prepare_html_response($attribute->name),
84 84
 			'taxonomy'     => $attribute->slug,
85 85
 			'type'         => $attribute->type,
86 86
 			'order'        => $attribute->order_by,
87 87
 			'has_archives' => $attribute->has_archives,
88
-			'count'        => (int) \wp_count_terms( $attribute->slug ),
88
+			'count'        => (int) \wp_count_terms($attribute->slug),
89 89
 		];
90 90
 	}
91 91
 }
Please login to merge, or discard this patch.