Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like EE_Line_Item often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EE_Line_Item, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
18 | class EE_Line_Item extends EE_Base_Class implements EEI_Line_Item |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * for children line items (currently not a normal relation) |
||
23 | * |
||
24 | * @type EE_Line_Item[] |
||
25 | */ |
||
26 | protected $_children = array(); |
||
27 | |||
28 | /** |
||
29 | * for the parent line item |
||
30 | * |
||
31 | * @var EE_Line_Item |
||
32 | */ |
||
33 | protected $_parent; |
||
34 | |||
35 | |||
36 | |||
37 | /** |
||
38 | * |
||
39 | * @param array $props_n_values incoming values |
||
40 | * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
||
41 | * used.) |
||
42 | * @param array $date_formats incoming date_formats in an array where the first value is the |
||
43 | * date_format and the second value is the time format |
||
44 | * @return EE_Line_Item |
||
45 | * @throws EE_Error |
||
46 | */ |
||
47 | View Code Duplication | public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
48 | { |
||
49 | $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
||
50 | return $has_object |
||
51 | ? $has_object |
||
52 | : new self($props_n_values, false, $timezone); |
||
53 | } |
||
54 | |||
55 | |||
56 | |||
57 | /** |
||
58 | * @param array $props_n_values incoming values from the database |
||
59 | * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
||
60 | * the website will be used. |
||
61 | * @return EE_Line_Item |
||
62 | * @throws EE_Error |
||
63 | */ |
||
64 | public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
||
68 | |||
69 | |||
70 | |||
71 | /** |
||
72 | * Adds some defaults if they're not specified |
||
73 | * |
||
74 | * @param array $fieldValues |
||
75 | * @param bool $bydb |
||
76 | * @param string $timezone |
||
77 | * @throws EE_Error |
||
78 | */ |
||
79 | protected function __construct($fieldValues = array(), $bydb = false, $timezone = '') |
||
86 | |||
87 | |||
88 | |||
89 | /** |
||
90 | * Gets ID |
||
91 | * |
||
92 | * @return int |
||
93 | * @throws EE_Error |
||
94 | */ |
||
95 | public function ID() |
||
99 | |||
100 | |||
101 | |||
102 | /** |
||
103 | * Gets TXN_ID |
||
104 | * |
||
105 | * @return int |
||
106 | * @throws EE_Error |
||
107 | */ |
||
108 | public function TXN_ID() |
||
112 | |||
113 | |||
114 | |||
115 | /** |
||
116 | * Sets TXN_ID |
||
117 | * |
||
118 | * @param int $TXN_ID |
||
119 | * @throws EE_Error |
||
120 | */ |
||
121 | public function set_TXN_ID($TXN_ID) |
||
125 | |||
126 | |||
127 | |||
128 | /** |
||
129 | * Gets name |
||
130 | * |
||
131 | * @return string |
||
132 | * @throws EE_Error |
||
133 | */ |
||
134 | public function name() |
||
142 | |||
143 | |||
144 | |||
145 | /** |
||
146 | * Sets name |
||
147 | * |
||
148 | * @param string $name |
||
149 | * @throws EE_Error |
||
150 | */ |
||
151 | public function set_name($name) |
||
155 | |||
156 | |||
157 | |||
158 | /** |
||
159 | * Gets desc |
||
160 | * |
||
161 | * @return string |
||
162 | * @throws EE_Error |
||
163 | */ |
||
164 | public function desc() |
||
168 | |||
169 | |||
170 | |||
171 | /** |
||
172 | * Sets desc |
||
173 | * |
||
174 | * @param string $desc |
||
175 | * @throws EE_Error |
||
176 | */ |
||
177 | public function set_desc($desc) |
||
181 | |||
182 | |||
183 | |||
184 | /** |
||
185 | * Gets quantity |
||
186 | * |
||
187 | * @return int |
||
188 | * @throws EE_Error |
||
189 | */ |
||
190 | public function quantity() |
||
194 | |||
195 | |||
196 | |||
197 | /** |
||
198 | * Sets quantity |
||
199 | * |
||
200 | * @param int $quantity |
||
201 | * @throws EE_Error |
||
202 | */ |
||
203 | public function set_quantity($quantity) |
||
207 | |||
208 | |||
209 | |||
210 | /** |
||
211 | * Gets item_id |
||
212 | * |
||
213 | * @return string |
||
214 | * @throws EE_Error |
||
215 | */ |
||
216 | public function OBJ_ID() |
||
220 | |||
221 | |||
222 | |||
223 | /** |
||
224 | * Sets item_id |
||
225 | * |
||
226 | * @param string $item_id |
||
227 | * @throws EE_Error |
||
228 | */ |
||
229 | public function set_OBJ_ID($item_id) |
||
233 | |||
234 | |||
235 | |||
236 | /** |
||
237 | * Gets item_type |
||
238 | * |
||
239 | * @return string |
||
240 | * @throws EE_Error |
||
241 | */ |
||
242 | public function OBJ_type() |
||
246 | |||
247 | |||
248 | |||
249 | /** |
||
250 | * Gets item_type |
||
251 | * |
||
252 | * @return string |
||
253 | * @throws EE_Error |
||
254 | */ |
||
255 | public function OBJ_type_i18n() |
||
277 | |||
278 | |||
279 | |||
280 | /** |
||
281 | * Sets item_type |
||
282 | * |
||
283 | * @param string $OBJ_type |
||
284 | * @throws EE_Error |
||
285 | */ |
||
286 | public function set_OBJ_type($OBJ_type) |
||
290 | |||
291 | |||
292 | |||
293 | /** |
||
294 | * Gets unit_price |
||
295 | * |
||
296 | * @return float |
||
297 | * @throws EE_Error |
||
298 | */ |
||
299 | public function unit_price() |
||
303 | |||
304 | |||
305 | |||
306 | /** |
||
307 | * Sets unit_price |
||
308 | * |
||
309 | * @param float $unit_price |
||
310 | * @throws EE_Error |
||
311 | */ |
||
312 | public function set_unit_price($unit_price) |
||
316 | |||
317 | |||
318 | |||
319 | /** |
||
320 | * Checks if this item is a percentage modifier or not |
||
321 | * |
||
322 | * @return boolean |
||
323 | * @throws EE_Error |
||
324 | */ |
||
325 | public function is_percent() |
||
351 | |||
352 | |||
353 | |||
354 | /** |
||
355 | * Gets percent (between 100-.001) |
||
356 | * |
||
357 | * @return float |
||
358 | * @throws EE_Error |
||
359 | */ |
||
360 | public function percent() |
||
364 | |||
365 | |||
366 | |||
367 | /** |
||
368 | * Sets percent (between 100-0.01) |
||
369 | * |
||
370 | * @param float $percent |
||
371 | * @throws EE_Error |
||
372 | */ |
||
373 | public function set_percent($percent) |
||
377 | |||
378 | |||
379 | |||
380 | /** |
||
381 | * Gets total |
||
382 | * |
||
383 | * @return float |
||
384 | * @throws EE_Error |
||
385 | */ |
||
386 | public function total() |
||
390 | |||
391 | |||
392 | |||
393 | /** |
||
394 | * Sets total |
||
395 | * |
||
396 | * @param float $total |
||
397 | * @throws EE_Error |
||
398 | */ |
||
399 | public function set_total($total) |
||
403 | |||
404 | |||
405 | |||
406 | /** |
||
407 | * Gets order |
||
408 | * |
||
409 | * @return int |
||
410 | * @throws EE_Error |
||
411 | */ |
||
412 | public function order() |
||
416 | |||
417 | |||
418 | |||
419 | /** |
||
420 | * Sets order |
||
421 | * |
||
422 | * @param int $order |
||
423 | * @throws EE_Error |
||
424 | */ |
||
425 | public function set_order($order) |
||
429 | |||
430 | |||
431 | |||
432 | /** |
||
433 | * Gets parent |
||
434 | * |
||
435 | * @return int |
||
436 | * @throws EE_Error |
||
437 | */ |
||
438 | public function parent_ID() |
||
442 | |||
443 | |||
444 | |||
445 | /** |
||
446 | * Sets parent |
||
447 | * |
||
448 | * @param int $parent |
||
449 | * @throws EE_Error |
||
450 | */ |
||
451 | public function set_parent_ID($parent) |
||
455 | |||
456 | |||
457 | |||
458 | /** |
||
459 | * Gets type |
||
460 | * |
||
461 | * @return string |
||
462 | * @throws EE_Error |
||
463 | */ |
||
464 | public function type() |
||
468 | |||
469 | |||
470 | |||
471 | /** |
||
472 | * Sets type |
||
473 | * |
||
474 | * @param string $type |
||
475 | * @throws EE_Error |
||
476 | */ |
||
477 | public function set_type($type) |
||
481 | |||
482 | |||
483 | |||
484 | /** |
||
485 | * Gets the line item of which this item is a composite. Eg, if this is a subtotal, the parent might be a total\ |
||
486 | * If this line item is saved to the DB, fetches the parent from the DB. However, if this line item isn't in the DB |
||
487 | * it uses its cached reference to its parent line item (which would have been set by `EE_Line_Item::set_parent()` |
||
488 | * or indirectly by `EE_Line_item::add_child_line_item()`) |
||
489 | * |
||
490 | * @return EE_Base_Class|EE_Line_Item |
||
491 | * @throws EE_Error |
||
492 | */ |
||
493 | public function parent() |
||
499 | |||
500 | |||
501 | |||
502 | /** |
||
503 | * Gets ALL the children of this line item (ie, all the parts that contribute towards this total). |
||
504 | * |
||
505 | * @return EE_Base_Class[]|EE_Line_Item[] |
||
506 | * @throws EE_Error |
||
507 | */ |
||
508 | public function children() |
||
523 | |||
524 | |||
525 | |||
526 | /** |
||
527 | * Gets code |
||
528 | * |
||
529 | * @return string |
||
530 | * @throws EE_Error |
||
531 | */ |
||
532 | public function code() |
||
536 | |||
537 | |||
538 | |||
539 | /** |
||
540 | * Sets code |
||
541 | * |
||
542 | * @param string $code |
||
543 | * @throws EE_Error |
||
544 | */ |
||
545 | public function set_code($code) |
||
549 | |||
550 | |||
551 | |||
552 | /** |
||
553 | * Gets is_taxable |
||
554 | * |
||
555 | * @return boolean |
||
556 | * @throws EE_Error |
||
557 | */ |
||
558 | public function is_taxable() |
||
562 | |||
563 | |||
564 | |||
565 | /** |
||
566 | * Sets is_taxable |
||
567 | * |
||
568 | * @param boolean $is_taxable |
||
569 | * @throws EE_Error |
||
570 | */ |
||
571 | public function set_is_taxable($is_taxable) |
||
575 | |||
576 | |||
577 | |||
578 | /** |
||
579 | * Gets the object that this model-joins-to. |
||
580 | * returns one of the model objects that the field OBJ_ID can point to... see the 'OBJ_ID' field on |
||
581 | * EEM_Promotion_Object |
||
582 | * |
||
583 | * Eg, if this line item join model object is for a ticket, this will return the EE_Ticket object |
||
584 | * |
||
585 | * @return EE_Base_Class | NULL |
||
586 | * @throws EE_Error |
||
587 | */ |
||
588 | public function get_object() |
||
595 | |||
596 | |||
597 | |||
598 | /** |
||
599 | * Like EE_Line_Item::get_object(), but can only ever actually return an EE_Ticket. |
||
600 | * (IE, if this line item is for a price or something else, will return NULL) |
||
601 | * |
||
602 | * @param array $query_params |
||
603 | * @return EE_Base_Class|EE_Ticket |
||
604 | * @throws EE_Error |
||
605 | */ |
||
606 | public function ticket($query_params = array()) |
||
613 | |||
614 | |||
615 | |||
616 | /** |
||
617 | * Gets the EE_Datetime that's related to the ticket, IF this is for a ticket |
||
618 | * |
||
619 | * @return EE_Datetime | NULL |
||
620 | * @throws EE_Error |
||
621 | */ |
||
622 | public function get_ticket_datetime() |
||
635 | |||
636 | |||
637 | |||
638 | /** |
||
639 | * Gets the event's name that's related to the ticket, if this is for |
||
640 | * a ticket |
||
641 | * |
||
642 | * @return string |
||
643 | * @throws EE_Error |
||
644 | */ |
||
645 | public function ticket_event_name() |
||
654 | |||
655 | |||
656 | /** |
||
657 | * Gets the event that's related to the ticket, if this line item represents a ticket. |
||
658 | * |
||
659 | * @return EE_Event|null |
||
660 | * @throws EE_Error |
||
661 | */ |
||
662 | public function ticket_event() |
||
674 | |||
675 | |||
676 | |||
677 | /** |
||
678 | * Gets the first datetime for this lien item, assuming it's for a ticket |
||
679 | * |
||
680 | * @param string $date_format |
||
681 | * @param string $time_format |
||
682 | * @return string |
||
683 | * @throws EE_Error |
||
684 | */ |
||
685 | public function ticket_datetime_start($date_format = '', $time_format = '') |
||
694 | |||
695 | |||
696 | |||
697 | /** |
||
698 | * Adds the line item as a child to this line item. If there is another child line |
||
699 | * item with the same LIN_code, it is overwritten by this new one |
||
700 | * |
||
701 | * @param EEI_Line_Item $line_item |
||
702 | * @param bool $set_order |
||
703 | * @return bool success |
||
704 | * @throws EE_Error |
||
705 | */ |
||
706 | public function add_child_line_item(EEI_Line_Item $line_item, $set_order = true) |
||
730 | |||
731 | |||
732 | /** |
||
733 | * Similar to EE_Base_Class::_add_relation_to, except this isn't a normal relation. |
||
734 | * If this line item is saved to the DB, this is just a wrapper for set_parent_ID() and save() |
||
735 | * However, if this line item is NOT saved to the DB, this just caches the parent on |
||
736 | * the EE_Line_Item::_parent property. |
||
737 | * |
||
738 | * @param EE_Line_Item $line_item |
||
739 | * @throws EE_Error |
||
740 | */ |
||
741 | public function set_parent($line_item) |
||
754 | |||
755 | |||
756 | |||
757 | /** |
||
758 | * Gets the child line item as specified by its code. Because this returns an object (by reference) |
||
759 | * you can modify this child line item and the parent (this object) can know about them |
||
760 | * because it also has a reference to that line item |
||
761 | * |
||
762 | * @param string $code |
||
763 | * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
||
764 | * @throws EE_Error |
||
765 | */ |
||
766 | public function get_child_line_item($code) |
||
777 | |||
778 | |||
779 | |||
780 | /** |
||
781 | * Returns how many items are deleted (or, if this item has not been saved ot the DB yet, just how many it HAD |
||
782 | * cached on it) |
||
783 | * |
||
784 | * @return int |
||
785 | * @throws EE_Error |
||
786 | */ |
||
787 | public function delete_children_line_items() |
||
796 | |||
797 | |||
798 | |||
799 | /** |
||
800 | * If this line item has been saved to the DB, deletes its child with LIN_code == $code. If this line |
||
801 | * HAS NOT been saved to the DB, removes the child line item with index $code. |
||
802 | * Also searches through the child's children for a matching line item. However, once a line item has been found |
||
803 | * and deleted, stops searching (so if there are line items with duplicate codes, only the first one found will be |
||
804 | * deleted) |
||
805 | * |
||
806 | * @param string $code |
||
807 | * @param bool $stop_search_once_found |
||
808 | * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to |
||
809 | * the DB yet) |
||
810 | * @throws EE_Error |
||
811 | */ |
||
812 | public function delete_child_line_item($code, $stop_search_once_found = true) |
||
834 | |||
835 | |||
836 | /** |
||
837 | * If this line item is in the database, is of the type subtotal, and |
||
838 | * has no children, why do we have it? It should be deleted so this function |
||
839 | * does that |
||
840 | * |
||
841 | * @return boolean |
||
842 | * @throws EE_Error |
||
843 | */ |
||
844 | public function delete_if_childless_subtotal() |
||
851 | |||
852 | |||
853 | |||
854 | /** |
||
855 | * Creates a code and returns a string. doesn't assign the code to this model object |
||
856 | * |
||
857 | * @return string |
||
858 | * @throws EE_Error |
||
859 | */ |
||
860 | public function generate_code() |
||
865 | |||
866 | |||
867 | |||
868 | /** |
||
869 | * @return bool |
||
870 | * @throws EE_Error |
||
871 | */ |
||
872 | public function is_tax() |
||
876 | |||
877 | |||
878 | |||
879 | /** |
||
880 | * @return bool |
||
881 | * @throws EE_Error |
||
882 | */ |
||
883 | public function is_tax_sub_total() |
||
887 | |||
888 | |||
889 | |||
890 | /** |
||
891 | * @return bool |
||
892 | * @throws EE_Error |
||
893 | */ |
||
894 | public function is_line_item() |
||
898 | |||
899 | |||
900 | |||
901 | /** |
||
902 | * @return bool |
||
903 | * @throws EE_Error |
||
904 | */ |
||
905 | public function is_sub_line_item() |
||
909 | |||
910 | |||
911 | |||
912 | /** |
||
913 | * @return bool |
||
914 | * @throws EE_Error |
||
915 | */ |
||
916 | public function is_sub_total() |
||
920 | |||
921 | |||
922 | |||
923 | /** |
||
924 | * Whether or not this line item is a cancellation line item |
||
925 | * |
||
926 | * @return boolean |
||
927 | * @throws EE_Error |
||
928 | */ |
||
929 | public function is_cancellation() |
||
933 | |||
934 | |||
935 | |||
936 | /** |
||
937 | * @return bool |
||
938 | * @throws EE_Error |
||
939 | */ |
||
940 | public function is_total() |
||
944 | |||
945 | |||
946 | |||
947 | /** |
||
948 | * @return bool |
||
949 | * @throws EE_Error |
||
950 | */ |
||
951 | public function is_cancelled() |
||
955 | |||
956 | |||
957 | |||
958 | /** |
||
959 | * @return string like '2, 004.00', formatted according to the localized currency |
||
960 | * @throws EE_Error |
||
961 | */ |
||
962 | public function unit_price_no_code() |
||
966 | |||
967 | |||
968 | |||
969 | /** |
||
970 | * @return string like '2, 004.00', formatted according to the localized currency |
||
971 | * @throws EE_Error |
||
972 | */ |
||
973 | public function total_no_code() |
||
977 | |||
978 | |||
979 | |||
980 | /** |
||
981 | * Gets the final total on this item, taking taxes into account. |
||
982 | * Has the side-effect of setting the sub-total as it was just calculated. |
||
983 | * If this is used on a grand-total line item, also updates the transaction's |
||
984 | * TXN_total (provided this line item is allowed to persist, otherwise we don't |
||
985 | * want to change a persistable transaction with info from a non-persistent line item) |
||
986 | * |
||
987 | * @return float |
||
988 | * @throws EE_Error |
||
989 | * @throws InvalidArgumentException |
||
990 | * @throws InvalidInterfaceException |
||
991 | * @throws InvalidDataTypeException |
||
992 | */ |
||
993 | public function recalculate_total_including_taxes() |
||
1017 | |||
1018 | |||
1019 | /** |
||
1020 | * Recursively goes through all the children and recalculates sub-totals EXCEPT for |
||
1021 | * tax-sub-totals (they're a an odd beast). Updates the 'total' on each line item according to either its |
||
1022 | * unit price * quantity or the total of all its children EXCEPT when we're only calculating the taxable total and |
||
1023 | * when this is called on the grand total |
||
1024 | * |
||
1025 | * @return float |
||
1026 | * @throws InvalidArgumentException |
||
1027 | * @throws InvalidInterfaceException |
||
1028 | * @throws InvalidDataTypeException |
||
1029 | * @throws EE_Error |
||
1030 | */ |
||
1031 | public function recalculate_pre_tax_total() |
||
1078 | |||
1079 | |||
1080 | |||
1081 | /** |
||
1082 | * Calculates the pretax total when this line item is a subtotal or total line item. |
||
1083 | * Basically does a sum-then-round approach (ie, any percent line item that are children |
||
1084 | * will calculate their total based on the un-rounded total we're working with so far, and |
||
1085 | * THEN round the result; instead of rounding as we go like with sub-line-items) |
||
1086 | * |
||
1087 | * @param float $calculated_total_so_far |
||
1088 | * @param EE_Line_Item[] $my_children |
||
1089 | * @return float |
||
1090 | * @throws InvalidArgumentException |
||
1091 | * @throws InvalidInterfaceException |
||
1092 | * @throws InvalidDataTypeException |
||
1093 | * @throws EE_Error |
||
1094 | */ |
||
1095 | protected function _recalculate_pretax_total_for_subtotal($calculated_total_so_far, $my_children = null) |
||
1131 | |||
1132 | |||
1133 | |||
1134 | /** |
||
1135 | * Calculates the pretax total for a normal line item, in a round-then-sum approach |
||
1136 | * (where each sub-line-item is applied to the base price for the line item |
||
1137 | * and the result is immediately rounded, rather than summing all the sub-line-items |
||
1138 | * then rounding, like we do when recalculating pretax totals on totals and subtotals). |
||
1139 | * |
||
1140 | * @param float $calculated_total_so_far |
||
1141 | * @param EE_Line_Item[] $my_children |
||
1142 | * @return float |
||
1143 | * @throws InvalidArgumentException |
||
1144 | * @throws InvalidInterfaceException |
||
1145 | * @throws InvalidDataTypeException |
||
1146 | * @throws EE_Error |
||
1147 | */ |
||
1148 | protected function _recalculate_pretax_total_for_line_item($calculated_total_so_far, $my_children = null) |
||
1188 | |||
1189 | |||
1190 | |||
1191 | /** |
||
1192 | * Recalculates the total on each individual tax (based on a recalculation of the pre-tax total), sets |
||
1193 | * the totals on each tax calculated, and returns the final tax total |
||
1194 | * |
||
1195 | * @return float |
||
1196 | * @throws EE_Error |
||
1197 | */ |
||
1198 | public function recalculate_taxes_and_tax_total() |
||
1214 | |||
1215 | |||
1216 | |||
1217 | /** |
||
1218 | * Simply forces all the tax-sub-totals to recalculate. Assumes the taxes have been calculated |
||
1219 | * |
||
1220 | * @return void |
||
1221 | * @throws EE_Error |
||
1222 | */ |
||
1223 | private function _recalculate_tax_sub_total() |
||
1245 | |||
1246 | |||
1247 | |||
1248 | /** |
||
1249 | * Gets the total tax on this line item. Assumes taxes have already been calculated using |
||
1250 | * recalculate_taxes_and_total |
||
1251 | * |
||
1252 | * @return float |
||
1253 | * @throws EE_Error |
||
1254 | */ |
||
1255 | public function get_total_tax() |
||
1266 | |||
1267 | |||
1268 | /** |
||
1269 | * Gets the total for all the items purchased only |
||
1270 | * |
||
1271 | * @return float |
||
1272 | * @throws EE_Error |
||
1273 | */ |
||
1274 | public function get_items_total() |
||
1291 | |||
1292 | |||
1293 | |||
1294 | /** |
||
1295 | * Gets all the descendants (ie, children or children of children etc) that |
||
1296 | * are of the type 'tax' |
||
1297 | * |
||
1298 | * @return EE_Line_Item[] |
||
1299 | */ |
||
1300 | public function tax_descendants() |
||
1304 | |||
1305 | |||
1306 | |||
1307 | /** |
||
1308 | * Gets all the real items purchased which are children of this item |
||
1309 | * |
||
1310 | * @return EE_Line_Item[] |
||
1311 | */ |
||
1312 | public function get_items() |
||
1316 | |||
1317 | |||
1318 | |||
1319 | /** |
||
1320 | * Returns the amount taxable among this line item's children (or if it has no children, |
||
1321 | * how much of it is taxable). Does not recalculate totals or subtotals. |
||
1322 | * If the taxable total is negative, (eg, if none of the tickets were taxable, |
||
1323 | * but there is a "Taxable" discount), returns 0. |
||
1324 | * |
||
1325 | * @return float |
||
1326 | * @throws EE_Error |
||
1327 | */ |
||
1328 | public function taxable_total() |
||
1348 | |||
1349 | |||
1350 | |||
1351 | /** |
||
1352 | * Gets the transaction for this line item |
||
1353 | * |
||
1354 | * @return EE_Base_Class|EE_Transaction |
||
1355 | * @throws EE_Error |
||
1356 | */ |
||
1357 | public function transaction() |
||
1361 | |||
1362 | |||
1363 | |||
1364 | /** |
||
1365 | * Saves this line item to the DB, and recursively saves its descendants. |
||
1366 | * Because there currently is no proper parent-child relation on the model, |
||
1367 | * save_this_and_cached() will NOT save the descendants. |
||
1368 | * Also sets the transaction on this line item and all its descendants before saving |
||
1369 | * |
||
1370 | * @param int $txn_id if none is provided, assumes $this->TXN_ID() |
||
1371 | * @return int count of items saved |
||
1372 | * @throws EE_Error |
||
1373 | */ |
||
1374 | public function save_this_and_descendants_to_txn($txn_id = null) |
||
1393 | |||
1394 | |||
1395 | |||
1396 | /** |
||
1397 | * Saves this line item to the DB, and recursively saves its descendants. |
||
1398 | * |
||
1399 | * @return int count of items saved |
||
1400 | * @throws EE_Error |
||
1401 | */ |
||
1402 | public function save_this_and_descendants() |
||
1417 | |||
1418 | |||
1419 | |||
1420 | /** |
||
1421 | * returns the cancellation line item if this item was cancelled |
||
1422 | * |
||
1423 | * @return EE_Line_Item[] |
||
1424 | * @throws InvalidArgumentException |
||
1425 | * @throws InvalidInterfaceException |
||
1426 | * @throws InvalidDataTypeException |
||
1427 | * @throws ReflectionException |
||
1428 | * @throws EE_Error |
||
1429 | */ |
||
1430 | public function get_cancellations() |
||
1435 | |||
1436 | |||
1437 | |||
1438 | /** |
||
1439 | * If this item has an ID, then this saves it again to update the db |
||
1440 | * |
||
1441 | * @return int count of items saved |
||
1442 | * @throws EE_Error |
||
1443 | */ |
||
1444 | public function maybe_save() |
||
1451 | |||
1452 | |||
1453 | /** |
||
1454 | * clears the cached children and parent from the line item |
||
1455 | * |
||
1456 | * @return void |
||
1457 | */ |
||
1458 | public function clear_related_line_item_cache() |
||
1463 | |||
1464 | |||
1465 | |||
1466 | /** |
||
1467 | * @param bool $raw |
||
1468 | * @return int |
||
1469 | * @throws EE_Error |
||
1470 | */ |
||
1471 | public function timestamp($raw = false) |
||
1477 | |||
1478 | |||
1479 | |||
1480 | |||
1481 | /************************* DEPRECATED *************************/ |
||
1482 | /** |
||
1483 | * @deprecated 4.6.0 |
||
1484 | * @param string $type one of the constants on EEM_Line_Item |
||
1485 | * @return EE_Line_Item[] |
||
1486 | */ |
||
1487 | protected function _get_descendants_of_type($type) |
||
1495 | |||
1496 | |||
1497 | |||
1498 | /** |
||
1499 | * @deprecated 4.6.0 |
||
1500 | * @param string $type like one of the EEM_Line_Item::type_* |
||
1501 | * @return EE_Line_Item |
||
1502 | */ |
||
1503 | public function get_nearest_descendant_of_type($type) |
||
1511 | |||
1512 | |||
1513 | |||
1514 | } |
||
1515 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
integer
values, zero is a special case, in particular the following results might be unexpected: