WooThemes_Sensei_Email_Teacher_Started_Course   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 53
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 2
lcom 1
cbo 2
dl 53
loc 53
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
B trigger() 26 26 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
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 View Code Duplication
if ( ! class_exists( 'WooThemes_Sensei_Email_Teacher_Started_Course' ) ) :
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...
6
7
/**
8
 * Teacher Started Course
9
 *
10
 * An email sent to the teacher when one of their students starts a course.
11
 *
12
 * @package Users
13
 * @author Automattic
14
 *
15
 * @since		1.6.0
16
 */
17
class WooThemes_Sensei_Email_Teacher_Started_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
	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...
30
		$this->template = 'teacher-started-course';
31
		$this->subject = apply_filters( 'sensei_email_subject', sprintf( __( '[%1$s] Your student has started a course', 'woothemes-sensei' ), get_bloginfo( 'name' ) ), $this->template );
32
		$this->heading = apply_filters( 'sensei_email_heading', __( 'Your student has started a course', 'woothemes-sensei' ), $this->template );
33
	}
34
35
	/**
36
	 * trigger function.
37
	 *
38
     * @param int $learner_id
39
     * @param int $course_id
40
     *
41
	 * @return void
42
	 */
43
	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...
44
		global  $sensei_email_data;
45
46
		// Get learner user object
47
		$this->learner = new WP_User( $learner_id );
48
49
		// Get teacher ID and user object
50
		$teacher_id = get_post_field( 'post_author', $course_id, 'raw' );
51
		$this->teacher = new WP_User( $teacher_id );
52
53
		// Construct data array
54
		$sensei_email_data = apply_filters( 'sensei_email_data', array(
55
			'template'			=> $this->template,
56
			'heading'			=> $this->heading,
57
			'teacher_id'		=> $teacher_id,
58
			'learner_id'		=> $learner_id,
59
			'learner_name'		=> $this->learner->display_name,
60
			'course_id'			=> $course_id,
61
		), $this->template );
62
63
		// Set recipient (learner)
64
		$this->recipient = stripslashes( $this->teacher->user_email );
65
66
		// Send mail
67
		Sensei()->emails->send( $this->recipient, $this->subject, Sensei()->emails->get_content( $this->template ) );
68
	}
69
}
70
71
endif;
72
73
return new WooThemes_Sensei_Email_Teacher_Started_Course();