Passed
Push — lsx-wp6 ( 4c21d3 )
by
unknown
04:54
created

LSX_Sensei_Course   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 147
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 59
dl 0
loc 147
rs 10
c 1
b 0
f 0
wmc 20

9 Methods

Rating   Name   Duplication   Size   Complexity  
A course_body_div_close() 0 3 1
A course_body_div_results_open() 0 3 1
A init() 0 31 1
A instance() 0 5 2
A course_body_div_open() 0 9 2
B display_course_amount() 0 14 10
A course_body_div_results_close() 0 3 1
A get_course_thumbnail() 0 5 1
A __construct() 0 2 1
1
<?php
2
/**
3
 * LSX Sensei Course Class
4
 *
5
 * @package    lsx
6
 * @subpackage sensei
7
 */
8
9
if ( ! defined( 'ABSPATH' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
10
	exit; // Exit if accessed directly.
11
}
12
13
/**
14
 * LSX Sensei Course Class
15
 */
16
class LSX_Sensei_Course {
17
18
	/**
19
	 * Instance of class.
20
	 *
21
	 * @var self
22
	 */
23
	private static $instance;
24
25
	/**
26
	 * Constructor.
27
	 */
28
	public function __construct() {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
29
		add_action( 'init', array( $this, 'init' ) );
30
	} // End __construct()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
31
32
	/**
33
	 * Fetches an instance of the class.
34
	 *
35
	 * @return self
36
	 */
37
	public static function instance() {
38
		if ( ! self::$instance ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
39
			self::$instance = new self();
40
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
41
		return self::$instance;
42
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
43
44
	/**
45
	 * Run our changes.
46
	 */
47
	public function init() {
48
		global $sensei;
49
		global $woothemes_sensei;
50
51
		// Switching the course filters and the headers around.
52
		remove_action( 'sensei_archive_before_course_loop', array( 'Sensei_Course', 'archive_header' ), 10, 0 );
0 ignored issues
show
Unused Code introduced by
The call to remove_action() has too many arguments starting with 0. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
		/** @scrutinizer ignore-call */ 
53
  remove_action( 'sensei_archive_before_course_loop', array( 'Sensei_Course', 'archive_header' ), 10, 0 );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
53
		remove_action( 'sensei_archive_before_course_loop', array( 'Sensei_Course', 'course_archive_sorting' ) );
54
		remove_action( 'sensei_archive_before_course_loop', array( 'Sensei_Course', 'course_archive_filters' ) );
55
		add_action( 'sensei_archive_before_course_loop', array( 'Sensei_Course', 'archive_header' ), 11, 0 );
56
		add_action( 'sensei_archive_before_course_loop', array( 'Sensei_Course', 'course_archive_sorting' ), 12 );
57
		add_action( 'sensei_archive_before_course_loop', array( 'Sensei_Course', 'course_archive_filters' ), 12 );
58
59
		// First add the thumbnail.
60
		add_action( 'sensei_course_content_inside_before', array( $this, 'get_course_thumbnail' ), 1 );
61
62
		// This is for our wrapper, we run it on 2, after the thumbnail we added.
63
		add_action( 'sensei_course_content_inside_before', array( $this, 'course_body_div_open' ), 1 );
64
		add_action( 'sensei_course_content_inside_after', array( $this, 'course_body_div_close' ), 50 );
65
66
		// This is for our wrapper, we run it on 2, after the thumbnail we added.
67
		add_action( 'sensei_course_content_inside_before', array( $this, 'course_body_div_results_open' ), 20 );
68
		add_action( 'sensei_course_content_inside_after', array( $this, 'course_body_div_results_close' ), 49 );
69
70
		add_action( 'sensei_single_course_content_inside_before', array( $this, 'display_course_amount' ), 20 );
71
72
		// removes the course image above the content.
73
		remove_action( 'sensei_course_content_inside_before', array( $woothemes_sensei->course, 'course_image' ), 30, 1 );
74
		// add the course image to the left of the content.
75
		add_action( 'lsx_sensei_course_content_inside_before', array( $woothemes_sensei->course, 'course_image' ), 30, 1 );
76
77
		add_filter( 'attach_shortcode_hooks', 'lsx_attach_shortcode_hooks', 10, 1 );
78
79
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
80
81
	/**
82
	 * Gets the current courses thumbnail for content-course.php
83
	 *
84
	 * @return void
85
	 */
86
	public function get_course_thumbnail() {
87
		?>
88
		<div class="course-thumbnail">
89
			<?php do_action( 'lsx_sensei_course_content_inside_before', get_the_ID() ); ?>
90
		</div>
91
		<?php
92
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
93
94
	/**
95
	 * <div class="course-body"> for content-course.php
96
	 *
97
	 * @return void
98
	 */
99
	public function course_body_div_open() {
100
		global $post, $current_user;
101
		$is_user_taking_course    = Sensei_Utils::has_started_course( $post->ID, $current_user->ID );
0 ignored issues
show
Bug introduced by
The type Sensei_Utils was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
102
		$user_taking_course_class = '';
103
		if ( ! empty( $is_user_taking_course ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
104
			$user_taking_course_class = 'currently-in-course';
105
		}
106
		?>
107
		<div class="course-body <?php echo esc_html( $user_taking_course_class ); ?>">
108
		<?php
109
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
110
111
	/**
112
	 * The closing </div> for <div class="course-body"> content-course.php
113
	 *
114
	 * @return void
115
	 */
116
	public function course_body_div_close() {
117
		?>
118
		</div>
119
		<?php
120
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
121
122
	/**
123
	 * <div class="course-details-info"> for content-course.php, just for the info after the meta
124
	 *
125
	 * @return void
126
	 */
127
	public function course_body_div_results_open() {
128
		?>
129
		<div class="course-details-info">
130
		<?php
131
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
132
133
	/**
134
	 * The closing </div> for <div class="course-details-info"> content-course.php, just for the info after the meta
135
	 *
136
	 * @return void
137
	 */
138
	public function course_body_div_results_close() {
139
		?>
140
		</div>
141
		<?php
142
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
143
144
	/**
145
	 * Display the course price on a single course.
146
	 *
147
	 * @return void
148
	 */
149
	public function display_course_amount() {
150
		global $post, $current_user;
151
		$is_user_taking_course   = Sensei_Course::is_user_enrolled( $post->ID, $current_user->ID );
0 ignored issues
show
Bug introduced by
The type Sensei_Course was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
152
		$is_user_starting_course = Sensei_Utils::has_started_course( $post->ID, $current_user->ID );
153
		$wc_post_id              = absint( get_post_meta( $post->ID, '_course_woocommerce_product', true ) );
154
		$course_purchasable      = '';
155
		if ( class_exists( 'Sensei_WC' ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
156
			$course_purchasable = Sensei_WC::is_course_purchasable( $post->ID );
0 ignored issues
show
Bug introduced by
The type Sensei_WC was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
157
			$currency           = get_woocommerce_currency_symbol();
0 ignored issues
show
Bug introduced by
The function get_woocommerce_currency_symbol was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

157
			$currency           = /** @scrutinizer ignore-call */ get_woocommerce_currency_symbol();
Loading history...
158
			$product            = new WC_Product( $wc_post_id );
0 ignored issues
show
Bug introduced by
The type WC_Product was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
159
			if ( ( ! empty( $product->get_price() ) ) && ( ( ! $is_user_taking_course ) || ( ! $is_user_starting_course ) ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
160
				echo '<span class="course-product-price price"><span>' . esc_html( $currency ) . ' </span>' . sprintf( '%0.2f', esc_html( $product->get_price() ) ) . '</span>';
161
			} elseif ( ( '' === $product->get_price() || 0 == $product->get_price() ) && $course_purchasable && ( ( ! $is_user_taking_course ) || ( ! $is_user_starting_course ) ) ) {
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces after opening bracket; 1 found
Loading history...
introduced by
Found: ==. Use strict comparisons (=== or !==).
Loading history...
Coding Style introduced by
Expected 0 spaces before closing bracket; 1 found
Loading history...
162
				echo '<span class="course-product-price price">' . wp_kses_post( 'Free!', 'lsx' ) . '</span>';
0 ignored issues
show
Unused Code introduced by
The call to wp_kses_post() has too many arguments starting with 'lsx'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

162
				echo '<span class="course-product-price price">' . /** @scrutinizer ignore-call */ wp_kses_post( 'Free!', 'lsx' ) . '</span>';

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
163
			}
164
		}
165
	}
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
166
167
} // End Class
168
new LSX_Sensei_Course();
169