LSX_Projects   A
last analyzed

Complexity

Total Complexity 35

Size/Duplication

Total Lines 196
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 115
c 1
b 0
f 0
dl 0
loc 196
rs 9.6
wmc 35

4 Methods

Rating   Name   Duplication   Size   Complexity  
A lsx_banner_allowed_taxonomies() 0 3 1
A __construct() 0 5 1
A lsx_banner_allowed_post_types() 0 3 1
F output() 0 166 32
1
<?php
0 ignored issues
show
Coding Style introduced by
This file is missing a doc comment.
Loading history...
2
/**
3
 * LSX Projects Main Class
4
 *
5
 * @package   LSX Projects
6
 * @author    LightSpeed
7
 * @license   GPL3
8
 * @link
9
 * @copyright 2016 LightSpeed
10
 */
11
class LSX_Projects {
12
13
	public $columns, $responsive, $options;
0 ignored issues
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
14
15
	public function __construct() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function __construct()
Loading history...
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
16
		$this->options = projects_get_options();
17
18
		add_filter( 'lsx_banner_allowed_post_types', array( $this, 'lsx_banner_allowed_post_types' ) );
19
		add_filter( 'lsx_banner_allowed_taxonomies', array( $this, 'lsx_banner_allowed_taxonomies' ) );
20
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
21
22
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$post_types" missing
Loading history...
23
	 * Enable project custom post type on LSX Banners.
24
	 */
25
	public function lsx_banner_allowed_post_types( $post_types ) {
26
		$post_types[] = 'project';
27
		return $post_types;
28
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
29
30
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$taxonomies" missing
Loading history...
31
	 * Enable project custom taxonomies on LSX Banners.
32
	 */
33
	public function lsx_banner_allowed_taxonomies( $taxonomies ) {
34
		$taxonomies[] = 'project-group';
35
		return $taxonomies;
36
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
37
38
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$atts" missing
Loading history...
39
	 * Returns the shortcode output markup
40
	 */
41
	public function output( $atts ) {
42
		// @codingStandardsIgnoreLine
43
		extract( shortcode_atts( array(
44
			'columns' => 3,
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 4 space(s) between "'columns'" and double arrow, but found 1.
Loading history...
45
			'orderby' => 'name',
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 4 space(s) between "'orderby'" and double arrow, but found 1.
Loading history...
46
			'order' => 'ASC',
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 6 space(s) between "'order'" and double arrow, but found 1.
Loading history...
47
			'limit' => '-1',
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 6 space(s) between "'limit'" and double arrow, but found 1.
Loading history...
48
			'include' => '',
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 4 space(s) between "'include'" and double arrow, but found 1.
Loading history...
49
			'display' => 'excerpt',
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 4 space(s) between "'display'" and double arrow, but found 1.
Loading history...
50
			'size' => 'lsx-thumbnail-single',
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 7 space(s) between "'size'" and double arrow, but found 1.
Loading history...
51
			'responsive' => 'true',
52
			'show_image' => 'true',
53
			'carousel' => 'true',
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 3 space(s) between "'carousel'" and double arrow, but found 1.
Loading history...
54
			'featured' => 'false',
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 3 space(s) between "'featured'" and double arrow, but found 1.
Loading history...
55
		), $atts ) );
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, each argument should be on a separate line.

For a function calls that spawns multiple lines, the coding style suggests to split arguments to separate lines like this:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
);
Loading history...
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
56
57
		$output = '';
58
59
		if ( 'true' === $responsive || true === $responsive ) {
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...
60
			$responsive = ' img-responsive';
61
		} else {
62
			$responsive = '';
63
		}
64
65
		$this->columns = $columns;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
66
		$this->responsive = $responsive;
67
68
		if ( ! empty( $include ) ) {
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...
69
			$include = explode( ',', $include );
70
71
			$args = array(
72
				'post_type' => 'project',
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 6 space(s) between "'post_type'" and double arrow, but found 1.
Loading history...
73
				'posts_per_page' => $limit,
74
				'post__in' => $include,
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 7 space(s) between "'post__in'" and double arrow, but found 1.
Loading history...
75
				'orderby' => 'post__in',
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 8 space(s) between "'orderby'" and double arrow, but found 1.
Loading history...
76
				'order' => $order,
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 10 space(s) between "'order'" and double arrow, but found 1.
Loading history...
77
			);
78
		} else {
79
			$args = array(
80
				'post_type' => 'project',
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 6 space(s) between "'post_type'" and double arrow, but found 1.
Loading history...
81
				'posts_per_page' => $limit,
82
				'orderby' => $orderby,
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 8 space(s) between "'orderby'" and double arrow, but found 1.
Loading history...
83
				'order' => $order,
0 ignored issues
show
introduced by
Array double arrow not aligned correctly; expected 10 space(s) between "'order'" and double arrow, but found 1.
Loading history...
84
			);
85
86
			if ( 'true' === $featured || true === $featured ) {
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...
87
				$args['meta_key'] = 'lsx_project_featured';
0 ignored issues
show
introduced by
Detected usage of meta_key, possible slow query.
Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
88
				$args['meta_value'] = 1;
0 ignored issues
show
introduced by
Detected usage of meta_value, possible slow query.
Loading history...
89
			}
90
		}
91
92
		$projects = new \WP_Query( $args );
93
94
		if ( $projects->have_posts() ) {
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...
95
			global $post;
96
97
			$count = 0;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
98
			$count_global = 0;
99
100
			if ( 'true' === $carousel || true === $carousel ) {
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...
101
				$output .= "<div id='lsx-projects-slider' class='lsx-projects-shortcode' data-slick='{\"slidesToShow\": $columns, \"slidesToScroll\": $columns }'>";
102
			} else {
103
				$output .= "<div class='lsx-projects-shortcode'><div class='row'>";
104
			}
105
106
			while ( $projects->have_posts() ) {
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...
107
				$projects->the_post();
108
109
				// Count
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
110
				$count++;
111
				$count_global++;
112
113
				// Content
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
114
				if ( 'full' === $display ) {
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...
115
					$content = apply_filters( 'the_content', get_the_content() );
116
					$content = str_replace( ']]>', ']]&gt;', $content );
117
				} elseif ( 'excerpt' === $display ) {
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...
118
					$content = apply_filters( 'the_excerpt', get_the_excerpt() );
119
				}
120
121
				// Image
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
122
				if ( 'true' === $show_image || true === $show_image ) {
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...
123
					if ( is_numeric( $size ) ) {
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...
124
						$thumb_size = array( $size, $size );
125
					} else {
126
						$thumb_size = $size;
127
					}
128
129
					if ( ! empty( get_the_post_thumbnail( $post->ID ) ) ) {
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...
130
						$image = get_the_post_thumbnail( $post->ID, $thumb_size, array(
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Coding Style introduced by
For multi-line function calls, each argument should be on a separate line.

For a function calls that spawns multiple lines, the coding style suggests to split arguments to separate lines like this:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
);
Loading history...
131
							'class' => $responsive,
132
						) );
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
133
					} else {
134
						$image = '';
135
					}
136
137
					if ( empty( $image ) ) {
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...
138
						if ( ! empty( $this->options['display']['projects_placeholder'] ) ) {
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...
139
							$image = '<img class="' . $responsive . '" src="' . $this->options['display']['projects_placeholder'] . '" width="' . $size . '" alt="placeholder" />';
140
						} else {
141
							$image = '';
142
						}
143
					}
144
				} else {
145
					$image = '';
146
				}
147
148
				// Project groups
0 ignored issues
show
Coding Style introduced by
Inline comments must end in full-stops, exclamation marks, or question marks
Loading history...
149
				$groups = '';
150
				$terms = get_the_terms( $post->ID, 'project-group' );
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
151
152
				if ( $terms && ! is_wp_error( $terms ) ) {
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...
153
					$groups = array();
154
155
					foreach ( $terms as $term ) {
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
						$groups[] = $term->name;
157
					}
158
159
					$groups = join( ', ', $groups );
160
				}
161
162
				$project_groups = '' !== $groups ? "<p class='lsx-projects-groups'>$groups</p>" : '';
163
164
				if ( 'true' === $carousel || true === $carousel ) {
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...
165
					$output .= "
166
						<div class='lsx-projects-slot'>
167
							" . ( ! empty( $image ) ? "<a href='" . get_permalink() . "'><figure class='lsx-projects-avatar'>$image</figure></a>" : '' ) . "
0 ignored issues
show
Bug introduced by
Are you sure get_permalink() of type false|string can be used in concatenation? ( Ignorable by Annotation )

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

167
							" . ( ! empty( $image ) ? "<a href='" . /** @scrutinizer ignore-type */ get_permalink() . "'><figure class='lsx-projects-avatar'>$image</figure></a>" : '' ) . "
Loading history...
168
							<h5 class='lsx-projects-title'><a href='" . get_permalink() . "'>" . apply_filters( 'the_title', $post->post_title ) . "</a></h5>
169
							$project_groups
170
							<div class='lsx-projects-content'><a href='" . get_permalink() . "' class='moretag'>" . esc_html__( 'View more', 'lsx-projects' ) . '</a></div>
171
						</div>';
172
				} elseif ( $columns >= 1 && $columns <= 4 ) {
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...
173
					$md_col_width = 12 / $columns;
174
175
					$output .= "
176
						<div class='col-xs-12 col-md-" . $md_col_width . "'>
177
							<div class='lsx-projects-slot'>
178
								" . ( ! empty( $image ) ? "<a href='" . get_permalink() . "'><figure class='lsx-projects-avatar'>$image</figure></a>" : '' ) . "
179
								<h5 class='lsx-projects-title'><a href='" . get_permalink() . "'>" . apply_filters( 'the_title', $post->post_title ) . "</a></h5>
180
								$project_groups
181
								<div class='lsx-projects-content'><a href='" . get_permalink() . "' class='moretag'>" . esc_html__( 'View more', 'lsx-projects' ) . '</a></div>
182
							</div>
183
						</div>';
184
185
					if ( $count == $columns && $projects->post_count > $count_global ) {
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...
186
						$output .= '</div>';
187
						$output .= "<div class='row'>";
188
						$count = 0;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
189
					}
190
				} else {
191
					$output .= "
192
						<p class='bg-warning' style='padding: 20px;'>
193
							" . esc_html__( 'Invalid number of columns set. LSX Projects supports 1 to 4 columns.', 'lsx-projects' ) . '
194
						</p>';
195
				}
196
197
				wp_reset_postdata();
198
			}
199
200
			if ( 'true' !== $carousel && true !== $carousel ) {
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...
201
				$output .= '</div>';
202
			}
203
204
			$output .= '</div>';
205
206
			return $output;
207
		}
208
	}
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
209
210
}
211
212
global $lsx_projects;
213
$lsx_projects = new LSX_Projects();
214