Passed
Push — master ( e51c9a...41921a )
by Chris
04:16
created

LSX_Rest_Helper::check_event_request()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
rs 10
c 2
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style introduced by
This file is missing a doc comment.
Loading history...
2
3
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...
4
	exit;
5
}
6
7
/**
8
 * Holds functions for rest api specific actions.
9
 *
10
 * @author   LightSpeed
11
 * @category Widgets
12
 * @package  LSX
13
 * @return   LSX_Rest_Helper
14
 */
15
class LSX_Rest_Helper {
16
17
	/**
18
	 * Holds class instance
19
	 *
20
	 * @since 1.0.0
21
	 * @var      object
22
	 */
23
	protected static $instance = null;
24
25
	/**
26
	 * Holds the conditional.
27
	 *
28
	 * @var boolean
29
	 */
30
	protected $is_rest_request = false;
31
32
	/**
33
	 * Constructor.
34
	 */
35
	public function __construct() {
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
36
		add_filter( 'tribe_events_views_v2_rest_params', array( $this, 'check_event_request' ), 10, 2 );
37
	}
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; 0 found
Loading history...
38
	/**
39
	 * Return an instance of this class.
40
	 *
41
	 * @since 1.0.0
42
	 * @return    object    A single instance of this class.
43
	 */
44
	public static function get_instance() {
45
		// If the single instance hasn't been set, set it now.
46
		if ( null === 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...
47
			self::$instance = new self;
0 ignored issues
show
introduced by
Parenthesis should always be used when instantiating a new object.
Loading history...
48
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
49
		return self::$instance;
50
	}
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...
51
52
	/**
53
	 * This will set the 'is_rest_request' variable as true if it runs. Tribe has already done the checkes for us.
54
	 *
55
	 * @param array $params
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
56
	 * @param array $request
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
57
	 * @return void
0 ignored issues
show
Coding Style introduced by
Function return type is void, but function contains return statement
Loading history...
58
	 */
59
	public function check_event_request( $params, $request ) {
60
		$this->is_rest_request = true;
61
		return $params;
62
	}
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...
63
64
	/**
65
	 * Determines if the request is an REST API request.
66
	 *
67
	 * @return bool True if it's a REST API request, false otherwise.
68
	 */
69
	public function is_rest_api_request() {
70
		if ( true === $this->is_rest_request ) {
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...
71
			return $this->is_rest_request;
72
		}
73
74
		if ( empty( $_SERVER['REQUEST_URI'] ) ) {
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...
75
			return false;
76
		}
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
77
		$rest_prefix         = trailingslashit( rest_get_url_prefix() );
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 9 spaces

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...
78
		$this->is_rest_request = ( false !== strpos( $_SERVER['REQUEST_URI'], $rest_prefix ) );
0 ignored issues
show
introduced by
$_SERVER data not unslashed before sanitization. Use wp_unslash() or similar
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_SERVER['REQUEST_URI']
Loading history...
79
		return $this->is_rest_request;
80
	}
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; 0 found
Loading history...
81
}
82
$rest_helper = LSX_Rest_Helper::get_instance();
83