Issues (2187)

includes/helpers.php (60 issues)

1
<?php
2
/**
3
 * Helper functions
4
 *
5
 * @package   lsx_wetu_importer
6
 * @author    LightSpeed
7
 * @license   GPL-2.0+
8
 * @link
9
 * @copyright 2019 LightSpeed
10
 **/
11
12
/**
13
 * Gets the settings
14
 *
15
 * @return array
16
 */
17
function lsx_wetu_get_options() {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
18
	$options = get_option( 'lsx_wetu_importer_settings', array() );
19
	if ( empty( $options ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
20
		// Check for any previous options.
21
		$temp_options = get_option( '_lsx-to_settings', false );
22
		if ( false !== $temp_options && isset( $temp_options['lsx-wetu-importer'] ) && ! empty( $temp_options['lsx-wetu-importer'] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
23
			$options = $temp_options['lsx-wetu-importer'];
24
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
25
		if ( false !== $temp_options && isset( $temp_options['api']['wetu_api_key'] ) && '' !== $temp_options['api']['wetu_api_key'] ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
26
			$options['api_key'] = $temp_options['api']['wetu_api_key'];
27
		}
28
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
29
	return $options;
30
}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
31
32
/**
33
 * Get the post count.
34
 *
35
 * @param string $post_type
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
36
 * @param string $post_status
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
37
 * @return void
0 ignored issues
show
Function return type is void, but function contains return statement
Loading history...
38
 */
39
function lsx_wetu_get_post_count( $post_type = '', $post_status = '' ) {
40
	global $wpdb;
41
	$count = '0';
42
	if ( '' !== $post_type && '' !== $post_status ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
43
		$result = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(`ID`) FROM $wpdb->posts WHERE `post_status` = '%s' AND `post_type` = '%s'", array( trim( $post_status ), $post_type ) ) );
0 ignored issues
show
Usage of a direct database call is discouraged.
Loading history...
Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete().
Loading history...
Simple placeholders should not be quoted in the query string in $wpdb->prepare(). Found: '%s'.
Loading history...
44
		if ( false !== $result && '' !== $result ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
45
			if ( 'tour' === $post_type ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
46
				$wetu_tours = get_transient( 'lsx_ti_tours' );
47
				if ( false !== $wetu_tours ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
48
					$results = $wpdb->get_results( $wpdb->prepare( "SELECT `ID` FROM $wpdb->posts WHERE `post_status` = '%s' AND `post_type` = '%s'", array( trim( $post_status ), $post_type ) ) );
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 7 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...
Usage of a direct database call is discouraged.
Loading history...
Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete().
Loading history...
Simple placeholders should not be quoted in the query string in $wpdb->prepare(). Found: '%s'.
Loading history...
49
					$result_count = 0;
0 ignored issues
show
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...
50
					$tour_wetu_ids = array();
51
					foreach ( $wetu_tours as $wetu_tour ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
52
						$tour_wetu_ids[] = $wetu_tour['identifier'];
53
					}
54
55
					if ( ! empty( $results ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
56
						foreach ( $results as $tour ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
57
							$current_wetu_id = get_post_meta( $tour->ID, 'lsx_wetu_id', true );
58
							if ( in_array( $current_wetu_id, $tour_wetu_ids ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Not using strict comparison for in_array; supply true for third argument.
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
59
								$result_count++;
60
							}
61
						}
62
					}
0 ignored issues
show
No blank line found after control structure
Loading history...
63
					$result = $result_count;
64
				} else {
65
					$result = 0;
66
				}
67
			}
0 ignored issues
show
No blank line found after control structure
Loading history...
68
			$count = $result;
69
		}
70
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
71
	return $count;
72
}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
73
74
/**
75
 * Returns the wetu queue count.
76
 *
77
 * @param string $post_type
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
78
 * @return void
0 ignored issues
show
Function return type is void, but function contains return statement
Loading history...
79
 */
80
function lsx_wetu_get_queue_count( $post_type = '' ) {
81
	$count = '0';
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 10 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...
82
	$queued_imports = get_option( 'lsx_wetu_importer_que', array() );
83
	if ( isset( $queued_imports[ $post_type ] ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
84
		$count = count( $queued_imports[ $post_type ] );
85
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
86
	return $count;
87
}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
Expected 2 blank lines after function; 1 found
Loading history...
88
89
/**
90
 * Returns the wetu tour count.
91
 *
92
 * @param string $post_type
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
93
 * @return void
0 ignored issues
show
Function return type is void, but function contains return statement
Loading history...
94
 */
95
function lsx_wetu_get_tour_count( $post_type = '' ) {
96
	$count = '0';
0 ignored issues
show
Equals sign not aligned with surrounding assignments; expected 6 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...
97
	$wetu_tours = get_transient( 'lsx_ti_tours', array() );
0 ignored issues
show
The call to get_transient() has too many arguments starting with array(). ( Ignorable by Annotation )

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

97
	$wetu_tours = /** @scrutinizer ignore-call */ get_transient( 'lsx_ti_tours', array() );

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...
98
	if ( ! empty( $wetu_tours ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
99
		$count = count( $wetu_tours );
100
	}
0 ignored issues
show
No blank line found after control structure
Loading history...
101
	return $count;
102
}
0 ignored issues
show
Expected 1 blank line before closing function brace; 0 found
Loading history...
103