Issues (4138)

classes/frontend/class-plan-query.php (40 issues)

1
<?php
0 ignored issues
show
This file is missing a doc comment.
Loading history...
2
namespace lsx_health_plan\classes\frontend;
3
4
/**
5
 * Holds the functionality to check and control your status with the current plan.
6
 *
7
 * @package lsx-health-plan
8
 */
9
class Plan_Query {
10
11
	/**
12
	 * Holds class instance
13
	 *
14
	 * @since 1.0.0
15
	 *
16
	 * @var      object \lsx_health_plan\classes\frontend\Plan_Query()
17
	 */
18
	protected static $instance = null;
19
20
	/**
21
	 * Holds the sections for the current plan.
22
	 *
23
	 * @var array
24
	 */
25
	public $sections = array();
26
27
	/**
28
	 * Holds the variable true/false if the current plan has sections or not.
29
	 *
30
	 * @var array
31
	 */
32
	public $has_sections = false;
33
34
	/**
35
	 * Constructor
36
	 */
37
	public function __construct() {
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
38
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
39
40
	/**
41
	 * Return an instance of this class.
42
	 *
43
	 * @since 1.0.0
44
	 *
45
	 * @return    object \lsx_health_plan\classes\frontend\Plan_Query()    A single instance of this class.
46
	 */
47
	public static function get_instance() {
48
		// If the single instance hasn't been set, set it now.
49
		if ( null === self::$instance ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
50
			self::$instance = new self();
51
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
52
		return self::$instance;
53
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
54
55
	/**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$plan_id" missing
Loading history...
56
	 * Undocumented function
57
	 *
58
	 * @return void
0 ignored issues
show
Function return type is void, but function contains return statement
Loading history...
59
	 */
60
	public function query_sections( $plan_id = '' ) {
61
		if ( '' === $plan_id ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
62
			$plan_id = get_the_ID();
63
		}
64
65
		$section_array = get_post_meta( $plan_id, 'plan_sections', true );
66
		if ( ! empty( $section_array ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
67
			$this->has_sections = true;
0 ignored issues
show
Documentation Bug introduced by
It seems like true of type true is incompatible with the declared type array of property $has_sections.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
68
			$this->sections     = $section_array;
0 ignored issues
show
Documentation Bug introduced by
It seems like $section_array can also be of type string. However, the property $sections is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
69
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
70
		return $this->has_sections;
71
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
72
73
	public function get_sections( $group = false ) {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function get_sections()
Loading history...
74
		$sections = $this->sections;
75
		if ( false !== $group ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
76
			$sections = $this->group_sections( $sections );
77
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
78
		return $sections;
79
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
80
81
	public function get_section_count() {
0 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function get_section_count()
Loading history...
82
		return count( $this->sections );
83
	}
0 ignored issues
show
Expected 2 blank lines after function; 1 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
84
85
	/**
86
	 * This will group the sections by their "Group" field.
87
	 *
88
	 * @param  array $sections
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
89
	 * @return array
90
	 */
91
	public function group_sections( $sections = array() ) {
92
		$groups = array();
93
		if ( ! empty( $sections ) ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
94
			foreach ( $sections as $section_key => $section_values ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
95
				$group_key = apply_filters( 'lsx_hp_default_plan_group', __( 'Daily Plan', 'lsx-health-plan' ) );
96
				if ( isset( $section_values['group'] ) && '' !== $section_values['group'] ) {
0 ignored issues
show
Expected 0 spaces after opening bracket; 1 found
Loading history...
Expected 0 spaces before closing bracket; 1 found
Loading history...
97
					$group_key = $section_values['group'];
98
				}
0 ignored issues
show
No blank line found after control structure
Loading history...
99
				$group_key                            = sanitize_title( $group_key );
100
				$groups[ $group_key ][ $section_key ] = $section_values;
101
			}
102
		}
0 ignored issues
show
No blank line found after control structure
Loading history...
103
		return $groups;
104
	}
0 ignored issues
show
Expected 2 blank lines after function; 0 found
Loading history...
Expected 1 blank line before closing function brace; 0 found
Loading history...
105
}
106