WC_Email_Customer_New_Account   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 114
Duplicated Lines 10.53 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 12
loc 114
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 1
A trigger() 0 18 4
A get_content_html() 0 12 1
A get_content_plain() 12 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
if ( ! defined( 'ABSPATH' ) ) {
4
	exit; // Exit if accessed directly
5
}
6
7
if ( ! class_exists( 'WC_Email_Customer_New_Account' ) ) :
8
9
/**
10
 * Customer New Account.
11
 *
12
 * An email sent to the customer when they create an account.
13
 *
14
 * @class       WC_Email_Customer_New_Account
15
 * @version     2.3.0
16
 * @package     WooCommerce/Classes/Emails
17
 * @author      WooThemes
18
 * @extends     WC_Email
19
 */
20
class WC_Email_Customer_New_Account extends WC_Email {
21
22
	/**
23
	 * User login name.
24
	 *
25
	 * @var string
26
	 */
27
	public $user_login;
28
29
	/**
30
	 * User email.
31
	 *
32
	 * @var string
33
	 */
34
	public $user_email;
35
36
	/**
37
	 * User password.
38
	 *
39
	 * @var string
40
	 */
41
	public $user_pass;
42
43
	/**
44
	 * Is the password generated?
45
	 *
46
	 * @var bool
47
	 */
48
	public $password_generated;
49
50
	/**
51
	 * Constructor.
52
	 */
53
	public function __construct() {
54
55
		$this->id             = 'customer_new_account';
56
		$this->customer_email = true;
57
		$this->title          = __( 'New account', 'woocommerce' );
58
		$this->description    = __( 'Customer "new account" emails are sent to the customer when a customer signs up via checkout or account pages.', 'woocommerce' );
59
60
		$this->template_html  = 'emails/customer-new-account.php';
61
		$this->template_plain = 'emails/plain/customer-new-account.php';
62
63
		$this->subject        = __( 'Your account on {site_title}', 'woocommerce');
64
		$this->heading        = __( 'Welcome to {site_title}', 'woocommerce');
65
66
		// Call parent constuctor
67
		parent::__construct();
68
	}
69
70
	/**
71
	 * Trigger.
72
	 *
73
	 * @param int $user_id
74
	 * @param string $user_pass
75
	 * @param bool $password_generated
76
	 */
77
	public function trigger( $user_id, $user_pass = '', $password_generated = false ) {
78
79
		if ( $user_id ) {
80
			$this->object             = new WP_User( $user_id );
81
82
			$this->user_pass          = $user_pass;
83
			$this->user_login         = stripslashes( $this->object->user_login );
84
			$this->user_email         = stripslashes( $this->object->user_email );
85
			$this->recipient          = $this->user_email;
86
			$this->password_generated = $password_generated;
87
		}
88
89
		if ( ! $this->is_enabled() || ! $this->get_recipient() ) {
90
			return;
91
		}
92
93
		$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
94
	}
95
96
	/**
97
	 * Get content html.
98
	 *
99
	 * @access public
100
	 * @return string
101
	 */
102
	public function get_content_html() {
103
		return wc_get_template_html( $this->template_html, array(
104
			'email_heading'      => $this->get_heading(),
105
			'user_login'         => $this->user_login,
106
			'user_pass'          => $this->user_pass,
107
			'blogname'           => $this->get_blogname(),
108
			'password_generated' => $this->password_generated,
109
			'sent_to_admin'      => false,
110
			'plain_text'         => false,
111
			'email'				 => $this
112
		) );
113
	}
114
115
	/**
116
	 * Get content plain.
117
	 *
118
	 * @access public
119
	 * @return string
120
	 */
121 View Code Duplication
	public function get_content_plain() {
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...
122
		return wc_get_template_html( $this->template_plain, array(
123
			'email_heading'      => $this->get_heading(),
124
			'user_login'         => $this->user_login,
125
			'user_pass'          => $this->user_pass,
126
			'blogname'           => $this->get_blogname(),
127
			'password_generated' => $this->password_generated,
128
			'sent_to_admin'      => false,
129
			'plain_text'         => true,
130
			'email'			     => $this
131
		) );
132
	}
133
}
134
135
endif;
136
137
return new WC_Email_Customer_New_Account();
138