1 | <?php |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
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
|
|||
38 | } |
||
0 ignored issues
–
show
|
|||
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
|
|||
50 | self::$instance = new self(); |
||
51 | } |
||
0 ignored issues
–
show
|
|||
52 | return self::$instance; |
||
53 | } |
||
0 ignored issues
–
show
|
|||
54 | |||
55 | /** |
||
0 ignored issues
–
show
|
|||
56 | * Undocumented function |
||
57 | * |
||
58 | * @return void |
||
0 ignored issues
–
show
|
|||
59 | */ |
||
60 | public function query_sections( $plan_id = '' ) { |
||
61 | if ( '' === $plan_id ) { |
||
0 ignored issues
–
show
|
|||
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
|
|||
67 | $this->has_sections = true; |
||
0 ignored issues
–
show
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.. ![]() |
|||
68 | $this->sections = $section_array; |
||
0 ignored issues
–
show
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 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;
}
![]() |
|||
69 | } |
||
0 ignored issues
–
show
|
|||
70 | return $this->has_sections; |
||
71 | } |
||
0 ignored issues
–
show
|
|||
72 | |||
73 | public function get_sections( $group = false ) { |
||
0 ignored issues
–
show
|
|||
74 | $sections = $this->sections; |
||
75 | if ( false !== $group ) { |
||
0 ignored issues
–
show
|
|||
76 | $sections = $this->group_sections( $sections ); |
||
77 | } |
||
0 ignored issues
–
show
|
|||
78 | return $sections; |
||
79 | } |
||
0 ignored issues
–
show
|
|||
80 | |||
81 | public function get_section_count() { |
||
0 ignored issues
–
show
|
|||
82 | return count( $this->sections ); |
||
83 | } |
||
0 ignored issues
–
show
|
|||
84 | |||
85 | /** |
||
86 | * This will group the sections by their "Group" field. |
||
87 | * |
||
88 | * @param array $sections |
||
0 ignored issues
–
show
|
|||
89 | * @return array |
||
90 | */ |
||
91 | public function group_sections( $sections = array() ) { |
||
92 | $groups = array(); |
||
93 | if ( ! empty( $sections ) ) { |
||
0 ignored issues
–
show
|
|||
94 | foreach ( $sections as $section_key => $section_values ) { |
||
0 ignored issues
–
show
|
|||
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
|
|||
97 | $group_key = $section_values['group']; |
||
98 | } |
||
0 ignored issues
–
show
|
|||
99 | $group_key = sanitize_title( $group_key ); |
||
100 | $groups[ $group_key ][ $section_key ] = $section_values; |
||
101 | } |
||
102 | } |
||
0 ignored issues
–
show
|
|||
103 | return $groups; |
||
104 | } |
||
0 ignored issues
–
show
|
|||
105 | } |
||
106 |