get_content_plain()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
eloc 7
nc 1
nop 0
1
<?php
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 Processing Order Email.
11
 *
12
 * An email sent to the customer when a new order is paid for.
13
 *
14
 * @class       WC_Email_Customer_Processing_Order
15
 * @version     2.0.0
16
 * @package     WooCommerce/Classes/Emails
17
 * @author      WooThemes
18
 * @extends     WC_Email
19
 */
20
class WC_Email_Customer_Processing_Order extends WC_Email {
21
22
	/**
23
	 * Constructor.
24
	 */
25
	public function __construct() {
26
		$this->id               = 'customer_processing_order';
27
		$this->customer_email   = true;
28
		$this->title            = __( 'Processing order', 'woocommerce' );
29
		$this->description      = __( 'This is an order notification sent to customers containing order details after payment.', '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-processing-order.php';
33
		$this->template_plain   = 'emails/plain/customer-processing-order.php';
34
35
		// Triggers for this email
36
		add_action( 'woocommerce_order_status_pending_to_processing_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
	public function trigger( $order_id ) {
48
49
		if ( $order_id ) {
50
			$this->object       = wc_get_order( $order_id );
0 ignored issues
show
Documentation Bug introduced by
It seems like wc_get_order($order_id) can also be of type false. However, the property $object is declared as type object. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
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() );
65
	}
66
67
	/**
68
	 * Get content html.
69
	 *
70
	 * @access public
71
	 * @return string
72
	 */
73
	public function get_content_html() {
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
	public function get_content_plain() {
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_Processing_Order();
103