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 EEH_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 EEH_Line_Item, and based on these observations, apply Extract Interface, too.
1 | <?php if (!defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
||
20 | class EEH_Line_Item { |
||
21 | |||
22 | //other functions: cancel ticket purchase |
||
23 | //delete ticket purchase |
||
24 | //add promotion |
||
25 | /** |
||
26 | * Adds a simple item ( unrelated to any other model object) to the total line item |
||
27 | * in the correct spot in the line item tree (also verifying it doesn't add a duplicate based on the LIN_code) |
||
28 | * beneath the pre-tax-total (alongside event subtotals). |
||
29 | * Automatically re-calculates the line item totals and updates the related transaction. But |
||
30 | * DOES NOT automatically upgrade the transaction's registrations' final prices (which |
||
31 | * should probably change because of this). |
||
32 | * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
||
33 | * after using this, to keep the registration final prices in-sync with the transaction's total. |
||
34 | * @param EE_Line_Item $parent_line_item |
||
35 | * @param string $name |
||
36 | * @param float $unit_price |
||
37 | * @param string $description |
||
38 | * @param int $quantity |
||
39 | * @param boolean $taxable |
||
40 | * @param boolean $code if set to a value, ensures there is only one line item with that code |
||
41 | * @return boolean success |
||
42 | */ |
||
43 | public static function add_unrelated_item( EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL ){ |
||
64 | |||
65 | |||
66 | |||
67 | /** |
||
68 | * Adds a simple item ( unrelated to any other model object) to the total line item, |
||
69 | * in the correct spot in the line item tree. Automatically |
||
70 | * re-calculates the line item totals and updates the related transaction. But |
||
71 | * DOES NOT automatically upgrade the transaction's registrations' final prices (which |
||
72 | * should probably change because of this). |
||
73 | * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
||
74 | * after using this, to keep the registration final prices in-sync with the transaction's total. |
||
75 | * |
||
76 | * @param EE_Line_Item $parent_line_item |
||
77 | * @param string $name |
||
78 | * @param float $percentage_amount |
||
79 | * @param string $description |
||
80 | * @param boolean $taxable |
||
81 | * @return boolean success |
||
82 | */ |
||
83 | public static function add_percentage_based_item( EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE ){ |
||
101 | |||
102 | |||
103 | |||
104 | /** |
||
105 | * Returns the new line item created by adding a purchase of the ticket |
||
106 | * ensures that ticket line item is saved, and that cart total has been recalculated. |
||
107 | * If this ticket has already been purchased, just increments its count. |
||
108 | * Automatically re-calculates the line item totals and updates the related transaction. But |
||
109 | * DOES NOT automatically upgrade the transaction's registrations' final prices (which |
||
110 | * should probably change because of this). |
||
111 | * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
||
112 | * after using this, to keep the registration final prices in-sync with the transaction's total. |
||
113 | * |
||
114 | * @param EE_Line_Item $total_line_item grand total line item of type EEM_Line_Item::type_total |
||
115 | * @param EE_Ticket $ticket |
||
116 | * @param int $qty |
||
117 | * @return \EE_Line_Item |
||
118 | * @throws \EE_Error |
||
119 | */ |
||
120 | public static function add_ticket_purchase( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ){ |
||
133 | |||
134 | |||
135 | |||
136 | /** |
||
137 | * Returns the new line item created by adding a purchase of the ticket |
||
138 | * @param \EE_Line_Item $total_line_item |
||
139 | * @param EE_Ticket $ticket |
||
140 | * @param int $qty |
||
141 | * @return \EE_Line_Item |
||
142 | * @throws \EE_Error |
||
143 | */ |
||
144 | public static function increment_ticket_qty_if_already_in_cart( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
||
161 | |||
162 | /** |
||
163 | * Increments the line item and all its children's quantity by $qty (but percent line items are unaffected). |
||
164 | * Does NOT save or recalculate other line items totals |
||
165 | * @param EE_Line_Item $line_item |
||
166 | * @param int $qty |
||
167 | * @return void |
||
168 | */ |
||
169 | public static function increment_quantity( EE_Line_Item $line_item, $qty = 1 ) { |
||
181 | |||
182 | /** |
||
183 | * Updates the line item and its children's quantities to the specified number. |
||
184 | * Does NOT save them or recalculate totals. |
||
185 | * @param EE_Line_Item $line_item |
||
186 | * @param int $new_quantity |
||
187 | */ |
||
188 | public static function update_quantity( EE_Line_Item $line_item, $new_quantity ) { |
||
199 | |||
200 | |||
201 | |||
202 | /** |
||
203 | * Returns the new line item created by adding a purchase of the ticket |
||
204 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
||
205 | * @param EE_Ticket $ticket |
||
206 | * @param int $qty |
||
207 | * @return \EE_Line_Item |
||
208 | * @throws \EE_Error |
||
209 | */ |
||
210 | public static function create_ticket_line_item( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
||
273 | |||
274 | |||
275 | |||
276 | /** |
||
277 | * Adds the specified item under the pre-tax-sub-total line item. Automatically |
||
278 | * re-calculates the line item totals and updates the related transaction. But |
||
279 | * DOES NOT automatically upgrade the transaction's registrations' final prices (which |
||
280 | * should probably change because of this). |
||
281 | * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
||
282 | * after using this, to keep the registration final prices in-sync with the transaction's total. |
||
283 | * @param EE_Line_Item $total_line_item |
||
284 | * @param EE_Line_Item $item to be added |
||
285 | * @return boolean |
||
286 | */ |
||
287 | public static function add_item( EE_Line_Item $total_line_item, EE_Line_Item $item ){ |
||
297 | |||
298 | |||
299 | |||
300 | /** |
||
301 | * Gets the line item which contains the subtotal of all the items |
||
302 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
||
303 | * @return \EE_Line_Item |
||
304 | */ |
||
305 | public static function get_pre_tax_subtotal( EE_Line_Item $total_line_item ){ |
||
309 | |||
310 | |||
311 | |||
312 | /** |
||
313 | * Gets the line item for the taxes subtotal |
||
314 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
||
315 | * @return \EE_Line_Item |
||
316 | */ |
||
317 | public static function get_taxes_subtotal( EE_Line_Item $total_line_item ){ |
||
321 | |||
322 | |||
323 | |||
324 | /** |
||
325 | * sets the TXN ID on an EE_Line_Item if passed a valid EE_Transaction object |
||
326 | * @param EE_Line_Item $line_item |
||
327 | * @param EE_Transaction $transaction |
||
328 | * @return void |
||
329 | */ |
||
330 | public static function set_TXN_ID( EE_Line_Item $line_item, $transaction = NULL ){ |
||
338 | |||
339 | |||
340 | |||
341 | /** |
||
342 | * Creates a new default total line item for the transaction, |
||
343 | * and its tickets subtotal and taxes subtotal line items (and adds the |
||
344 | * existing taxes as children of the taxes subtotal line item) |
||
345 | * @param EE_Transaction $transaction |
||
346 | * @return \EE_Line_Item of type total |
||
347 | */ |
||
348 | View Code Duplication | public static function create_total_line_item( $transaction = NULL ){ |
|
364 | |||
365 | |||
366 | |||
367 | /** |
||
368 | * Creates a default items subtotal line item |
||
369 | * @param EE_Line_Item $total_line_item |
||
370 | * @param EE_Transaction $transaction |
||
371 | * @return EE_Line_Item |
||
372 | */ |
||
373 | View Code Duplication | protected static function create_pre_tax_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
388 | |||
389 | |||
390 | |||
391 | /** |
||
392 | * Creates a line item for the taxes subtotal and finds all the tax prices |
||
393 | * and applies taxes to it |
||
394 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
||
395 | * @param EE_Transaction $transaction |
||
396 | * @return EE_Line_Item |
||
397 | */ |
||
398 | View Code Duplication | protected static function create_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
415 | |||
416 | |||
417 | |||
418 | /** |
||
419 | * Creates a default items subtotal line item |
||
420 | * @param EE_Line_Item $pre_tax_line_item |
||
421 | * @param EE_Transaction $transaction |
||
422 | * @param EE_Event $event |
||
423 | * @return EE_Line_Item |
||
424 | */ |
||
425 | public static function create_event_subtotal( EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL ){ |
||
442 | |||
443 | /** |
||
444 | * Gets what the event ticket's code SHOULD be |
||
445 | * @param EE_Event $event |
||
446 | * @return string |
||
447 | */ |
||
448 | public static function get_event_code( $event ) { |
||
451 | |||
452 | /** |
||
453 | * Gets the event name |
||
454 | * @param EE_Event $event |
||
455 | * @return string |
||
456 | */ |
||
457 | public static function get_event_name( $event ) { |
||
460 | |||
461 | /** |
||
462 | * Gets the event excerpt |
||
463 | * @param EE_Event $event |
||
464 | * @return string |
||
465 | */ |
||
466 | public static function get_event_desc( $event ) { |
||
469 | |||
470 | /** |
||
471 | * Given the grand total line item and a ticket, finds the event sub-total |
||
472 | * line item the ticket's purchase should be added onto |
||
473 | * |
||
474 | * @access public |
||
475 | * @param EE_Line_Item $grand_total the grand total line item |
||
476 | * @param EE_Ticket $ticket |
||
477 | * @throws \EE_Error |
||
478 | * @return EE_Line_Item |
||
479 | */ |
||
480 | public static function get_event_line_item_for_ticket( EE_Line_Item $grand_total, EE_Ticket $ticket ) { |
||
491 | |||
492 | /** |
||
493 | * Gets the event line item |
||
494 | * @param EE_Line_Item $grand_total |
||
495 | * @param EE_Event $event |
||
496 | * @return EE_Line_Item for the event subtotal which is a child of $grand_total |
||
497 | */ |
||
498 | public static function get_event_line_item( EE_Line_Item $grand_total, $event ) { |
||
526 | |||
527 | |||
528 | |||
529 | /** |
||
530 | * Creates a default items subtotal line item |
||
531 | * @param EE_Line_Item $event_line_item |
||
532 | * @param EE_Event $event |
||
533 | * @param EE_Transaction $transaction |
||
534 | * @return EE_Line_Item |
||
535 | */ |
||
536 | public static function set_event_subtotal_details( EE_Line_Item $event_line_item, EE_Event $event, $transaction = NULL ){ |
||
545 | |||
546 | |||
547 | |||
548 | /** |
||
549 | * Finds what taxes should apply, adds them as tax line items under the taxes sub-total, |
||
550 | * and recalculates the taxes sub-total and the grand total. Resets the taxes, so |
||
551 | * any old taxes are removed |
||
552 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
||
553 | */ |
||
554 | public static function apply_taxes( EE_Line_Item $total_line_item ){ |
||
590 | |||
591 | |||
592 | |||
593 | /** |
||
594 | * Ensures that taxes have been applied to the order, if not applies them. |
||
595 | * Returns the total amount of tax |
||
596 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
||
597 | * @return float |
||
598 | */ |
||
599 | public static function ensure_taxes_applied( $total_line_item ){ |
||
606 | |||
607 | |||
608 | |||
609 | /** |
||
610 | * Deletes ALL children of the passed line item |
||
611 | * |
||
612 | * @param EE_Line_Item $parent_line_item |
||
613 | * @return bool |
||
614 | */ |
||
615 | public static function delete_all_child_items( EE_Line_Item $parent_line_item ) { |
||
631 | |||
632 | |||
633 | |||
634 | /** |
||
635 | * Deletes the line items as indicated by the line item code(s) provided, |
||
636 | * regardless of where they're found in the line item tree. Automatically |
||
637 | * re-calculates the line item totals and updates the related transaction. But |
||
638 | * DOES NOT automatically upgrade the transaction's registrations' final prices (which |
||
639 | * should probably change because of this). |
||
640 | * You should call EE_Registration_Processor::calculate_reg_final_prices_per_line_item() |
||
641 | * after using this, to keep the registration final prices in-sync with the transaction's total. |
||
642 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
||
643 | * @param array|bool|string $line_item_codes |
||
644 | * @return int number of items successfully removed |
||
645 | */ |
||
646 | public static function delete_items( EE_Line_Item $total_line_item, $line_item_codes = FALSE ) { |
||
671 | |||
672 | |||
673 | |||
674 | /** |
||
675 | * Overwrites the previous tax by clearing out the old taxes, and creates a new |
||
676 | * tax and updates the total line item accordingly |
||
677 | * @param EE_Line_Item $total_line_item |
||
678 | * @param float $amount |
||
679 | * @param string $name |
||
680 | * @param string $description |
||
681 | * @param string $code |
||
682 | * @param boolean $add_to_existing_line_item |
||
683 | * if true, and a duplicate line item with the same code is found, |
||
684 | * $amount will be added onto it; otherwise will simply set the taxes to match $amount |
||
685 | * @return EE_Line_Item the new tax line item created |
||
686 | */ |
||
687 | public static function set_total_tax_to( EE_Line_Item $total_line_item, $amount, $name = NULL, $description = NULL, $code = NULL, $add_to_existing_line_item = false ){ |
||
726 | |||
727 | |||
728 | |||
729 | /** |
||
730 | * Makes all the line items which are children of $line_item taxable (or not). |
||
731 | * Does NOT save the line items |
||
732 | * @param EE_Line_Item $line_item |
||
733 | * @param string $code_substring_for_whitelist if this string is part of the line item's code |
||
734 | * it will be whitelisted (ie, except from becoming taxable) |
||
735 | * @param boolean $taxable |
||
736 | */ |
||
737 | public static function set_line_items_taxable( EE_Line_Item $line_item, $taxable = true, $code_substring_for_whitelist = null ) { |
||
750 | |||
751 | |||
752 | |||
753 | /** |
||
754 | * Gets all descendants that are event subtotals |
||
755 | * |
||
756 | * @uses EEH_Line_Item::get_subtotals_of_object_type() |
||
757 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
||
758 | * @return EE_Line_Item[] |
||
759 | */ |
||
760 | public static function get_event_subtotals( EE_Line_Item $parent_line_item ) { |
||
763 | |||
764 | |||
765 | |||
766 | /** |
||
767 | * Gets all descendants subtotals that match the supplied object type |
||
768 | * |
||
769 | * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
||
770 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
||
771 | * @param string $obj_type |
||
772 | * @return EE_Line_Item[] |
||
773 | */ |
||
774 | public static function get_subtotals_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
||
777 | |||
778 | |||
779 | |||
780 | /** |
||
781 | * Gets all descendants that are tickets |
||
782 | * |
||
783 | * @uses EEH_Line_Item::get_line_items_of_object_type() |
||
784 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
||
785 | * @return EE_Line_Item[] |
||
786 | */ |
||
787 | public static function get_ticket_line_items( EE_Line_Item $parent_line_item ) { |
||
790 | |||
791 | |||
792 | |||
793 | /** |
||
794 | * Gets all descendants subtotals that match the supplied object type |
||
795 | * |
||
796 | * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
||
797 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
||
798 | * @param string $obj_type |
||
799 | * @return EE_Line_Item[] |
||
800 | */ |
||
801 | public static function get_line_items_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
||
804 | |||
805 | |||
806 | |||
807 | /** |
||
808 | * Gets all the descendants (ie, children or children of children etc) that are of the type 'tax' |
||
809 | * @uses EEH_Line_Item::get_descendants_of_type() |
||
810 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
||
811 | * @return EE_Line_Item[] |
||
812 | */ |
||
813 | public static function get_tax_descendants( EE_Line_Item $parent_line_item ) { |
||
816 | |||
817 | |||
818 | |||
819 | /** |
||
820 | * Gets all the real items purchased which are children of this item |
||
821 | * @uses EEH_Line_Item::get_descendants_of_type() |
||
822 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
||
823 | * @return EE_Line_Item[] |
||
824 | */ |
||
825 | public static function get_line_item_descendants( EE_Line_Item $parent_line_item ) { |
||
828 | |||
829 | |||
830 | |||
831 | /** |
||
832 | * Gets all descendants of supplied line item that match the supplied line item type |
||
833 | * |
||
834 | * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
||
835 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
||
836 | * @param string $line_item_type one of the EEM_Line_Item constants |
||
837 | * @return EE_Line_Item[] |
||
838 | */ |
||
839 | public static function get_descendants_of_type( EE_Line_Item $parent_line_item, $line_item_type ) { |
||
842 | |||
843 | |||
844 | |||
845 | /** |
||
846 | * Gets all descendants of supplied line item that match the supplied line item type and possibly the object type as well |
||
847 | * |
||
848 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
||
849 | * @param string $line_item_type one of the EEM_Line_Item constants |
||
850 | * @param string | NULL $obj_type object model class name (minus prefix) or NULL to ignore object type when searching |
||
851 | * @return EE_Line_Item[] |
||
852 | */ |
||
853 | protected static function _get_descendants_by_type_and_object_type( EE_Line_Item $parent_line_item, $line_item_type, $obj_type = NULL ) { |
||
867 | |||
868 | |||
869 | |||
870 | /** |
||
871 | * Gets all descendants subtotals that match the supplied object type |
||
872 | * |
||
873 | * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
||
874 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
||
875 | * @param string $OBJ_type object type (like Event) |
||
876 | * @param array $OBJ_IDs array of OBJ_IDs |
||
877 | * @return EE_Line_Item[] |
||
878 | */ |
||
879 | public static function get_line_items_by_object_type_and_IDs( EE_Line_Item $parent_line_item, $OBJ_type = '', $OBJ_IDs = array() ) { |
||
882 | |||
883 | |||
884 | |||
885 | /** |
||
886 | * Gets all descendants of supplied line item that match the supplied line item type and possibly the object type as well |
||
887 | * |
||
888 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
||
889 | * @param string $OBJ_type object type (like Event) |
||
890 | * @param array $OBJ_IDs array of OBJ_IDs |
||
891 | * @return EE_Line_Item[] |
||
892 | */ |
||
893 | protected static function _get_descendants_by_object_type_and_object_ID( EE_Line_Item $parent_line_item, $OBJ_type, $OBJ_IDs ) { |
||
907 | |||
908 | |||
909 | |||
910 | /** |
||
911 | * Uses a breadth-first-search in order to find the nearest descendant of |
||
912 | * the specified type and returns it, else NULL |
||
913 | * |
||
914 | * @uses EEH_Line_Item::_get_nearest_descendant() |
||
915 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
||
916 | * @param string $type like one of the EEM_Line_Item::type_* |
||
917 | * @return EE_Line_Item |
||
918 | */ |
||
919 | public static function get_nearest_descendant_of_type( EE_Line_Item $parent_line_item, $type ) { |
||
922 | |||
923 | |||
924 | |||
925 | /** |
||
926 | * Uses a breadth-first-search in order to find the nearest descendant having the specified LIN_code and returns it, else NULL |
||
927 | * |
||
928 | * @uses EEH_Line_Item::_get_nearest_descendant() |
||
929 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
||
930 | * @param string $code any value used for LIN_code |
||
931 | * @return EE_Line_Item |
||
932 | */ |
||
933 | public static function get_nearest_descendant_having_code( EE_Line_Item $parent_line_item, $code ) { |
||
936 | |||
937 | |||
938 | |||
939 | /** |
||
940 | * Uses a breadth-first-search in order to find the nearest descendant having the specified LIN_code and returns it, else NULL |
||
941 | * |
||
942 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
||
943 | * @param string $search_field name of EE_Line_Item property |
||
944 | * @param string $value any value stored in $search_field |
||
945 | * @return EE_Line_Item |
||
946 | */ |
||
947 | protected static function _get_nearest_descendant( EE_Line_Item $parent_line_item, $search_field, $value ) { |
||
961 | |||
962 | |||
963 | |||
964 | |||
965 | /** |
||
966 | * Prints out a representation of the line item tree |
||
967 | * @param EE_Line_Item $line_item |
||
968 | * @param int $indentation |
||
969 | * @return void |
||
970 | */ |
||
971 | public static function visualize( EE_Line_Item $line_item, $indentation = 0 ){ |
||
991 | |||
992 | |||
993 | |||
994 | /** |
||
995 | * Calculates the registration's final price, taking into account that they |
||
996 | * need to not only help pay for their OWN ticket, but also any transaction-wide surcharges and taxes, |
||
997 | * and receive a portion of any transaction-wide discounts. |
||
998 | * eg1, if I buy a $1 ticket and brent buys a $9 ticket, and we receive a $5 discount |
||
999 | * then I'll get 1/10 of that $5 discount, which is $0.50, and brent will get |
||
1000 | * 9/10ths of that $5 discount, which is $4.50. So my final price should be $0.50 |
||
1001 | * and brent's final price should be $5.50. |
||
1002 | * |
||
1003 | * In order to do this, we basically need to traverse the line item tree calculating |
||
1004 | * the running totals (just as if we were recalculating the total), but when we identify |
||
1005 | * regular line items, we need to keep track of their share of the grand total. |
||
1006 | * Also, we need to keep track of the TAXABLE total for each ticket purchase, so |
||
1007 | * we can know how to apply taxes to it. (Note: "taxable total" does not equal the "pretax total" |
||
1008 | * when there are non-taxable items; otherwise they would be the same) |
||
1009 | * |
||
1010 | * @param EE_Line_Item $line_item |
||
1011 | * @param array $billable_ticket_quantities array of EE_Ticket IDs and their corresponding quantity that |
||
1012 | * can be included in price calculations at this moment |
||
1013 | * @return array keys are line items for tickets IDs and values are their share of the running total, |
||
1014 | * plus the key 'total', and 'taxable' which also has keys of all the ticket IDs. Eg |
||
1015 | * array( |
||
1016 | * 12 => 4.3 |
||
1017 | * 23 => 8.0 |
||
1018 | * 'total' => 16.6, |
||
1019 | * 'taxable' => array( |
||
1020 | * 12 => 10, |
||
1021 | * 23 => 4 |
||
1022 | * ). |
||
1023 | * So to find which registrations have which final price, we need to find which line item |
||
1024 | * is theirs, which can be done with |
||
1025 | * `EEM_Line_Item::instance()->get_line_item_for_registration( $registration );` |
||
1026 | */ |
||
1027 | public static function calculate_reg_final_prices_per_line_item( EE_Line_Item $line_item, $billable_ticket_quantities = array() ) { |
||
1117 | |||
1118 | |||
1119 | |||
1120 | /** |
||
1121 | * Creates a duplicate of the line item tree, except only includes billable items |
||
1122 | * and the portion of line items attributed to billable things |
||
1123 | * @param EE_Line_Item $line_item |
||
1124 | * @param EE_Registration[] $registrations |
||
1125 | * @return \EE_Line_Item |
||
1126 | */ |
||
1127 | public static function billable_line_item_tree( EE_Line_Item $line_item, $registrations ) { |
||
1140 | |||
1141 | |||
1142 | |||
1143 | /** |
||
1144 | * Creates a new, unsaved line item from $line_item that factors in the |
||
1145 | * number of billable registrations on $registrations. |
||
1146 | * @param EE_Line_Item $line_item |
||
1147 | * @return EE_Line_Item |
||
1148 | * @param EE_Registration[] $registrations |
||
1149 | */ |
||
1150 | public static function billable_line_item( EE_Line_Item $line_item, $registrations ) { |
||
1171 | |||
1172 | |||
1173 | |||
1174 | /** |
||
1175 | * Returns a modified line item tree where all the subtotals which have a total of 0 |
||
1176 | * are removed, and line items with a quantity of 0 |
||
1177 | * |
||
1178 | * @param EE_Line_Item $line_item |null |
||
1179 | * @return \EE_Line_Item|null |
||
1180 | */ |
||
1181 | public static function non_empty_line_items( EE_Line_Item $line_item ) { |
||
1211 | |||
1212 | |||
1213 | |||
1214 | /** |
||
1215 | * Creates a new, unsaved line item, but if it's a ticket line item |
||
1216 | * with a total of 0, or a subtotal of 0, returns null instead |
||
1217 | * @param EE_Line_Item $line_item |
||
1218 | * @return EE_Line_Item |
||
1219 | */ |
||
1220 | public static function non_empty_line_item( EE_Line_Item $line_item ) { |
||
1233 | |||
1234 | |||
1235 | |||
1236 | /**************************************** @DEPRECATED METHODS ****************************************/ |
||
1237 | |||
1238 | |||
1239 | |||
1240 | /** |
||
1241 | * @deprecated |
||
1242 | * @param EE_Line_Item $total_line_item |
||
1243 | * @return \EE_Line_Item |
||
1244 | */ |
||
1245 | public static function get_items_subtotal( EE_Line_Item $total_line_item ){ |
||
1249 | |||
1250 | |||
1251 | |||
1252 | /** |
||
1253 | * @deprecated |
||
1254 | * @param EE_Transaction $transaction |
||
1255 | * @return \EE_Line_Item |
||
1256 | */ |
||
1257 | public static function create_default_total_line_item( $transaction = NULL) { |
||
1261 | |||
1262 | |||
1263 | |||
1264 | /** |
||
1265 | * @deprecated |
||
1266 | * @param EE_Line_Item $total_line_item |
||
1267 | * @param EE_Transaction $transaction |
||
1268 | * @return \EE_Line_Item |
||
1269 | */ |
||
1270 | public static function create_default_tickets_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
||
1274 | |||
1275 | |||
1276 | |||
1277 | /** |
||
1278 | * @deprecated |
||
1279 | * @param EE_Line_Item $total_line_item |
||
1280 | * @param EE_Transaction $transaction |
||
1281 | * @return \EE_Line_Item |
||
1282 | */ |
||
1283 | public static function create_default_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
||
1287 | |||
1288 | |||
1289 | |||
1290 | /** |
||
1291 | * @deprecated |
||
1292 | * @param EE_Line_Item $total_line_item |
||
1293 | * @param EE_Transaction $transaction |
||
1294 | * @return \EE_Line_Item |
||
1295 | */ |
||
1296 | public static function create_default_event_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
||
1300 | |||
1301 | |||
1302 | |||
1303 | } |
||
1304 | // End of file EEH_Line_Item.helper.php |
||
1305 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: