WC_Order_Refund::get_refund()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
eloc 7
nc 3
nop 1
1
<?php
2
3
if ( ! defined( 'ABSPATH' ) ) {
4
	exit; // Exit if accessed directly
5
}
6
7
/**
8
 * Order refund
9
 *
10
 * @class    WC_Order_Refund
11
 * @version  2.2.0
12
 * @package  WooCommerce/Classes
13
 * @category Class
14
 * @author   WooThemes
15
 */
16
class WC_Order_Refund extends WC_Abstract_Order {
17
18
	/** @public string Order type */
19
	public $order_type = 'refund';
20
21
	/** @var string Date */
22
	public $date;
23
24
	/** @var string Refund reason */
25
	public $reason;
26
27
	/**
28
	 * Init/load the refund object. Called from the constructor.
29
	 *
30
	 * @param  string|int|object|WC_Order_Refund $refund Refund to init
31
	 * @uses   WP_POST
32
	 */
33 View Code Duplication
	protected function init( $refund ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
		if ( is_numeric( $refund ) ) {
35
			$this->id   = absint( $refund );
36
			$this->post = get_post( $refund );
37
			$this->get_refund( $this->id );
38
		} elseif ( $refund instanceof WC_Order_Refund ) {
39
			$this->id   = absint( $refund->id );
40
			$this->post = $refund->post;
41
			$this->get_refund( $this->id );
42
		} elseif ( isset( $refund->ID ) ) {
43
			$this->id   = absint( $refund->ID );
44
			$this->post = $refund;
45
			$this->get_refund( $this->id );
46
		}
47
	}
48
49
	/**
50
	 * Gets an refund from the database.
51
	 *
52
	 * @since 2.2
53
	 * @param int $id
54
	 * @return bool
55
	 */
56 View Code Duplication
	public function get_refund( $id = 0 ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
		if ( ! $id ) {
58
			return false;
59
		}
60
61
		if ( $result = get_post( $id ) ) {
62
			$this->populate( $result );
63
64
			return true;
65
		}
66
67
		return false;
68
	}
69
70
	/**
71
	 * Populates an refund from the loaded post data.
72
	 *
73
	 * @param mixed $result
74
	 */
75
	public function populate( $result ) {
76
		// Standard post data
77
		$this->id            = $result->ID;
78
		$this->date          = $result->post_date;
79
		$this->modified_date = $result->post_modified;
80
		$this->reason        = $result->post_excerpt;
81
	}
82
83
	/**
84
	 * Get refunded amount.
85
	 *
86
	 * @since 2.2
87
	 * @return int|float
88
	 */
89
	public function get_refund_amount() {
90
		return apply_filters( 'woocommerce_refund_amount', (double) $this->refund_amount, $this );
91
	}
92
93
	/**
94
	 * Get formatted refunded amount.
95
	 *
96
	 * @since 2.4
97
	 * @return string
98
	 */
99
	public function get_formatted_refund_amount() {
100
		return apply_filters( 'woocommerce_formatted_refund_amount', wc_price( $this->refund_amount, array('currency' => $this->get_order_currency()) ), $this );
101
	}
102
103
104
	/**
105
	 * Get refunded amount.
106
	 *
107
	 * @since 2.2
108
	 * @return int|float
109
	 */
110
	public function get_refund_reason() {
111
		return apply_filters( 'woocommerce_refund_reason', $this->reason, $this );
112
	}
113
}
114