Conditions | 1 |
Paths | 1 |
Total Lines | 112 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
30 | protected function __construct($timezone) |
||
31 | { |
||
32 | require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
||
33 | $this->singular_item = __('Price', 'event_espresso'); |
||
34 | $this->plural_item = __('Prices', 'event_espresso'); |
||
35 | |||
36 | $this->_tables = array( |
||
37 | 'Price' => new EE_Primary_Table('esp_price', 'PRC_ID'), |
||
38 | ); |
||
39 | $this->_fields = array( |
||
40 | 'Price' => array( |
||
41 | 'PRC_ID' => new EE_Primary_Key_Int_Field( |
||
42 | 'PRC_ID', |
||
43 | 'Price ID' |
||
44 | ), |
||
45 | 'PRT_ID' => new EE_Foreign_Key_Int_Field( |
||
46 | 'PRT_ID', |
||
47 | esc_html__('Price type Id', 'event_espresso'), |
||
48 | false, |
||
49 | null, |
||
50 | 'Price_Type' |
||
51 | ), |
||
52 | 'PRC_amount' => new EE_Money_Field( |
||
53 | 'PRC_amount', |
||
54 | esc_html__('Price Amount', 'event_espresso'), |
||
55 | false, |
||
56 | 0 |
||
57 | ), |
||
58 | 'PRC_name' => new EE_Plain_Text_Field( |
||
59 | 'PRC_name', |
||
60 | esc_html__('Name of Price', 'event_espresso'), |
||
61 | false, |
||
62 | '' |
||
63 | ), |
||
64 | 'PRC_desc' => new EE_Post_Content_Field( |
||
65 | 'PRC_desc', |
||
66 | esc_html__('Price Description', 'event_espresso'), |
||
67 | false, |
||
68 | '' |
||
69 | ), |
||
70 | 'PRC_is_default' => new EE_Boolean_Field( |
||
71 | 'PRC_is_default', |
||
72 | esc_html__('Flag indicating whether price is a default price', 'event_espresso'), |
||
73 | false, |
||
74 | false |
||
75 | ), |
||
76 | 'PRC_overrides' => new EE_Integer_Field( |
||
77 | 'PRC_overrides', |
||
78 | esc_html__( |
||
79 | 'Price ID for a global Price that will be overridden by this Price ( for replacing default prices )', |
||
80 | 'event_espresso' |
||
81 | ), |
||
82 | true, |
||
83 | 0 |
||
84 | ), |
||
85 | 'PRC_order' => new EE_Integer_Field( |
||
86 | 'PRC_order', |
||
87 | esc_html__( |
||
88 | 'Order of Application of Price (lower numbers apply first?)', |
||
89 | 'event_espresso' |
||
90 | ), |
||
91 | false, |
||
92 | 1 |
||
93 | ), |
||
94 | 'PRC_deleted' => new EE_Trashed_Flag_Field( |
||
95 | 'PRC_deleted', |
||
96 | esc_html__('Flag Indicating if this has been deleted or not', 'event_espresso'), |
||
97 | false, |
||
98 | false |
||
99 | ), |
||
100 | 'PRC_parent' => new EE_Integer_Field( |
||
101 | 'PRC_parent', |
||
102 | esc_html__('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), |
||
103 | true, |
||
104 | 0 |
||
105 | ), |
||
106 | 'PRC_wp_user' => new EE_WP_User_Field( |
||
107 | 'PRC_wp_user', |
||
108 | esc_html__('Price Creator ID', 'event_espresso'), |
||
109 | false |
||
110 | ), |
||
111 | ), |
||
112 | ); |
||
113 | $this->_model_relations = array( |
||
114 | 'Ticket' => new EE_HABTM_Relation('Ticket_Price'), |
||
115 | 'Price_Type' => new EE_Belongs_To_Relation(), |
||
116 | 'WP_User' => new EE_Belongs_To_Relation(), |
||
117 | ); |
||
118 | // this model is generally available for reading |
||
119 | $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
||
120 | new EE_Restriction_Generator_Default_Public( |
||
121 | 'PRC_is_default', |
||
122 | 'Ticket.Datetime.Event' |
||
123 | ); |
||
124 | // account for default tickets in the caps |
||
125 | $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
||
126 | new EE_Restriction_Generator_Default_Protected( |
||
127 | 'PRC_is_default', |
||
128 | 'Ticket.Datetime.Event' |
||
129 | ); |
||
130 | $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
||
131 | new EE_Restriction_Generator_Default_Protected( |
||
132 | 'PRC_is_default', |
||
133 | 'Ticket.Datetime.Event' |
||
134 | ); |
||
135 | $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
||
136 | new EE_Restriction_Generator_Default_Protected( |
||
137 | 'PRC_is_default', |
||
138 | 'Ticket.Datetime.Event' |
||
139 | ); |
||
140 | parent::__construct($timezone); |
||
141 | } |
||
142 | |||
346 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.