trigger()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 15

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 27
rs 8.8571
cc 2
eloc 15
nc 2
nop 2
1
<?php
0 ignored issues
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 17 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
3
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
5
if ( ! class_exists( 'WooThemes_Sensei_Email_Learner_Completed_Course' ) ) :
6
7
/**
8
 * Learner Completed Course
9
 *
10
 * An email sent to the learner when they complete a course.
11
 *
12
 * @package Users
13
 * @author Automattic
14
 *
15
 * @since		1.6.0
16
 */
17
class WooThemes_Sensei_Email_Learner_Completed_Course {
18
19
	var $template;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $template.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
20
	var $subject;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $subject.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
21
	var $heading;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $heading.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
22
	var $recipient;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $recipient.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
23
	var $user;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $user.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

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

Loading history...
24
25
	/**
26
	 * Constructor
27
	 *
28
	 * @access public
29
	 * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
30
	 */
31
	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...
32
		$this->template = 'learner-completed-course';
33
		$this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] You have completed a course', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template );
34
		$this->heading = apply_filters( 'sensei_email_heading', __( 'You have completed a course', 'woothemes-sensei' ), $this->template );
35
	}
36
37
	/**
38
	 * trigger function.
39
	 *
40
	 * @access public
41
     *
42
     * @param int $user_id
43
     * @param int $course_id
44
     *
45
	 * @return void
46
	 */
47
	function trigger( $user_id = 0, $course_id = 0 ) {
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
		global  $sensei_email_data;
49
50
		// Get learner user object
51
		$this->user = new WP_User( $user_id );
52
53
		// Get passed status
54
		$passed = __( 'passed', 'woothemes-sensei' );
55
		if( ! Sensei_Utils::sensei_user_passed_course( $course_id, $user_id ) ) {
56
			$passed = __( 'failed', 'woothemes-sensei' );
57
		}
58
59
		// Construct data array
60
		$sensei_email_data = apply_filters( 'sensei_email_data', array(
61
			'template'			=> $this->template,
62
			'heading'			=> $this->heading,
63
			'user_id'			=> $user_id,
64
			'course_id'			=> $course_id,
65
			'passed'			=> $passed,
66
		), $this->template );
67
68
		// Set recipient (learner)
69
		$this->recipient = stripslashes( $this->user->user_email );
70
71
		// Send mail
72
		Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) );
73
	}
74
}
75
76
endif;
77
78
return new WooThemes_Sensei_Email_Learner_Completed_Course();