Completed
Pull Request — master (#10259)
by Mike
09:41
created

WC_Order_Refund::init()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 13

Duplication

Lines 15
Ratio 100 %
Metric Value
dl 15
loc 15
rs 9.2
cc 4
eloc 13
nc 4
nop 1
1
<?php
1 ignored issue
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 16 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
if ( ! defined( 'ABSPATH' ) ) {
3
	exit;
4
}
5
6
/**
7
 * Order refund. Refunds are based on orders (essentially negative orders) and
8
 * contain much of the same data.
9
 *
10
 * @class    WC_Order_Refund
11
 * @version  2.6.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
     * Data array, with defaults.
29
     *
30
     * @todo when migrating to custom tables, these will be columns
31
     * @since 2.6.0
32
     * @var array
33
     */
34
    protected $_refund_data = array(
35
		'refund_amount' => '',
36
		'refund_reason' => '',
37
	);
38
39
    /**
40
     * Get the refund if ID is passed, otherwise the refund is new and empty.
41
     * @param  int|object|WC_Order_Refund $refund Refund to init.
42
     */
43 View Code Duplication
    public function __construct( $refund = 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...
44
		if ( is_numeric( $refund ) ) {
45
            $this->read( $refund );
46
        } elseif ( $order instanceof WC_Order_Refund ) {
47
            $this->read( absint( $refund->get_id() ) );
48
        } elseif ( ! empty( $refund->ID ) ) {
49
            $this->read( absint( $refund->ID ) );
50
        }
51
    }
52
53
	/**
54
	 * Get refunded amount.
55
	 *
56
	 * @since 2.2
57
	 * @return int|float
58
	 */
59
	public function get_refund_amount() {
60
		return apply_filters( 'woocommerce_refund_amount', (double) $this->refund_amount, $this );
61
	}
62
63
	/**
64
	 * Get formatted refunded amount.
65
	 *
66
	 * @since 2.4
67
	 * @return string
68
	 */
69
	public function get_formatted_refund_amount() {
70
		return apply_filters( 'woocommerce_formatted_refund_amount', wc_price( $this->refund_amount, array('currency' => $this->get_order_currency()) ), $this );
71
	}
72
73
	/**
74
	 * Get refunded amount.
75
	 *
76
	 * @since 2.2
77
	 * @return int|float
78
	 */
79
	public function get_refund_reason() {
80
		return apply_filters( 'woocommerce_refund_reason', $this->reason, $this );
81
	}
82
83
	/**
84
     * Gets an refund from the database.
85
     * @deprecated 2.6
86
     * @param int $id (default: 0).
87
     * @return bool
88
     */
89 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...
90
        _deprecated_function( 'get_refund', '2.6', 'read' );
91
        if ( ! $id ) {
92
            return false;
93
        }
94
        if ( $result = get_post( $id ) ) {
95
            $this->populate( $result );
0 ignored issues
show
Deprecated Code introduced by
The method WC_Abstract_Order::populate() has been deprecated with message: 2.6

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
96
            return true;
97
        }
98
        return false;
99
    }
100
}
101