WooThemes_Sensei_Email_Teacher_Completed_Course   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 62
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B trigger() 0 33 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_Teacher_Completed_Course' ) ) :
6
7
/**
8
 * Teacher Completed Course
9
 *
10
 * An email sent to the teacher when one of their students completes a course.
11
 *
12
 * @package Users
13
 * @author Automattic
14
 *
15
 * @since		1.6.0
16
 */
17
class WooThemes_Sensei_Email_Teacher_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 $learner;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $learner.

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
	var $teacher;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $teacher.

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...
25
26
	/**
27
	 * Constructor
28
	 *
29
	 * @access public
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 = 'teacher-completed-course';
33
		$this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] Your student has completed a course', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template );
34
		$this->heading = apply_filters( 'sensei_email_heading', __( 'Your student has completed a course', 'woothemes-sensei' ), $this->template );
35
	}
36
37
	/**
38
	 * trigger function.
39
	 *
40
     * @param int $learner_id
41
     * @param int $course_id
42
     *
43
	 * @return void
44
	 */
45
	function trigger( $learner_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...
46
		global  $sensei_email_data;
47
48
		// Get learner user object
49
		$this->learner = new WP_User( $learner_id );
50
51
		// Get teacher ID and user object
52
		$teacher_id = get_post_field( 'post_author', $course_id, 'raw' );
53
		$this->teacher = new WP_User( $teacher_id );
54
55
		// Get passed status
56
		$passed = __( 'passed', 'woothemes-sensei' );
57
		if( ! Sensei_Utils::sensei_user_passed_course( $course_id, $learner_id ) ) {
58
			$passed = __( 'failed', 'woothemes-sensei' );
59
		}
60
61
		// Construct data array
62
		$sensei_email_data = apply_filters( 'sensei_email_data', array(
63
			'template'			=> $this->template,
64
			'heading'			=> $this->heading,
65
			'teacher_id'		=> $teacher_id,
66
			'learner_id'		=> $learner_id,
67
			'learner_name'		=> $this->learner->display_name,
68
			'course_id'			=> $course_id,
69
			'passed'			=> $passed,
70
		), $this->template );
71
72
		// Set recipient (learner)
73
		$this->recipient = stripslashes( $this->teacher->user_email );
74
75
		// Send mail
76
		Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) );
77
	}
78
}
79
80
endif;
81
82
return new WooThemes_Sensei_Email_Teacher_Completed_Course();