Completed
Push — master ( 1fecd7...971f6a )
by Mike
07:38
created

WC_Email_Customer_On_Hold_Order::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 16
Ratio 100 %
Metric Value
dl 16
loc 16
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
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 20 and the first side effect is on line 4.

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

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

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

Loading history...
8
9
/**
10
 * Customer On-hold Order Email.
11
 *
12
 * An email sent to the customer when a new order is on-hold for.
13
 *
14
 * @class       WC_Email_Customer_On_Hold_Order
15
 * @version     2.0.0
16
 * @package     WooCommerce/Classes/Emails
17
 * @author      WooThemes
18
 * @extends     WC_Email
19
 */
20
class WC_Email_Customer_On_Hold_Order extends WC_Email {
21
22
	/**
23
	 * Constructor.
24
	 */
25
	function __construct() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
26
		$this->id               = 'customer_on_hold_order';
27
		$this->customer_email   = true;
28
		$this->title            = __( 'Order on-hold', 'woocommerce' );
29
		$this->description      = __( 'This is an order notification sent to customers containing order details after an order is placed on-hold.', 'woocommerce' );
30
		$this->heading          = __( 'Thank you for your order', 'woocommerce' );
31
		$this->subject          = __( 'Your {site_title} order receipt from {order_date}', 'woocommerce' );
32
		$this->template_html    = 'emails/customer-on-hold-order.php';
33
		$this->template_plain   = 'emails/plain/customer-on-hold-order.php';
34
35
		// Triggers for this email
36
		add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $this, 'trigger' ) );
37
38
		// Call parent constructor
39
		parent::__construct();
40
	}
41
42
	/**
43
	 * Trigger.
44
	 *
45
	 * @param int $order_id
46
	 */
47
	function trigger( $order_id ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
48
49
		if ( $order_id ) {
50
			$this->object       = wc_get_order( $order_id );
51
			$this->recipient    = $this->object->billing_email;
52
53
			$this->find['order-date']      = '{order_date}';
54
			$this->find['order-number']    = '{order_number}';
55
56
			$this->replace['order-date']   = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) );
57
			$this->replace['order-number'] = $this->object->get_order_number();
58
		}
59
60
		if ( ! $this->is_enabled() || ! $this->get_recipient() ) {
61
			return;
62
		}
63
64
		$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
0 ignored issues
show
Bug introduced by
It seems like $this->get_attachments() targeting WC_Email::get_attachments() can also be of type array; however, WC_Email::send() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
65
	}
66
67
	/**
68
	 * Get content html.
69
	 *
70
	 * @access public
71
	 * @return string
72
	 */
73
	function get_content_html() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
74
		return wc_get_template_html( $this->template_html, array(
75
			'order'         => $this->object,
76
			'email_heading' => $this->get_heading(),
77
			'sent_to_admin' => false,
78
			'plain_text'    => false,
79
			'email'			=> $this
80
		) );
81
	}
82
83
	/**
84
	 * Get content plain.
85
	 *
86
	 * @access public
87
	 * @return string
88
	 */
89
	function get_content_plain() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
90
		return wc_get_template_html( $this->template_plain, array(
91
			'order'         => $this->object,
92
			'email_heading' => $this->get_heading(),
93
			'sent_to_admin' => false,
94
			'plain_text'    => true,
95
			'email'			=> $this
96
		) );
97
	}
98
}
99
100
endif;
101
102
return new WC_Email_Customer_On_Hold_Order();
103