Completed
Branch FET-5580-registration-cancella... (9a8d8b)
by
unknown
113:07 queued 96:44
created
core/db_models/EEM_Base.model.php 3 patches
Doc Comments   +16 added lines, -13 removed lines patch added patch discarded remove patch
@@ -802,7 +802,7 @@  discard block
 block discarded – undo
802 802
 	 * Returns the name of the field's name that points to the WP_User table
803 803
 	 *  on this model (or follows the _model_chain_to_wp_user and uses that model's
804 804
 	 * foreign key to the WP_User table)
805
-	 * @return string|boolean string on success, boolean false when there is no
805
+	 * @return string|false string on success, boolean false when there is no
806 806
 	 * foreign key to the WP_User table
807 807
 	 */
808 808
 	public function wp_user_field_name() {
@@ -897,6 +897,7 @@  discard block
 block discarded – undo
897 897
 	 * If you would like to use these custom selections in WHERE, GROUP_BY, or HAVING clauses, you must instead provide an array.
898 898
 	 * Array keys are the aliases used to refer to this selection, and values are to be numerically-indexed arrays, where 0 is the selection
899 899
 	 * and 1 is the data type. Eg, array('count'=>array('COUNT(REG_ID)','%d'))
900
+	 * @param string $columns_to_select
900 901
 	 * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
901 902
 	 * @throws \EE_Error
902 903
 	 */
@@ -1242,7 +1243,7 @@  discard block
 block discarded – undo
1242 1243
 	 * @param bool   $pretty          Whether to return the pretty formats (true) or not (false).
1243 1244
 	 * @throws EE_Error   If the given field_name is not of the EE_Datetime_Field type.
1244 1245
 	 *
1245
-	 * @return array formats in an array with the date format first, and the time format last.
1246
+	 * @return string[] formats in an array with the date format first, and the time format last.
1246 1247
 	 */
1247 1248
 	public function get_formats_for( $field_name, $pretty = false ) {
1248 1249
 		$field_settings = $this->field_settings_for( $field_name );
@@ -1277,7 +1278,7 @@  discard block
 block discarded – undo
1277 1278
 	 *
1278 1279
 	 * @throws EE_Error   	If the given field_name is not of the EE_Datetime_Field type.
1279 1280
 	 *
1280
-	 * @return int|string  If the given field_name is not of the EE_Datetime_Field type, then an EE_Error
1281
+	 * @return string|null  If the given field_name is not of the EE_Datetime_Field type, then an EE_Error
1281 1282
 	 *                    	     exception is triggered.
1282 1283
 	 */
1283 1284
 	public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) {
@@ -1588,7 +1589,7 @@  discard block
 block discarded – undo
1588 1589
 	 * Wrapper for EEM_Base::delete_permanently()
1589 1590
 	 *
1590 1591
 	 * @param mixed $id
1591
-	 * @return boolean whether the row got deleted or not
1592
+	 * @return integer whether the row got deleted or not
1592 1593
 	 * @throws \EE_Error
1593 1594
 	 */
1594 1595
 	public function delete_permanently_by_ID( $id ) {
@@ -1607,7 +1608,7 @@  discard block
 block discarded – undo
1607 1608
 	 * Wrapper for EEM_Base::delete()
1608 1609
 	 *
1609 1610
 	 * @param mixed $id
1610
-	 * @return boolean whether the row got deleted or not
1611
+	 * @return integer whether the row got deleted or not
1611 1612
 	 * @throws \EE_Error
1612 1613
 	 */
1613 1614
 	public function delete_by_ID( $id ){
@@ -2017,7 +2018,7 @@  discard block
 block discarded – undo
2017 2018
 	/**
2018 2019
 	 * Verifies the EE addons' database is up-to-date and records that we've done it on
2019 2020
 	 * EEM_Base::$_db_verification_level
2020
-	 * @param $wpdb_method
2021
+	 * @param string $wpdb_method
2021 2022
 	 * @param $arguments_to_provide
2022 2023
 	 * @return string
2023 2024
 	 */
@@ -2112,6 +2113,7 @@  discard block
 block discarded – undo
2112 2113
 	 * @return boolean of success
2113 2114
 	 * @throws \EE_Error
2114 2115
 	 * @param array  $where_query  This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM).  Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well.
2116
+	 * @param EE_Base_Class $id_or_obj
2115 2117
 	 */
2116 2118
 	public function remove_relationship_to($id_or_obj,  $other_model_id_or_obj, $relationName, $where_query= array() ){
2117 2119
 		$relation_obj = $this->related_settings_for($relationName);
@@ -2121,7 +2123,7 @@  discard block
 block discarded – undo
2121 2123
 
2122 2124
 
2123 2125
 	/**
2124
-	 * @param mixed           $id_or_obj
2126
+	 * @param EE_Base_Class           $id_or_obj
2125 2127
 	 * @param string          $relationName
2126 2128
 	 * @param array           $where_query_params
2127 2129
 	 * @param EE_Base_Class[] objects to which relations were removed
@@ -2160,7 +2162,7 @@  discard block
 block discarded – undo
2160 2162
 	 * However, if the model objects can't be deleted because of blocking related model objects, then
2161 2163
 	 * they aren't deleted. (Unless the thing that would have been deleted can be soft-deleted, that still happens).
2162 2164
 	 *
2163
-	 * @param EE_Base_Class|int|string $id_or_obj
2165
+	 * @param EE_Base_Class $id_or_obj
2164 2166
 	 * @param string                   $model_name
2165 2167
 	 * @param array                    $query_params
2166 2168
 	 * @return int how many deleted
@@ -2180,7 +2182,7 @@  discard block
 block discarded – undo
2180 2182
 	 * the model objects can't be hard deleted because of blocking related model objects,
2181 2183
 	 * just does a soft-delete on them instead.
2182 2184
 	 *
2183
-	 * @param EE_Base_Class|int|string $id_or_obj
2185
+	 * @param EE_Base_Class $id_or_obj
2184 2186
 	 * @param string                   $model_name
2185 2187
 	 * @param array                    $query_params
2186 2188
 	 * @return int how many deleted
@@ -2229,6 +2231,7 @@  discard block
 block discarded – undo
2229 2231
 	 * @param string $model_name   like 'Event', or 'Registration'
2230 2232
 	 * @param array  $query_params like EEM_Base::get_all's
2231 2233
 	 * @param string $field_to_sum name of field to count by. By default, uses primary key
2234
+	 * @param EE_Base_Class $id_or_obj
2232 2235
 	 * @return float
2233 2236
 	 * @throws \EE_Error
2234 2237
 	 */
@@ -2638,7 +2641,7 @@  discard block
 block discarded – undo
2638 2641
 	/**
2639 2642
 	 * Finds all the fields that correspond to the given table
2640 2643
 	 * @param string $table_alias, array key in EEM_Base::_tables
2641
-	 * @return EE_Model_Field_Base[]
2644
+	 * @return EE_Model_Field_Base
2642 2645
 	 */
2643 2646
 	public function _get_fields_for_table($table_alias){
2644 2647
 		return $this->_fields[$table_alias];
@@ -3901,7 +3904,7 @@  discard block
 block discarded – undo
3901 3904
 	/**
3902 3905
 	 * gets the field object of type 'primary_key' from the fieldsSettings attribute.
3903 3906
 	 * Eg, on EE_Answer that would be ANS_ID field object
3904
-	 * @param $field_obj
3907
+	 * @param EE_Model_Field_Base $field_obj
3905 3908
 	 * @return boolean
3906 3909
 	 */
3907 3910
 	public function is_primary_key_field( $field_obj ){
@@ -3997,7 +4000,7 @@  discard block
 block discarded – undo
3997 4000
 	 * Gets the actual table for the table alias
3998 4001
 	 * @param string $table_alias eg Event, Event_Meta, Registration, Transaction, but maybe
3999 4002
 	 * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works
4000
-	 * @return EE_Table_Base
4003
+	 * @return string
4001 4004
 	 */
4002 4005
 	public function get_table_for_alias($table_alias){
4003 4006
 		$table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias);
@@ -4543,7 +4546,7 @@  discard block
 block discarded – undo
4543 4546
 	}
4544 4547
 	/**
4545 4548
 	 * Read comments for assume_values_already_prepared_by_model_object()
4546
-	 * @return int
4549
+	 * @return boolean
4547 4550
 	 */
4548 4551
 	public function get_assumption_concerning_values_already_prepared_by_model_object(){
4549 4552
 		return $this->_values_already_prepared_by_model_object;
Please login to merge, or discard this patch.
Indentation   +16 added lines, -17 removed lines patch added patch discarded remove patch
@@ -653,11 +653,11 @@  discard block
 block discarded – undo
653 653
 	 * Gets all the EE_Base_Class objects which match the $query_params, by querying the DB.
654 654
 	 *
655 655
 	 * @param array $query_params {
656
-     *	@var array $0 (where) array {
656
+	 *	@var array $0 (where) array {
657 657
 	 *		eg: array('QST_display_text'=>'Are you bob?','QST_admin_text'=>'Determine if user is bob')
658
-			* becomes
658
+	 * becomes
659 659
 	 *		SQL >> "...WHERE QST_display_text = 'Are you bob?' AND QST_admin_text = 'Determine if user is bob'...")
660
-     *		To add WHERE conditions based on related models (and even models-related-to-related-models) prepend the model's name
660
+	 *		To add WHERE conditions based on related models (and even models-related-to-related-models) prepend the model's name
661 661
 	 *		onto the field name. Eg, EEM_Event::instance()->get_all(array(array('Venue.VNU_ID'=>12)));
662 662
 	 *		becomes
663 663
 	 *		SQL >> "SELECT * FROM wp_posts AS Event_CPT
@@ -677,7 +677,7 @@  discard block
 block discarded – undo
677 677
 	 *		SQL >> "...WHERE QST_display_text LIKE '%bob%' AND QST_ID < 34 AND QST_wp_user IN (1,2,7,23)...".
678 678
 	 *        Valid operators so far: =, !=, <, <=, >, >=, LIKE, NOT LIKE, IN (followed by numeric-indexed array),
679 679
 	 *          NOT IN (dido), BETWEEN (followed by an array with exactly 2 date strings), IS NULL, and IS NOT NULL
680
-     *		Values can be a string, int, or float. They can also be arrays IFF the operator is IN.
680
+	 *		Values can be a string, int, or float. They can also be arrays IFF the operator is IN.
681 681
 	 *        Also, values can actually be field names. To indicate the value is a field,
682 682
 	 *          simply provide a third array item (true) to the operator-value array like so:
683 683
 	 *		eg: array( 'DTT_reg_limit' => array('>', 'DTT_sold', TRUE) )
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
 	 *		Note: you can also use related model field names like you would any other field name.
687 687
 	 *		eg: array('Datetime.DTT_reg_limit'=>array('=','Datetime.DTT_sold',TRUE)
688 688
 	 *		could be used if you were querying EEM_Tickets (because Datetime is directly related to tickets)
689
-     *		Also, by default all the where conditions are AND'd together.
689
+	 *		Also, by default all the where conditions are AND'd together.
690 690
 	 *		To override this, add an array key 'OR' (or 'AND') and the array to be OR'd together
691 691
 	 *		eg: array('OR'=>array('TXN_ID' => 23 , 'TXN_timestamp__>' => 345678912))
692 692
 	 *		becomes
@@ -701,17 +701,17 @@  discard block
 block discarded – undo
701 701
 	 *		eg array('OR'=>array('NOT'=>array('TXN_total' => 50, 'TXN_paid'=>23)),AND=>array('TXN_ID'=>1,'STS_ID'=>'TIN')
702 702
 	 *		becomes
703 703
 	 *		SQL >> "...where ! (TXN_total =50 OR TXN_paid =23) AND TXN_ID=1 AND STS_ID='TIN'"
704
-     *		They can be nested indefinitely.
704
+	 *		They can be nested indefinitely.
705 705
 	 *		eg: array('OR'=>array('TXN_total' => 23, 'NOT'=> array( 'TXN_timestamp'=> 345678912, 'AND'=>array('TXN_paid' => 53, 'STS_ID' => 'TIN'))))
706 706
 	 *		becomes
707 707
 	 *		SQL >> "...WHERE TXN_total = 23 OR ! (TXN_timestamp = 345678912 OR (TXN_paid = 53 AND STS_ID = 'TIN'))..."
708
-     *		GOTCHA:
708
+	 *		GOTCHA:
709 709
 	 *		because this is an array, array keys must be unique, making it impossible to place two or more where conditions applying to the same field.
710 710
 	 *		eg: array('PAY_timestamp'=>array('>',$start_date),'PAY_timestamp'=>array('<',$end_date),'PAY_timestamp'=>array('!=',$special_date)),
711 711
 	 *		as PHP enforces that the array keys must be unique, thus removing the first two array entries with key 'PAY_timestamp'.
712 712
 	 *		becomes
713 713
 	 *		SQL >> "PAY_timestamp !=  4234232", ignoring the first two PAY_timestamp conditions).
714
-     *		To overcome this, you can add a '*' character to the end of the field's name, followed by anything.
714
+	 *		To overcome this, you can add a '*' character to the end of the field's name, followed by anything.
715 715
 	 *		These will be removed when generating the SQL string, but allow for the array keys to be unique.
716 716
 	 *		eg: you could rewrite the previous query as:
717 717
 	 *		array('PAY_timestamp'=>array('>',$start_date),'PAY_timestamp*1st'=>array('<',$end_date),'PAY_timestamp*2nd'=>array('!=',$special_date))
@@ -744,7 +744,7 @@  discard block
 block discarded – undo
744 744
 	 *		You will probably only want to do this in hopes of increasing efficiency, as related models which belongs to the current model
745 745
 	 *		(ie, the current model has a foreign key to them, like how Registration belongs to Attendee) can be cached in order
746 746
 	 *		to avoid future queries
747
-     *	@var string $default_where_conditions can be set to 'none', 'this_model_only', 'other_models_only', or 'all'. set this to 'none' to disable all default where conditions. Eg, usually soft-deleted objects are filtered-out
747
+	 *	@var string $default_where_conditions can be set to 'none', 'this_model_only', 'other_models_only', or 'all'. set this to 'none' to disable all default where conditions. Eg, usually soft-deleted objects are filtered-out
748 748
 	 *		if you want to include them, set this query param to 'none'. If you want to ONLY disable THIS model's default where conditions
749 749
 	 *		set it to 'other_models_only'. If you only want this model's default where conditions added to the query, use 'this_model_only'.
750 750
 	 *		If you want to use all default where conditions (default), set to 'all'.
@@ -1014,7 +1014,6 @@  discard block
 block discarded – undo
1014 1014
 	/**
1015 1015
 	 * Gets a single item for this model from the DB, given the $query_params. Only returns a single class, not an array. If no item is found,
1016 1016
 	 * null is returned.
1017
-
1018 1017
 	 *
1019 1018
 *@param array $query_params like EEM_Base's $query_params variable.
1020 1019
 	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class|NULL
@@ -1117,7 +1116,7 @@  discard block
 block discarded – undo
1117 1116
 	 *                                      can indicate just the columns you
1118 1117
 	 *                                      want and a single array indexed by
1119 1118
 	 *                                      the columns will be returned.
1120
- * @return EE_Base_Class|null|array()
1119
+	 * @return EE_Base_Class|null|array()
1121 1120
 	 * @throws EE_Error
1122 1121
 	 */
1123 1122
 	public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
@@ -1765,7 +1764,7 @@  discard block
 block discarded – undo
1765 1764
 				//make sure there's no related objects blocking its deletion (if we're checking)
1766 1765
 				if (
1767 1766
 					$allow_blocking
1768
-				    && $this->delete_is_blocked_by_related_models(
1767
+					&& $this->delete_is_blocked_by_related_models(
1769 1768
 						$delete_object[ $primary_table->get_fully_qualified_pk_column() ]
1770 1769
 					)
1771 1770
 				) {
@@ -1813,8 +1812,8 @@  discard block
 block discarded – undo
1813 1812
 				foreach($fields as $cpk_field){
1814 1813
 					if ( $cpk_field instanceof EE_Model_Field_Base ){
1815 1814
 						$values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column()
1816
-						                                   . "="
1817
-						                                   . $delete_object[ $cpk_field->get_qualified_column() ];
1815
+														   . "="
1816
+														   . $delete_object[ $cpk_field->get_qualified_column() ];
1818 1817
 					}
1819 1818
 				}
1820 1819
 				$ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")";
@@ -2930,8 +2929,8 @@  discard block
 block discarded – undo
2930 2929
 		}
2931 2930
 		//if 'order_by' wasn't set, maybe they are just using 'order' on its own?
2932 2931
 		if ( ! array_key_exists( 'order_by', $query_params )
2933
-		     && array_key_exists( 'order', $query_params )
2934
-		     && ! empty( $query_params['order'] )
2932
+			 && array_key_exists( 'order', $query_params )
2933
+			 && ! empty( $query_params['order'] )
2935 2934
 		) {
2936 2935
 			$pk_field = $this->get_primary_key_field();
2937 2936
 			$order = $this->_extract_order( $query_params['order'] );
@@ -4469,7 +4468,7 @@  discard block
 block discarded – undo
4469 4468
 				$model_object = $this->get_one_by_ID( $base_class_obj_or_id );
4470 4469
 			} else if (
4471 4470
 				$primary_key_field instanceof EE_Primary_Key_String_Field
4472
-			    && is_string( $base_class_obj_or_id )
4471
+				&& is_string( $base_class_obj_or_id )
4473 4472
 			) {
4474 4473
 				// assume its a string representation of the object
4475 4474
 				$model_object = $this->get_one_by_ID( $base_class_obj_or_id );
Please login to merge, or discard this patch.
Spacing   +970 added lines, -970 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  * @since 				EE4
24 24
  *
25 25
  */
26
-abstract class EEM_Base extends EE_Base{
26
+abstract class EEM_Base extends EE_Base {
27 27
 
28 28
 	//admin posty
29 29
 	//basic -> grants access to mine -> if they don't have it, select none
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 	 * Flag indicating whether this model has a primary key or not
244 244
 	 * @var boolean
245 245
 	 */
246
-	protected $_has_primary_key_field=null;
246
+	protected $_has_primary_key_field = null;
247 247
 
248 248
 	/**
249 249
 	 * Whether or not this model is based off a table in WP core only (CPTs should set
@@ -305,19 +305,19 @@  discard block
 block discarded – undo
305 305
 	 * operators that work like 'BETWEEN'.  Typically used for datetime calculations, i.e. "BETWEEN '12-1-2011' AND '12-31-2012'"
306 306
 	 * @var array
307 307
 	 */
308
-	protected $_between_style_operators = array( 'BETWEEN' );
308
+	protected $_between_style_operators = array('BETWEEN');
309 309
 
310 310
 	/**
311 311
 	 * operators that are used for handling NUll and !NULL queries.  Typically used for when checking if a row exists on a join table.
312 312
 	 * @var array
313 313
 	 */
314
-	protected $_null_style_operators = array( 'IS NOT NULL', 'IS NULL');
314
+	protected $_null_style_operators = array('IS NOT NULL', 'IS NULL');
315 315
 
316 316
 	/**
317 317
 	 * Allowed values for $query_params['order'] for ordering in queries
318 318
 	 * @var array
319 319
 	 */
320
-	protected $_allowed_order_values = array('asc','desc','ASC','DESC');
320
+	protected $_allowed_order_values = array('asc', 'desc', 'ASC', 'DESC');
321 321
 
322 322
 	/**
323 323
 	 * When these are keys in a WHERE or HAVING clause, they are handled much differently
@@ -331,13 +331,13 @@  discard block
 block discarded – undo
331 331
 	 * 'where', but 'where' clauses are so common that we thought we'd omit it
332 332
 	 * @var array
333 333
 	 */
334
-	private $_allowed_query_params = array(0, 'limit','order_by','group_by','having','force_join','order','on_join_limit','default_where_conditions', 'caps');
334
+	private $_allowed_query_params = array(0, 'limit', 'order_by', 'group_by', 'having', 'force_join', 'order', 'on_join_limit', 'default_where_conditions', 'caps');
335 335
 
336 336
 	/**
337 337
 	 * All the data types that can be used in $wpdb->prepare statements.
338 338
 	 * @var array
339 339
 	 */
340
-	private $_valid_wpdb_data_types = array('%d','%s','%f');
340
+	private $_valid_wpdb_data_types = array('%d', '%s', '%f');
341 341
 
342 342
 	/**
343 343
 	 * 	EE_Registry Object
@@ -370,17 +370,17 @@  discard block
 block discarded – undo
370 370
 	/**
371 371
 	 * constant used to show EEM_Base has not yet verified the db on this http request
372 372
 	 */
373
-	const db_verified_none 		= 0;
373
+	const db_verified_none = 0;
374 374
 	/**
375 375
 	 * constant used to show EEM_Base has verified the EE core db on this http request,
376 376
 	 * but not the addons' dbs
377 377
 	 */
378
-	const db_verified_core 		= 1;
378
+	const db_verified_core = 1;
379 379
 	/**
380 380
 	 * constant used to show EEM_Base has verified the addons' dbs (and implicitly
381 381
 	 * the EE core db too)
382 382
 	 */
383
-	const db_verified_addons 	= 2;
383
+	const db_verified_addons = 2;
384 384
 
385 385
 	/**
386 386
 	 * indicates whether an EEM_Base child has already re-verified the DB
@@ -411,13 +411,13 @@  discard block
 block discarded – undo
411 411
 	 * @param null $timezone
412 412
 	 * @throws \EE_Error
413 413
 	 */
414
-	protected function __construct( $timezone = NULL ){
414
+	protected function __construct($timezone = NULL) {
415 415
 		// check that the model has not been loaded too soon
416
-		if ( ! did_action( 'AHEE__EE_System__load_espresso_addons' )) {
417
-			throw new EE_Error (
416
+		if ( ! did_action('AHEE__EE_System__load_espresso_addons')) {
417
+			throw new EE_Error(
418 418
 				sprintf(
419
-					__( 'The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso' ),
420
-					get_class( $this )
419
+					__('The %1$s model can not be loaded before the "AHEE__EE_System__load_espresso_addons" hook has been called. This gives other addons a chance to extend this model.', 'event_espresso'),
420
+					get_class($this)
421 421
 				)
422 422
 			);
423 423
 		}
@@ -425,7 +425,7 @@  discard block
 block discarded – undo
425 425
 		/**
426 426
 		 * Set blogid for models to current blog. However we ONLY do this if $_model_query_blog_id is not already set.
427 427
 		 */
428
-		if ( empty( EEM_Base::$_model_query_blog_id ) ) {
428
+		if (empty(EEM_Base::$_model_query_blog_id)) {
429 429
 			EEM_Base::set_model_query_blog_id();
430 430
 		}
431 431
 
@@ -434,11 +434,11 @@  discard block
 block discarded – undo
434 434
 		 * just use EE_Register_Model_Extension
435 435
 		 * @var EE_Table_Base[] $_tables
436 436
 		 */
437
-		$this->_tables = apply_filters( 'FHEE__'.get_class($this).'__construct__tables', $this->_tables );
438
-		foreach($this->_tables as $table_alias => $table_obj){
437
+		$this->_tables = apply_filters('FHEE__'.get_class($this).'__construct__tables', $this->_tables);
438
+		foreach ($this->_tables as $table_alias => $table_obj) {
439 439
 			/** @var $table_obj EE_Table_Base */
440 440
 			$table_obj->_construct_finalize_with_alias($table_alias);
441
-			if( $table_obj instanceof EE_Secondary_Table ){
441
+			if ($table_obj instanceof EE_Secondary_Table) {
442 442
 				/** @var $table_obj EE_Secondary_Table */
443 443
 				$table_obj->_construct_finalize_set_table_to_join_with($this->_get_main_table());
444 444
 			}
@@ -448,54 +448,54 @@  discard block
 block discarded – undo
448 448
 		 * EE_Register_Model_Extension
449 449
 		 * @param EE_Model_Field_Base[] $_fields
450 450
 		 */
451
-		$this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields',$this->_fields);
451
+		$this->_fields = apply_filters('FHEE__'.get_class($this).'__construct__fields', $this->_fields);
452 452
 		$this->_invalidate_field_caches();
453
-		foreach($this->_fields as $table_alias => $fields_for_table){
454
-			if ( ! array_key_exists( $table_alias, $this->_tables )){
455
-				throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s",'event_espresso'),$table_alias,implode(",",$this->_fields)));
453
+		foreach ($this->_fields as $table_alias => $fields_for_table) {
454
+			if ( ! array_key_exists($table_alias, $this->_tables)) {
455
+				throw new EE_Error(sprintf(__("Table alias %s does not exist in EEM_Base child's _tables array. Only tables defined are %s", 'event_espresso'), $table_alias, implode(",", $this->_fields)));
456 456
 			}
457
-			foreach($fields_for_table as $field_name => $field_obj){
457
+			foreach ($fields_for_table as $field_name => $field_obj) {
458 458
 				/** @var $field_obj EE_Model_Field_Base | EE_Primary_Key_Field_Base */
459 459
 				//primary key field base has a slightly different _construct_finalize
460 460
 				/** @var $field_obj EE_Model_Field_Base */
461
-				$field_obj->_construct_finalize( $table_alias, $field_name, $this->get_this_model_name() );
461
+				$field_obj->_construct_finalize($table_alias, $field_name, $this->get_this_model_name());
462 462
 			}
463 463
 		}
464 464
 
465 465
 		// everything is related to Extra_Meta
466
-		if( get_class($this) !== 'EEM_Extra_Meta'){
466
+		if (get_class($this) !== 'EEM_Extra_Meta') {
467 467
 			//make extra meta related to everything, but don't block deleting things just
468 468
 			//because they have related extra meta info. For now just orphan those extra meta
469 469
 			//in the future we should automatically delete them
470
-			$this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation( FALSE );
470
+			$this->_model_relations['Extra_Meta'] = new EE_Has_Many_Any_Relation(FALSE);
471 471
 		}
472 472
 		//and change logs
473
-		if( get_class( $this) !==  'EEM_Change_Log' ) {
474
-			$this->_model_relations[ 'Change_Log' ] = new EE_Has_Many_Any_Relation( FALSE );
473
+		if (get_class($this) !== 'EEM_Change_Log') {
474
+			$this->_model_relations['Change_Log'] = new EE_Has_Many_Any_Relation(FALSE);
475 475
 		}
476 476
 		/**
477 477
 		 * Filters the list of relations on a model. It is best to NOT use this directly and instead just use
478 478
 		 * EE_Register_Model_Extension
479 479
 		 * @param EE_Model_Relation_Base[] $_model_relations
480 480
 		 */
481
-		$this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations',$this->_model_relations);
482
-		foreach($this->_model_relations as $model_name => $relation_obj){
481
+		$this->_model_relations = apply_filters('FHEE__'.get_class($this).'__construct__model_relations', $this->_model_relations);
482
+		foreach ($this->_model_relations as $model_name => $relation_obj) {
483 483
 			/** @var $relation_obj EE_Model_Relation_Base */
484 484
 			$relation_obj->_construct_finalize_set_models($this->get_this_model_name(), $model_name);
485 485
 		}
486
-		foreach($this->_indexes as $index_name => $index_obj){
486
+		foreach ($this->_indexes as $index_name => $index_obj) {
487 487
 			/** @var $index_obj EE_Index */
488 488
 			$index_obj->_construct_finalize($index_name, $this->get_this_model_name());
489 489
 		}
490 490
 
491 491
 		$this->set_timezone($timezone);
492 492
 		//finalize default where condition strategy, or set default
493
-		if( ! $this->_default_where_conditions_strategy){
493
+		if ( ! $this->_default_where_conditions_strategy) {
494 494
 			//nothing was set during child constructor, so set default
495 495
 			$this->_default_where_conditions_strategy = new EE_Default_Where_Conditions();
496 496
 		}
497 497
 		$this->_default_where_conditions_strategy->_finalize_construct($this);
498
-		if( ! $this->_minimum_where_conditions_strategy){
498
+		if ( ! $this->_minimum_where_conditions_strategy) {
499 499
 			//nothing was set during child constructor, so set default
500 500
 			$this->_minimum_where_conditions_strategy = new EE_Default_Where_Conditions();
501 501
 		}
@@ -503,14 +503,14 @@  discard block
 block discarded – undo
503 503
 
504 504
 		//if the cap slug hasn't been set, and we haven't set it to false on purpose
505 505
 		//to indicate to NOT set it, set it to the logical default
506
-		if( $this->_caps_slug === null ) {
507
-			$this->_caps_slug = EEH_Inflector::pluralize_and_lower( $this->get_this_model_name() );
506
+		if ($this->_caps_slug === null) {
507
+			$this->_caps_slug = EEH_Inflector::pluralize_and_lower($this->get_this_model_name());
508 508
 		}
509 509
 		//initialize the standard cap restriction generators if none were specified by the child constructor
510
-		if( $this->_cap_restriction_generators !== false ){
511
-			foreach( $this->cap_contexts_to_cap_action_map() as $cap_context => $action ){
512
-				if( ! isset( $this->_cap_restriction_generators[ $cap_context ] ) ) {
513
-					$this->_cap_restriction_generators[ $cap_context ] = apply_filters(
510
+		if ($this->_cap_restriction_generators !== false) {
511
+			foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) {
512
+				if ( ! isset($this->_cap_restriction_generators[$cap_context])) {
513
+					$this->_cap_restriction_generators[$cap_context] = apply_filters(
514 514
 						'FHEE__EEM_Base___construct__standard_cap_restriction_generator',
515 515
 						new EE_Restriction_Generator_Protected(),
516 516
 						$cap_context,
@@ -520,23 +520,23 @@  discard block
 block discarded – undo
520 520
 			}
521 521
 		}
522 522
 		//if there are cap restriction generators, use them to make the default cap restrictions
523
-		if( $this->_cap_restriction_generators !== false ){
524
-			foreach( $this->_cap_restriction_generators as $context => $generator_object ) {
525
-				if( ! $generator_object ){
523
+		if ($this->_cap_restriction_generators !== false) {
524
+			foreach ($this->_cap_restriction_generators as $context => $generator_object) {
525
+				if ( ! $generator_object) {
526 526
 					continue;
527 527
 				}
528
-				if( ! $generator_object instanceof EE_Restriction_Generator_Base ){
528
+				if ( ! $generator_object instanceof EE_Restriction_Generator_Base) {
529 529
 					throw new EE_Error(
530 530
 						sprintf(
531
-							__( 'Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso' ),
531
+							__('Index "%1$s" in the model %2$s\'s _cap_restriction_generators is not a child of EE_Restriction_Generator_Base. It should be that or NULL.', 'event_espresso'),
532 532
 							$context,
533 533
 							$this->get_this_model_name()
534 534
 						)
535 535
 					);
536 536
 				}
537
-				$action = $this->cap_action_for_context( $context );
538
-				if( ! $generator_object->construction_finalized() ){
539
-					$generator_object->_construct_finalize( $this, $action );
537
+				$action = $this->cap_action_for_context($context);
538
+				if ( ! $generator_object->construction_finalized()) {
539
+					$generator_object->_construct_finalize($this, $action);
540 540
 				}
541 541
 
542 542
 			}
@@ -550,11 +550,11 @@  discard block
 block discarded – undo
550 550
 	 * @param string $context one of EEM_Base::valid_cap_contexts()
551 551
 	 * @return EE_Default_Where_Conditions[]
552 552
 	 */
553
-	protected function _generate_cap_restrictions( $context ){
554
-		if( isset( $this->_cap_restriction_generators[ $context ] ) &&
555
-				$this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base ) {
556
-			return $this->_cap_restriction_generators[ $context ]->generate_restrictions();
557
-		}else{
553
+	protected function _generate_cap_restrictions($context) {
554
+		if (isset($this->_cap_restriction_generators[$context]) &&
555
+				$this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base) {
556
+			return $this->_cap_restriction_generators[$context]->generate_restrictions();
557
+		} else {
558 558
 			return array();
559 559
 		}
560 560
 	}
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
 	 * @param int $blog_id  If provided then will set the blog_id for the models to this id.  If not provided then the
567 567
 	 *                      value for get_current_blog_id() will be used.
568 568
 	 */
569
-	public static function set_model_query_blog_id( $blog_id = 0 ) {
569
+	public static function set_model_query_blog_id($blog_id = 0) {
570 570
 		EEM_Base::$_model_query_blog_id = $blog_id > 0 ? (int) $blog_id : get_current_blog_id();
571 571
 	}
572 572
 
@@ -591,16 +591,16 @@  discard block
 block discarded – undo
591 591
 	 *		@param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
592 592
 	 *		@return static (as in the concrete child class)
593 593
 	 */
594
-	public static function instance( $timezone = NULL ){
594
+	public static function instance($timezone = NULL) {
595 595
 
596 596
 		// check if instance of Espresso_model already exists
597 597
 		if ( ! static::$_instance instanceof static) {
598 598
 			// instantiate Espresso_model
599
-			static::$_instance = new static( $timezone );
599
+			static::$_instance = new static($timezone);
600 600
 		}
601 601
 
602 602
 		//we might have a timezone set, let set_timezone decide what to do with it
603
-		static::$_instance->set_timezone( $timezone );
603
+		static::$_instance->set_timezone($timezone);
604 604
 
605 605
 		// Espresso_model object
606 606
 		return static::$_instance;
@@ -613,11 +613,11 @@  discard block
 block discarded – undo
613 613
 	 * @param null | string $timezone
614 614
 	 * @return static
615 615
 	 */
616
-	public static function reset(  $timezone = NULL ){
617
-		if ( ! is_null( static::$_instance ) ) {
616
+	public static function reset($timezone = NULL) {
617
+		if ( ! is_null(static::$_instance)) {
618 618
 			static::$_instance = null;
619 619
 
620
-			return self::instance( $timezone );
620
+			return self::instance($timezone);
621 621
 		}
622 622
 		return null;
623 623
 	}
@@ -631,19 +631,19 @@  discard block
 block discarded – undo
631 631
 	 * @return array
632 632
 	 * @throws \EE_Error
633 633
 	 */
634
-	 public function status_array( $translated = FALSE ) {
635
-		 if ( ! array_key_exists( 'Status', $this->_model_relations ) ) {
634
+	 public function status_array($translated = FALSE) {
635
+		 if ( ! array_key_exists('Status', $this->_model_relations)) {
636 636
 			 return array();
637 637
 		 }
638 638
 		 $model_name = $this->get_this_model_name();
639
-		 $status_type = str_replace( ' ', '_', strtolower( str_replace( '_', ' ', $model_name ) ) );
640
-		 $stati = EEM_Status::instance()->get_all( array( array( 'STS_type' => $status_type ) ) );
639
+		 $status_type = str_replace(' ', '_', strtolower(str_replace('_', ' ', $model_name)));
640
+		 $stati = EEM_Status::instance()->get_all(array(array('STS_type' => $status_type)));
641 641
 		 $status_array = array();
642
-		 foreach ( $stati as $status ) {
643
-			 $status_array[ $status->ID() ] = $status->get( 'STS_code' );
642
+		 foreach ($stati as $status) {
643
+			 $status_array[$status->ID()] = $status->get('STS_code');
644 644
 		 }
645 645
 		 return $translated
646
-			 ? EEM_Status::instance()->localized_status( $status_array, false, 'sentence' )
646
+			 ? EEM_Status::instance()->localized_status($status_array, false, 'sentence')
647 647
 			 : $status_array;
648 648
 	 }
649 649
 
@@ -776,10 +776,10 @@  discard block
 block discarded – undo
776 776
 	 *		));
777 777
 	 * @throws \EE_Error
778 778
 	 */
779
-	public function get_all($query_params = array()){
780
-		if( isset( $query_params[ 'limit' ] )
781
-			&& ! isset( $query_params[ 'group_by' ] ) ) {
782
-			$query_params[ 'group_by' ] = array_keys( $this->get_combined_primary_key_fields() );
779
+	public function get_all($query_params = array()) {
780
+		if (isset($query_params['limit'])
781
+			&& ! isset($query_params['group_by'])) {
782
+			$query_params['group_by'] = array_keys($this->get_combined_primary_key_fields());
783 783
 		}
784 784
 		return $this->_create_objects($this->_get_all_wpdb_results($query_params, ARRAY_A, NULL));
785 785
 	}
@@ -790,10 +790,10 @@  discard block
 block discarded – undo
790 790
 	 * @param array $query_params @see EEM_Base::get_all()
791 791
 	 * @return array like EEM_Base::get_all
792 792
 	 */
793
-	public function alter_query_params_to_only_include_mine( $query_params = array() ) {
793
+	public function alter_query_params_to_only_include_mine($query_params = array()) {
794 794
 		$wp_user_field_name = $this->wp_user_field_name();
795
-		if( $wp_user_field_name ){
796
-			$query_params[0][ $wp_user_field_name ] = get_current_user_id();
795
+		if ($wp_user_field_name) {
796
+			$query_params[0][$wp_user_field_name] = get_current_user_id();
797 797
 		}
798 798
 		return $query_params;
799 799
 	}
@@ -806,19 +806,19 @@  discard block
 block discarded – undo
806 806
 	 * foreign key to the WP_User table
807 807
 	 */
808 808
 	public function wp_user_field_name() {
809
-		try{
810
-			if( ! empty( $this->_model_chain_to_wp_user ) ) {
811
-				$models_to_follow_to_wp_users = explode( '.', $this->_model_chain_to_wp_user );
812
-				$last_model_name = end( $models_to_follow_to_wp_users );
813
-				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model( $last_model_name );
814
-				$model_chain_to_wp_user = $this->_model_chain_to_wp_user . '.';
815
-			}else{
809
+		try {
810
+			if ( ! empty($this->_model_chain_to_wp_user)) {
811
+				$models_to_follow_to_wp_users = explode('.', $this->_model_chain_to_wp_user);
812
+				$last_model_name = end($models_to_follow_to_wp_users);
813
+				$model_with_fk_to_wp_users = EE_Registry::instance()->load_model($last_model_name);
814
+				$model_chain_to_wp_user = $this->_model_chain_to_wp_user.'.';
815
+			} else {
816 816
 				$model_with_fk_to_wp_users = $this;
817 817
 				$model_chain_to_wp_user = '';
818 818
 			}
819
-			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to( 'WP_User' );
820
-			return $model_chain_to_wp_user . $wp_user_field->get_name();
821
-		}catch( EE_Error $e ) {
819
+			$wp_user_field = $model_with_fk_to_wp_users->get_foreign_key_to('WP_User');
820
+			return $model_chain_to_wp_user.$wp_user_field->get_name();
821
+		} catch (EE_Error $e) {
822 822
 			return false;
823 823
 		}
824 824
 	}
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
 	 * (or transiently-related model)
833 833
 	 * @return string
834 834
 	 */
835
-	public function model_chain_to_wp_user(){
835
+	public function model_chain_to_wp_user() {
836 836
 		return $this->_model_chain_to_wp_user;
837 837
 	}
838 838
 
@@ -844,13 +844,13 @@  discard block
 block discarded – undo
844 844
 	 * @return boolean
845 845
 	 */
846 846
 	public function is_owned() {
847
-		if( $this->model_chain_to_wp_user() ){
847
+		if ($this->model_chain_to_wp_user()) {
848 848
 			return true;
849
-		}else{
850
-			try{
851
-				$this->get_foreign_key_to( 'WP_User' );
849
+		} else {
850
+			try {
851
+				$this->get_foreign_key_to('WP_User');
852 852
 				return true;
853
-			}catch( EE_Error $e ){
853
+			} catch (EE_Error $e) {
854 854
 				return false;
855 855
 			}
856 856
 		}
@@ -872,17 +872,17 @@  discard block
 block discarded – undo
872 872
 	 * @return array | stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
873 873
 	 * @throws \EE_Error
874 874
 	 */
875
-	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
875
+	protected function  _get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
876 876
 		// remember the custom selections, if any, and type cast as array
877 877
 		// (unless $columns_to_select is an object, then just set as an empty array)
878 878
 		// Note: (array) 'some string' === array( 'some string' )
879
-		$this->_custom_selections = ! is_object( $columns_to_select ) ? (array) $columns_to_select : array();
880
-		$model_query_info = $this->_create_model_query_info_carrier( $query_params );
879
+		$this->_custom_selections = ! is_object($columns_to_select) ? (array) $columns_to_select : array();
880
+		$model_query_info = $this->_create_model_query_info_carrier($query_params);
881 881
 		$select_expressions = $columns_to_select !== null
882
-			? $this->_construct_select_from_input( $columns_to_select )
883
-			: $this->_construct_default_select_sql( $model_query_info );
884
-		$SQL = "SELECT $select_expressions " . $this->_construct_2nd_half_of_select_query( $model_query_info );
885
-		return $this->_do_wpdb_query( 'get_results', array( $SQL, $output ) );
882
+			? $this->_construct_select_from_input($columns_to_select)
883
+			: $this->_construct_default_select_sql($model_query_info);
884
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
885
+		return $this->_do_wpdb_query('get_results', array($SQL, $output));
886 886
 	}
887 887
 
888 888
 	/**
@@ -900,7 +900,7 @@  discard block
 block discarded – undo
900 900
 	 * @return array|stdClass[] like results of $wpdb->get_results($sql,OBJECT), (ie, output type is OBJECT)
901 901
 	 * @throws \EE_Error
902 902
 	 */
903
-	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null){
903
+	public function  get_all_wpdb_results($query_params = array(), $output = ARRAY_A, $columns_to_select = null) {
904 904
 		return $this->_get_all_wpdb_results($query_params, $output, $columns_to_select);
905 905
 	}
906 906
 
@@ -912,12 +912,12 @@  discard block
 block discarded – undo
912 912
 	 * @throws EE_Error
913 913
 	 * @return string
914 914
 	 */
915
-	private function _construct_select_from_input($columns_to_select){
916
-		if(is_array($columns_to_select)){
915
+	private function _construct_select_from_input($columns_to_select) {
916
+		if (is_array($columns_to_select)) {
917 917
 			$select_sql_array = array();
918 918
 
919
-			foreach($columns_to_select as $alias => $selection_and_datatype){
920
-				if( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])){
919
+			foreach ($columns_to_select as $alias => $selection_and_datatype) {
920
+				if ( ! is_array($selection_and_datatype) || ! isset($selection_and_datatype[1])) {
921 921
 					throw new EE_Error(
922 922
 						sprintf(
923 923
 							__(
@@ -929,24 +929,24 @@  discard block
 block discarded – undo
929 929
 						)
930 930
 					);
931 931
 				}
932
-				if( ! in_array( $selection_and_datatype[1],$this->_valid_wpdb_data_types)){
932
+				if ( ! in_array($selection_and_datatype[1], $this->_valid_wpdb_data_types)) {
933 933
 					throw new EE_Error(
934 934
 						sprintf(
935 935
 							__(
936 936
 								"Datatype %s (for selection '%s' and alias '%s') is not a valid wpdb datatype (eg %%s)",
937 937
 								"event_espresso"
938 938
 							),
939
-							$selection_and_datatype[ 1 ],
940
-							$selection_and_datatype[ 0 ],
939
+							$selection_and_datatype[1],
940
+							$selection_and_datatype[0],
941 941
 							$alias,
942
-							implode( ",", $this->_valid_wpdb_data_types )
942
+							implode(",", $this->_valid_wpdb_data_types)
943 943
 						)
944 944
 					);
945 945
 				}
946 946
 				$select_sql_array[] = "{$selection_and_datatype[0]} AS $alias";
947 947
 			}
948
-			$columns_to_select_string = implode(", ",$select_sql_array);
949
-		}else{
948
+			$columns_to_select_string = implode(", ", $select_sql_array);
949
+		} else {
950 950
 			$columns_to_select_string = $columns_to_select;
951 951
 		}
952 952
 		return $columns_to_select_string;
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
 	 * @return string
962 962
 	 * @throws \EE_Error
963 963
 	 */
964
-	public function primary_key_name(){
964
+	public function primary_key_name() {
965 965
 		return $this->get_primary_key_field()->get_name();
966 966
 	}
967 967
 
@@ -973,14 +973,14 @@  discard block
 block discarded – undo
973 973
 	 * @param mixed $id int or string, depending on the type of the model's primary key
974 974
 	 * @return EE_Base_Class
975 975
 	 */
976
-	public function get_one_by_ID($id){
977
-		if( $this->get_from_entity_map( $id ) ){
978
-			return $this->get_from_entity_map( $id );
976
+	public function get_one_by_ID($id) {
977
+		if ($this->get_from_entity_map($id)) {
978
+			return $this->get_from_entity_map($id);
979 979
 		}
980 980
 		return $this->get_one(
981 981
 			$this->alter_query_params_to_restrict_by_ID(
982 982
 				$id,
983
-				array( 'default_where_conditions' => 'minimum' )
983
+				array('default_where_conditions' => 'minimum')
984 984
 			)
985 985
 		);
986 986
 	}
@@ -996,15 +996,15 @@  discard block
 block discarded – undo
996 996
 	 * @return array of normal query params, @see EEM_Base::get_all
997 997
 	 * @throws \EE_Error
998 998
 	 */
999
-	public function alter_query_params_to_restrict_by_ID( $id, $query_params = array() ) {
1000
-		if( ! isset( $query_params[ 0 ] ) ) {
1001
-			$query_params[ 0 ] = array();
999
+	public function alter_query_params_to_restrict_by_ID($id, $query_params = array()) {
1000
+		if ( ! isset($query_params[0])) {
1001
+			$query_params[0] = array();
1002 1002
 		}
1003
-		if( $this->has_primary_key_field ( ) ) {
1004
-			$query_params[ 0 ][ $this->primary_key_name() ] = $id ;
1005
-		}else{
1003
+		if ($this->has_primary_key_field( )) {
1004
+			$query_params[0][$this->primary_key_name()] = $id;
1005
+		} else {
1006 1006
 			//no primary key, so the $id must be from the get_index_primary_key_string()
1007
-			$query_params[0] = array_replace_recursive( $query_params[ 0 ], $this->parse_index_primary_key_string( $id ) );
1007
+			$query_params[0] = array_replace_recursive($query_params[0], $this->parse_index_primary_key_string($id));
1008 1008
 		}
1009 1009
 		return $query_params;
1010 1010
 	}
@@ -1020,16 +1020,16 @@  discard block
 block discarded – undo
1020 1020
 	 * @return EE_Base_Class|EE_Soft_Delete_Base_Class|NULL
1021 1021
 	 * @throws \EE_Error
1022 1022
 	 */
1023
-	public function get_one($query_params = array()){
1024
-		if( ! is_array( $query_params ) ){
1025
-			EE_Error::doing_it_wrong('EEM_Base::get_one', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' );
1023
+	public function get_one($query_params = array()) {
1024
+		if ( ! is_array($query_params)) {
1025
+			EE_Error::doing_it_wrong('EEM_Base::get_one', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0');
1026 1026
 			$query_params = array();
1027 1027
 		}
1028 1028
 		$query_params['limit'] = 1;
1029 1029
 		$items = $this->get_all($query_params);
1030
-		if(empty($items)){
1030
+		if (empty($items)) {
1031 1031
 			return null;
1032
-		}else{
1032
+		} else {
1033 1033
 			return array_shift($items);
1034 1034
 		}
1035 1035
 	}
@@ -1052,8 +1052,8 @@  discard block
 block discarded – undo
1052 1052
 	 * @return EE_Base_Class[]|array
1053 1053
 	 * @throws \EE_Error
1054 1054
 	 */
1055
-	public function next_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1056
-		return $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select );
1055
+	public function next_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1056
+		return $this->_get_consecutive($current_field_value, '>', $field_to_order_by, $limit, $query_params, $columns_to_select);
1057 1057
 	}
1058 1058
 
1059 1059
 
@@ -1074,8 +1074,8 @@  discard block
 block discarded – undo
1074 1074
 	 * @return EE_Base_Class[]|array
1075 1075
 	 * @throws \EE_Error
1076 1076
 	 */
1077
-	public function previous_x( $current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1078
-		return $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select );
1077
+	public function previous_x($current_field_value, $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1078
+		return $this->_get_consecutive($current_field_value, '<', $field_to_order_by, $limit, $query_params, $columns_to_select);
1079 1079
 	}
1080 1080
 
1081 1081
 
@@ -1096,9 +1096,9 @@  discard block
 block discarded – undo
1096 1096
 	 * @return EE_Base_Class|null|array()
1097 1097
 	 * @throws \EE_Error
1098 1098
 	 */
1099
-	public function next( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
1100
-		$results = $this->_get_consecutive( $current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select );
1101
-		return empty( $results ) ? null : reset( $results );
1099
+	public function next($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
1100
+		$results = $this->_get_consecutive($current_field_value, '>', $field_to_order_by, 1, $query_params, $columns_to_select);
1101
+		return empty($results) ? null : reset($results);
1102 1102
 	}
1103 1103
 
1104 1104
 
@@ -1120,9 +1120,9 @@  discard block
 block discarded – undo
1120 1120
  * @return EE_Base_Class|null|array()
1121 1121
 	 * @throws EE_Error
1122 1122
 	 */
1123
-	public function previous( $current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) {
1124
-		$results = $this->_get_consecutive( $current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select );
1125
-		return empty( $results ) ? null : reset( $results );
1123
+	public function previous($current_field_value, $field_to_order_by = null, $query_params = array(), $columns_to_select = null) {
1124
+		$results = $this->_get_consecutive($current_field_value, '<', $field_to_order_by, 1, $query_params, $columns_to_select);
1125
+		return empty($results) ? null : reset($results);
1126 1126
 	}
1127 1127
 
1128 1128
 
@@ -1143,42 +1143,42 @@  discard block
 block discarded – undo
1143 1143
 	 * @return EE_Base_Class[]|array
1144 1144
 	 * @throws EE_Error
1145 1145
 	 */
1146
-	protected function _get_consecutive( $current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) {
1146
+	protected function _get_consecutive($current_field_value, $operand = '>', $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) {
1147 1147
 		//if $field_to_order_by is empty then let's assume we're ordering by the primary key.
1148
-		if ( empty( $field_to_order_by ) ) {
1149
-			if ( $this->has_primary_key_field() ) {
1148
+		if (empty($field_to_order_by)) {
1149
+			if ($this->has_primary_key_field()) {
1150 1150
 				$field_to_order_by = $this->get_primary_key_field()->get_name();
1151 1151
 			} else {
1152 1152
 
1153
-				if ( WP_DEBUG ) {
1154
-					throw new EE_Error( __( 'EEM_Base::_get_consecutive() has been called with no $field_to_order_by argument and there is no primary key on the field.  Please provide the field you would like to use as the base for retrieving the next item(s).', 'event_espresso' ) );
1153
+				if (WP_DEBUG) {
1154
+					throw new EE_Error(__('EEM_Base::_get_consecutive() has been called with no $field_to_order_by argument and there is no primary key on the field.  Please provide the field you would like to use as the base for retrieving the next item(s).', 'event_espresso'));
1155 1155
 				}
1156
-				EE_Error::add_error( __('There was an error with the query.', 'event_espresso') );
1156
+				EE_Error::add_error(__('There was an error with the query.', 'event_espresso'));
1157 1157
 				return array();
1158 1158
 			}
1159 1159
 		}
1160 1160
 
1161
-		if( ! is_array( $query_params ) ){
1162
-			EE_Error::doing_it_wrong('EEM_Base::_get_consecutive', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' );
1161
+		if ( ! is_array($query_params)) {
1162
+			EE_Error::doing_it_wrong('EEM_Base::_get_consecutive', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0');
1163 1163
 			$query_params = array();
1164 1164
 		}
1165 1165
 
1166 1166
 		//let's add the where query param for consecutive look up.
1167
-		$query_params[0][ $field_to_order_by ] = array( $operand, $current_field_value );
1167
+		$query_params[0][$field_to_order_by] = array($operand, $current_field_value);
1168 1168
 		$query_params['limit'] = $limit;
1169 1169
 
1170 1170
 		//set direction
1171
-		$incoming_orderby = isset( $query_params['order_by'] ) ? (array)$query_params['order_by'] : array();
1171
+		$incoming_orderby = isset($query_params['order_by']) ? (array) $query_params['order_by'] : array();
1172 1172
 		$query_params['order_by'] = $operand === '>'
1173
-			? array( $field_to_order_by => 'ASC' ) + $incoming_orderby
1174
-			: array( $field_to_order_by => 'DESC') + $incoming_orderby;
1173
+			? array($field_to_order_by => 'ASC') + $incoming_orderby
1174
+			: array($field_to_order_by => 'DESC') + $incoming_orderby;
1175 1175
 
1176 1176
 		//if $columns_to_select is empty then that means we're returning EE_Base_Class objects
1177
-		if ( empty( $columns_to_select ) ) {
1178
-			return $this->get_all( $query_params );
1177
+		if (empty($columns_to_select)) {
1178
+			return $this->get_all($query_params);
1179 1179
 		} else {
1180 1180
 			//getting just the fields
1181
-			return $this->_get_all_wpdb_results( $query_params, ARRAY_A, $columns_to_select );
1181
+			return $this->_get_all_wpdb_results($query_params, ARRAY_A, $columns_to_select);
1182 1182
 		}
1183 1183
 	}
1184 1184
 
@@ -1189,18 +1189,18 @@  discard block
 block discarded – undo
1189 1189
 	 * This sets the _timezone property after model object has been instantiated.
1190 1190
 	 * @param null | string $timezone valid PHP DateTimeZone timezone string
1191 1191
 	 */
1192
-	public function set_timezone( $timezone ) {
1193
-		if ( $timezone !== null ) {
1192
+	public function set_timezone($timezone) {
1193
+		if ($timezone !== null) {
1194 1194
 			$this->_timezone = $timezone;
1195 1195
 		}
1196 1196
 		//note we need to loop through relations and set the timezone on those objects as well.
1197
-		foreach ( $this->_model_relations as $relation ) {
1198
-			$relation->set_timezone( $timezone );
1197
+		foreach ($this->_model_relations as $relation) {
1198
+			$relation->set_timezone($timezone);
1199 1199
 		}
1200 1200
 		//and finally we do the same for any datetime fields
1201
-		foreach ( $this->_fields as $field ) {
1202
-			if ( $field instanceof EE_Datetime_Field ) {
1203
-				$field->set_timezone( $timezone );
1201
+		foreach ($this->_fields as $field) {
1202
+			if ($field instanceof EE_Datetime_Field) {
1203
+				$field->set_timezone($timezone);
1204 1204
 			}
1205 1205
 		}
1206 1206
 	}
@@ -1215,9 +1215,9 @@  discard block
 block discarded – undo
1215 1215
 	 */
1216 1216
 	public function get_timezone() {
1217 1217
 		//first validate if timezone is set.  If not, then let's set it be whatever is set on the model fields.
1218
-		if ( empty( $this->_timezone ) ) {
1219
-			foreach( $this->_fields as $field ) {
1220
-				if ( $field instanceof EE_Datetime_Field ) {
1218
+		if (empty($this->_timezone)) {
1219
+			foreach ($this->_fields as $field) {
1220
+				if ($field instanceof EE_Datetime_Field) {
1221 1221
 					$this->set_timezone($field->get_timezone());
1222 1222
 					break;
1223 1223
 				}
@@ -1225,8 +1225,8 @@  discard block
 block discarded – undo
1225 1225
 		}
1226 1226
 
1227 1227
 		//if timezone STILL empty then return the default timezone for the site.
1228
-		if ( empty( $this->_timezone ) ) {
1229
-			$this->set_timezone( EEH_DTT_Helper::get_timezone() );
1228
+		if (empty($this->_timezone)) {
1229
+			$this->set_timezone(EEH_DTT_Helper::get_timezone());
1230 1230
 		}
1231 1231
 		return $this->_timezone;
1232 1232
 	}
@@ -1244,19 +1244,19 @@  discard block
 block discarded – undo
1244 1244
 	 *
1245 1245
 	 * @return array formats in an array with the date format first, and the time format last.
1246 1246
 	 */
1247
-	public function get_formats_for( $field_name, $pretty = false ) {
1248
-		$field_settings = $this->field_settings_for( $field_name );
1247
+	public function get_formats_for($field_name, $pretty = false) {
1248
+		$field_settings = $this->field_settings_for($field_name);
1249 1249
 
1250 1250
 		//if not a valid EE_Datetime_Field then throw error
1251
-		if ( ! $field_settings instanceof EE_Datetime_Field ) {
1252
-			throw new EE_Error( sprintf( __('The field sent into EEM_Base::get_formats_for (%s) is not registered as a EE_Datetime_Field. Please check the spelling and make sure you are submitting the right field name to retrieve date_formats for.', 'event_espresso' ), $field_name ) );
1251
+		if ( ! $field_settings instanceof EE_Datetime_Field) {
1252
+			throw new EE_Error(sprintf(__('The field sent into EEM_Base::get_formats_for (%s) is not registered as a EE_Datetime_Field. Please check the spelling and make sure you are submitting the right field name to retrieve date_formats for.', 'event_espresso'), $field_name));
1253 1253
 		}
1254 1254
 
1255 1255
 		//while we are here, let's make sure the timezone internally in EEM_Base matches what is stored on
1256 1256
 		//the field.
1257 1257
 		$this->_timezone = $field_settings->get_timezone();
1258 1258
 
1259
-		return array( $field_settings->get_date_format( $pretty ), $field_settings->get_time_format( $pretty ) );
1259
+		return array($field_settings->get_date_format($pretty), $field_settings->get_time_format($pretty));
1260 1260
 	}
1261 1261
 
1262 1262
 
@@ -1280,25 +1280,25 @@  discard block
 block discarded – undo
1280 1280
 	 * @return int|string  If the given field_name is not of the EE_Datetime_Field type, then an EE_Error
1281 1281
 	 *                    	     exception is triggered.
1282 1282
 	 */
1283
-	public function current_time_for_query( $field_name, $timestamp = false, $what = 'both' ) {
1284
-		$formats = $this->get_formats_for( $field_name );
1283
+	public function current_time_for_query($field_name, $timestamp = false, $what = 'both') {
1284
+		$formats = $this->get_formats_for($field_name);
1285 1285
 
1286
-		$DateTime = new DateTime( "now", new DateTimeZone( $this->_timezone ) );
1286
+		$DateTime = new DateTime("now", new DateTimeZone($this->_timezone));
1287 1287
 
1288
-		if ( $timestamp ) {
1289
-			return $DateTime->format( 'U' );
1288
+		if ($timestamp) {
1289
+			return $DateTime->format('U');
1290 1290
 		}
1291 1291
 
1292 1292
 		//not returning timestamp, so return formatted string in timezone.
1293
-		switch( $what ) {
1293
+		switch ($what) {
1294 1294
 			case 'time' :
1295
-				return $DateTime->format( $formats[1] );
1295
+				return $DateTime->format($formats[1]);
1296 1296
 				break;
1297 1297
 			case 'date' :
1298
-				return $DateTime->format( $formats[0] );
1298
+				return $DateTime->format($formats[0]);
1299 1299
 				break;
1300 1300
 			default :
1301
-				return $DateTime->format( implode( ' ', $formats ) );
1301
+				return $DateTime->format(implode(' ', $formats));
1302 1302
 				break;
1303 1303
 		}
1304 1304
 	}
@@ -1320,17 +1320,17 @@  discard block
 block discarded – undo
1320 1320
 	 * @return DateTime
1321 1321
 	 * @throws \EE_Error
1322 1322
 	 */
1323
-	public function convert_datetime_for_query( $field_name, $timestring, $incoming_format, $timezone = '' ) {
1323
+	public function convert_datetime_for_query($field_name, $timestring, $incoming_format, $timezone = '') {
1324 1324
 
1325 1325
 		//just using this to ensure the timezone is set correctly internally
1326
-		$this->get_formats_for( $field_name );
1326
+		$this->get_formats_for($field_name);
1327 1327
 
1328 1328
 		//load EEH_DTT_Helper
1329
-		$set_timezone = empty( $timezone ) ? EEH_DTT_Helper::get_timezone() : $timezone;
1329
+		$set_timezone = empty($timezone) ? EEH_DTT_Helper::get_timezone() : $timezone;
1330 1330
 
1331
-		$incomingDateTime = date_create_from_format( $incoming_format, $timestring, new DateTimeZone( $set_timezone ) );
1331
+		$incomingDateTime = date_create_from_format($incoming_format, $timestring, new DateTimeZone($set_timezone));
1332 1332
 
1333
-		return $incomingDateTime->setTimezone( new DateTimeZone( $this->_timezone ) );
1333
+		return $incomingDateTime->setTimezone(new DateTimeZone($this->_timezone));
1334 1334
 	}
1335 1335
 
1336 1336
 
@@ -1340,7 +1340,7 @@  discard block
 block discarded – undo
1340 1340
 	 * Gets all the tables comprising this model. Array keys are the table aliases, and values are EE_Table objects
1341 1341
 	 * @return EE_Table_Base[]
1342 1342
 	 */
1343
-	public function get_tables(){
1343
+	public function get_tables() {
1344 1344
 		return $this->_tables;
1345 1345
 	}
1346 1346
 
@@ -1376,9 +1376,9 @@  discard block
 block discarded – undo
1376 1376
 	 * @return int how many rows got updated or FALSE if something went wrong with the query (wp returns FALSE or num rows affected which *could* include 0 which DOES NOT mean the query was bad)
1377 1377
 	 * @throws \EE_Error
1378 1378
 	 */
1379
-	public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE){
1380
-		if( ! is_array( $query_params ) ){
1381
-			EE_Error::doing_it_wrong('EEM_Base::update', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' );
1379
+	public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) {
1380
+		if ( ! is_array($query_params)) {
1381
+			EE_Error::doing_it_wrong('EEM_Base::update', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0');
1382 1382
 			$query_params = array();
1383 1383
 		}
1384 1384
 		/**
@@ -1388,7 +1388,7 @@  discard block
 block discarded – undo
1388 1388
 		 * @param array $fields_n_values the updated fields and their new values
1389 1389
 		 * @param array $query_params @see EEM_Base::get_all()
1390 1390
 		 */
1391
-		do_action( 'AHEE__EEM_Base__update__begin',$this, $fields_n_values, $query_params );
1391
+		do_action('AHEE__EEM_Base__update__begin', $this, $fields_n_values, $query_params);
1392 1392
 		/**
1393 1393
 		 * Filters the fields about to be updated given the query parameters. You can provide the
1394 1394
 		 * $query_params to $this->get_all() to find exactly which records will be updated
@@ -1396,10 +1396,10 @@  discard block
 block discarded – undo
1396 1396
 		 * @param EEM_Base $model the model being queried
1397 1397
 		 * @param array $query_params see EEM_Base::get_all()
1398 1398
 		 */
1399
-		$fields_n_values = (array)apply_filters( 'FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params );
1399
+		$fields_n_values = (array) apply_filters('FHEE__EEM_Base__update__fields_n_values', $fields_n_values, $this, $query_params);
1400 1400
 		//need to verify that, for any entry we want to update, there are entries in each secondary table.
1401 1401
 		//to do that, for each table, verify that it's PK isn't null.
1402
-		$tables= $this->get_tables();
1402
+		$tables = $this->get_tables();
1403 1403
 
1404 1404
 		//and if the other tables don't have a row for each table-to-be-updated, we'll insert one with whatever values available in the current update query
1405 1405
 		//NOTE: we should make this code more efficient by NOT querying twice
@@ -1409,29 +1409,29 @@  discard block
 block discarded – undo
1409 1409
 			//we want to make sure the default_where strategy is ignored
1410 1410
 			$this->_ignore_where_strategy = TRUE;
1411 1411
 			$wpdb_select_results = $this->_get_all_wpdb_results($query_params);
1412
-			foreach( $wpdb_select_results as $wpdb_result ){
1412
+			foreach ($wpdb_select_results as $wpdb_result) {
1413 1413
 				// type cast stdClass as array
1414
-				$wpdb_result = (array)$wpdb_result;
1414
+				$wpdb_result = (array) $wpdb_result;
1415 1415
 				//get the model object's PK, as we'll want this if we need to insert a row into secondary tables
1416
-				if( $this->has_primary_key_field() ){
1417
-					$main_table_pk_value = $wpdb_result[ $this->get_primary_key_field()->get_qualified_column() ];
1418
-				}else{
1416
+				if ($this->has_primary_key_field()) {
1417
+					$main_table_pk_value = $wpdb_result[$this->get_primary_key_field()->get_qualified_column()];
1418
+				} else {
1419 1419
 					//if there's no primary key, we basically can't support having a 2nd table on the model (we could but it would be lots of work)
1420 1420
 					$main_table_pk_value = null;
1421 1421
 				}
1422 1422
 				//if there are more than 1 tables, we'll want to verify that each table for this model has an entry in the other tables
1423 1423
 				//and if the other tables don't have a row for each table-to-be-updated, we'll insert one with whatever values available in the current update query
1424
-				if(count($tables) > 1){
1424
+				if (count($tables) > 1) {
1425 1425
 					//foreach matching row in the DB, ensure that each table's PK isn't null. If so, there must not be an entry
1426 1426
 					//in that table, and so we'll want to insert one
1427
-					foreach($tables as $table_obj){
1427
+					foreach ($tables as $table_obj) {
1428 1428
 						$this_table_pk_column = $table_obj->get_fully_qualified_pk_column();
1429 1429
 						//if there is no private key for this table on the results, it means there's no entry
1430 1430
 						//in this table, right? so insert a row in the current table, using any fields available
1431
-						if( ! ( array_key_exists( $this_table_pk_column, $wpdb_result) && $wpdb_result[ $this_table_pk_column ] )){
1431
+						if ( ! (array_key_exists($this_table_pk_column, $wpdb_result) && $wpdb_result[$this_table_pk_column])) {
1432 1432
 							$success = $this->_insert_into_specific_table($table_obj, $fields_n_values, $main_table_pk_value);
1433 1433
 							//if we died here, report the error
1434
-							if( ! $success ) {
1434
+							if ( ! $success) {
1435 1435
 								return false;
1436 1436
 							}
1437 1437
 						}
@@ -1451,44 +1451,44 @@  discard block
 block discarded – undo
1451 1451
 		//if this wasn't called from a model object (to update itself)
1452 1452
 		//then we want to make sure we keep all the existing
1453 1453
 		//model objects in sync with the db
1454
-		if( $keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object ){
1455
-			if( $this->has_primary_key_field() ){
1456
-				$model_objs_affected_ids = $this->get_col( $query_params );
1457
-			}else{
1454
+		if ($keep_model_objs_in_sync && ! $this->_values_already_prepared_by_model_object) {
1455
+			if ($this->has_primary_key_field()) {
1456
+				$model_objs_affected_ids = $this->get_col($query_params);
1457
+			} else {
1458 1458
 				//we need to select a bunch of columns and then combine them into the the "index primary key string"s
1459
-				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A );
1459
+				$models_affected_key_columns = $this->_get_all_wpdb_results($query_params, ARRAY_A);
1460 1460
 				$model_objs_affected_ids = array();
1461
-				foreach( $models_affected_key_columns as $row ){
1462
-					$combined_index_key = $this->get_index_primary_key_string( $row );
1463
-					$model_objs_affected_ids[ $combined_index_key ] = $combined_index_key;
1461
+				foreach ($models_affected_key_columns as $row) {
1462
+					$combined_index_key = $this->get_index_primary_key_string($row);
1463
+					$model_objs_affected_ids[$combined_index_key] = $combined_index_key;
1464 1464
 				}
1465 1465
 
1466 1466
 			}
1467 1467
 
1468
-			if( ! $model_objs_affected_ids ){
1468
+			if ( ! $model_objs_affected_ids) {
1469 1469
 				//wait wait wait- if nothing was affected let's stop here
1470 1470
 				return 0;
1471 1471
 			}
1472
-			foreach( $model_objs_affected_ids as $id ){
1473
-				$model_obj_in_entity_map = $this->get_from_entity_map( $id );
1474
-				if( $model_obj_in_entity_map ){
1475
-					foreach( $fields_n_values as $field => $new_value ){
1476
-						$model_obj_in_entity_map->set( $field, $new_value );
1472
+			foreach ($model_objs_affected_ids as $id) {
1473
+				$model_obj_in_entity_map = $this->get_from_entity_map($id);
1474
+				if ($model_obj_in_entity_map) {
1475
+					foreach ($fields_n_values as $field => $new_value) {
1476
+						$model_obj_in_entity_map->set($field, $new_value);
1477 1477
 					}
1478 1478
 				}
1479 1479
 			}
1480 1480
 			//if there is a primary key on this model, we can now do a slight optimization
1481
-			if( $this->has_primary_key_field() ){
1481
+			if ($this->has_primary_key_field()) {
1482 1482
 				//we already know what we want to update. So let's make the query simpler so it's a little more efficient
1483 1483
 				$query_params = array(
1484
-					array( $this->primary_key_name() => array( 'IN', $model_objs_affected_ids ) ),
1485
-					'limit' => count( $model_objs_affected_ids ), 'default_where_conditions' => 'none' );
1484
+					array($this->primary_key_name() => array('IN', $model_objs_affected_ids)),
1485
+					'limit' => count($model_objs_affected_ids), 'default_where_conditions' => 'none' );
1486 1486
 			}
1487 1487
 		}
1488 1488
 
1489
-		$model_query_info = $this->_create_model_query_info_carrier( $query_params );
1490
-		$SQL = "UPDATE ".$model_query_info->get_full_join_sql()." SET ".$this->_construct_update_sql($fields_n_values).$model_query_info->get_where_sql();//note: doesn't use _construct_2nd_half_of_select_query() because doesn't accept LIMIT, ORDER BY, etc.
1491
-		$rows_affected = $this->_do_wpdb_query('query', array( $SQL ) );
1489
+		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1490
+		$SQL = "UPDATE ".$model_query_info->get_full_join_sql()." SET ".$this->_construct_update_sql($fields_n_values).$model_query_info->get_where_sql(); //note: doesn't use _construct_2nd_half_of_select_query() because doesn't accept LIMIT, ORDER BY, etc.
1491
+		$rows_affected = $this->_do_wpdb_query('query', array($SQL));
1492 1492
 		/**
1493 1493
 		 * Action called after a model update call has been made.
1494 1494
 		 *
@@ -1497,8 +1497,8 @@  discard block
 block discarded – undo
1497 1497
 		 * @param array $query_params @see EEM_Base::get_all()
1498 1498
 		 * @param int $rows_affected
1499 1499
 		 */
1500
-		do_action( 'AHEE__EEM_Base__update__end',$this, $fields_n_values, $query_params, $rows_affected );
1501
-		return $rows_affected;//how many supposedly got updated
1500
+		do_action('AHEE__EEM_Base__update__end', $this, $fields_n_values, $query_params, $rows_affected);
1501
+		return $rows_affected; //how many supposedly got updated
1502 1502
 	}
1503 1503
 
1504 1504
 
@@ -1514,22 +1514,22 @@  discard block
 block discarded – undo
1514 1514
 	 * @return array just like $wpdb->get_col()
1515 1515
 	 * @throws \EE_Error
1516 1516
 	 */
1517
-	public function get_col( $query_params  = array(), $field_to_select = NULL ){
1517
+	public function get_col($query_params = array(), $field_to_select = NULL) {
1518 1518
 
1519
-		if( $field_to_select ){
1520
-			$field = $this->field_settings_for( $field_to_select );
1521
-		}elseif( $this->has_primary_key_field ( ) ){
1519
+		if ($field_to_select) {
1520
+			$field = $this->field_settings_for($field_to_select);
1521
+		}elseif ($this->has_primary_key_field( )) {
1522 1522
 			$field = $this->get_primary_key_field();
1523
-		}else{
1523
+		} else {
1524 1524
 			//no primary key, just grab the first column
1525
-			$field = reset( $this->field_settings());
1525
+			$field = reset($this->field_settings());
1526 1526
 		}
1527 1527
 
1528 1528
 
1529 1529
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1530 1530
 		$select_expressions = $field->get_qualified_column();
1531
-		$SQL ="SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1532
-		return $this->_do_wpdb_query('get_col', array( $SQL ) );
1531
+		$SQL = "SELECT $select_expressions ".$this->_construct_2nd_half_of_select_query($model_query_info);
1532
+		return $this->_do_wpdb_query('get_col', array($SQL));
1533 1533
 	}
1534 1534
 
1535 1535
 
@@ -1542,12 +1542,12 @@  discard block
 block discarded – undo
1542 1542
 	 * @return string
1543 1543
 	 * @throws \EE_Error
1544 1544
 	 */
1545
-	public function get_var( $query_params = array(), $field_to_select = NULL ) {
1546
-		$query_params[ 'limit' ] = 1;
1547
-		$col = $this->get_col( $query_params, $field_to_select );
1548
-		if( ! empty( $col ) ) {
1549
-			return reset( $col );
1550
-		}else{
1545
+	public function get_var($query_params = array(), $field_to_select = NULL) {
1546
+		$query_params['limit'] = 1;
1547
+		$col = $this->get_col($query_params, $field_to_select);
1548
+		if ( ! empty($col)) {
1549
+			return reset($col);
1550
+		} else {
1551 1551
 			return NULL;
1552 1552
 		}
1553 1553
 	}
@@ -1563,19 +1563,19 @@  discard block
 block discarded – undo
1563 1563
 	 * @return string of SQL
1564 1564
 	 * @throws \EE_Error
1565 1565
 	 */
1566
-	public function _construct_update_sql($fields_n_values){
1566
+	public function _construct_update_sql($fields_n_values) {
1567 1567
 		/** @type WPDB $wpdb */
1568 1568
 		global $wpdb;
1569 1569
 		$cols_n_values = array();
1570
-		foreach($fields_n_values as $field_name => $value){
1570
+		foreach ($fields_n_values as $field_name => $value) {
1571 1571
 			$field_obj = $this->field_settings_for($field_name);
1572 1572
 			//if the value is NULL, we want to assign the value to that.
1573 1573
 			//wpdb->prepare doesn't really handle that properly
1574
-			$prepared_value = $this->_prepare_value_or_use_default( $field_obj, $fields_n_values );
1575
-			$value_sql = $prepared_value===NULL ? 'NULL' : $wpdb->prepare( $field_obj->get_wpdb_data_type(), $prepared_value );
1574
+			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
1575
+			$value_sql = $prepared_value === NULL ? 'NULL' : $wpdb->prepare($field_obj->get_wpdb_data_type(), $prepared_value);
1576 1576
 			$cols_n_values[] = $field_obj->get_qualified_column()."=".$value_sql;
1577 1577
 		}
1578
-		return implode(",",$cols_n_values);
1578
+		return implode(",", $cols_n_values);
1579 1579
 
1580 1580
 	}
1581 1581
 
@@ -1591,10 +1591,10 @@  discard block
 block discarded – undo
1591 1591
 	 * @return boolean whether the row got deleted or not
1592 1592
 	 * @throws \EE_Error
1593 1593
 	 */
1594
-	public function delete_permanently_by_ID( $id ) {
1594
+	public function delete_permanently_by_ID($id) {
1595 1595
 		return $this->delete_permanently(
1596 1596
 			array(
1597
-				array( $this->get_primary_key_field()->get_name() => $id ),
1597
+				array($this->get_primary_key_field()->get_name() => $id),
1598 1598
 				'limit' 	=> 1
1599 1599
 			)
1600 1600
 		);
@@ -1610,10 +1610,10 @@  discard block
 block discarded – undo
1610 1610
 	 * @return boolean whether the row got deleted or not
1611 1611
 	 * @throws \EE_Error
1612 1612
 	 */
1613
-	public function delete_by_ID( $id ){
1613
+	public function delete_by_ID($id) {
1614 1614
 		return $this->delete(
1615 1615
 			array(
1616
-				array( $this->get_primary_key_field()->get_name() => $id ),
1616
+				array($this->get_primary_key_field()->get_name() => $id),
1617 1617
 				'limit' 	=> 1
1618 1618
 			)
1619 1619
 		);
@@ -1632,7 +1632,7 @@  discard block
 block discarded – undo
1632 1632
 	 * @return int how many rows got deleted
1633 1633
 	 * @throws \EE_Error
1634 1634
 	 */
1635
-	public function delete($query_params,$allow_blocking = true){
1635
+	public function delete($query_params, $allow_blocking = true) {
1636 1636
 		return $this->delete_permanently($query_params, $allow_blocking);
1637 1637
 	}
1638 1638
 
@@ -1650,7 +1650,7 @@  discard block
 block discarded – undo
1650 1650
 	 * @return int how many rows got deleted
1651 1651
 	 * @throws \EE_Error
1652 1652
 	 */
1653
-	public function delete_permanently($query_params,$allow_blocking = true){
1653
+	public function delete_permanently($query_params, $allow_blocking = true) {
1654 1654
 		/**
1655 1655
 		 * Action called just before performing a real deletion query. You can use the
1656 1656
 		 * model and its $query_params to find exactly which items will be deleted
@@ -1659,31 +1659,31 @@  discard block
 block discarded – undo
1659 1659
 		 * @param boolean $allow_blocking whether or not to allow related model objects
1660 1660
 		 * to block (prevent) this deletion
1661 1661
 		 */
1662
-		do_action( 'AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking );
1662
+		do_action('AHEE__EEM_Base__delete__begin', $this, $query_params, $allow_blocking);
1663 1663
 		//some MySQL databases may be running safe mode, which may restrict
1664 1664
 		//deletion if there is no KEY column used in the WHERE statement of a deletion.
1665 1665
 		//to get around this, we first do a SELECT, get all the IDs, and then run another query
1666 1666
 		//to delete them
1667 1667
 		$items_for_deletion = $this->_get_all_wpdb_results($query_params);
1668
-		$deletion_where = $this->_setup_ids_for_delete( $items_for_deletion, $allow_blocking);
1669
-		if($deletion_where){
1668
+		$deletion_where = $this->_setup_ids_for_delete($items_for_deletion, $allow_blocking);
1669
+		if ($deletion_where) {
1670 1670
 			//echo "objects for deletion:";var_dump($objects_for_deletion);
1671 1671
 			$model_query_info = $this->_create_model_query_info_carrier($query_params);
1672
-			$table_aliases = array_keys( $this->_tables );
1673
-			$SQL = "DELETE ".implode(", ",$table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1672
+			$table_aliases = array_keys($this->_tables);
1673
+			$SQL = "DELETE ".implode(", ", $table_aliases)." FROM ".$model_query_info->get_full_join_sql()." WHERE ".$deletion_where;
1674 1674
 
1675 1675
 			//		/echo "delete sql:$SQL";
1676
-			$rows_deleted = $this->_do_wpdb_query( 'query', array( $SQL ) );
1677
-		}else{
1676
+			$rows_deleted = $this->_do_wpdb_query('query', array($SQL));
1677
+		} else {
1678 1678
 			$rows_deleted = 0;
1679 1679
 		}
1680 1680
 
1681 1681
 		//and lastly make sure those items are removed from the entity map; if they could be put into it at all
1682
-		if( $this->has_primary_key_field() ){
1683
-			foreach($items_for_deletion as $item_for_deletion_row ){
1684
-				$pk_value = $item_for_deletion_row[ $this->get_primary_key_field()->get_qualified_column() ];
1685
-				if( isset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $pk_value ] ) ){
1686
-					unset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $pk_value ] );
1682
+		if ($this->has_primary_key_field()) {
1683
+			foreach ($items_for_deletion as $item_for_deletion_row) {
1684
+				$pk_value = $item_for_deletion_row[$this->get_primary_key_field()->get_qualified_column()];
1685
+				if (isset($this->_entity_map[EEM_Base::$_model_query_blog_id][$pk_value])) {
1686
+					unset($this->_entity_map[EEM_Base::$_model_query_blog_id][$pk_value]);
1687 1687
 				}
1688 1688
 			}
1689 1689
 		}
@@ -1695,8 +1695,8 @@  discard block
 block discarded – undo
1695 1695
 		 * @param array $query_params @see EEM_Base::get_all()
1696 1696
 		 * @param int $rows_deleted
1697 1697
 		 */
1698
-		do_action( 'AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted );
1699
-		return $rows_deleted;//how many supposedly got deleted
1698
+		do_action('AHEE__EEM_Base__delete__end', $this, $query_params, $rows_deleted);
1699
+		return $rows_deleted; //how many supposedly got deleted
1700 1700
 	}
1701 1701
 
1702 1702
 
@@ -1714,28 +1714,28 @@  discard block
 block discarded – undo
1714 1714
 	 * @return boolean
1715 1715
 	 * @throws \EE_Error
1716 1716
 	 */
1717
-	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null){
1717
+	public function delete_is_blocked_by_related_models($this_model_obj_or_id, $ignore_this_model_obj = null) {
1718 1718
 		//first, if $ignore_this_model_obj was supplied, get its model
1719
-		if($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class){
1719
+		if ($ignore_this_model_obj && $ignore_this_model_obj instanceof EE_Base_Class) {
1720 1720
 			$ignored_model = $ignore_this_model_obj->get_model();
1721
-		}else{
1721
+		} else {
1722 1722
 			$ignored_model = null;
1723 1723
 		}
1724 1724
 		//now check all the relations of $this_model_obj_or_id and see if there
1725 1725
 		//are any related model objects blocking it?
1726 1726
 		$is_blocked = false;
1727
-		foreach($this->_model_relations as $relation_name => $relation_obj){
1728
-			if( $relation_obj->block_delete_if_related_models_exist()){
1727
+		foreach ($this->_model_relations as $relation_name => $relation_obj) {
1728
+			if ($relation_obj->block_delete_if_related_models_exist()) {
1729 1729
 				//if $ignore_this_model_obj was supplied, then for the query
1730 1730
 				//on that model needs to be told to ignore $ignore_this_model_obj
1731
-				if($ignored_model && $relation_name === $ignored_model->get_this_model_name()){
1732
-					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id,array(
1733
-					array($ignored_model->get_primary_key_field()->get_name() => array('!=',$ignore_this_model_obj->ID()))));
1734
-				}else{
1731
+				if ($ignored_model && $relation_name === $ignored_model->get_this_model_name()) {
1732
+					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id, array(
1733
+					array($ignored_model->get_primary_key_field()->get_name() => array('!=', $ignore_this_model_obj->ID()))));
1734
+				} else {
1735 1735
 					$related_model_objects = $relation_obj->get_all_related($this_model_obj_or_id);
1736 1736
 				}
1737 1737
 
1738
-				if($related_model_objects){
1738
+				if ($related_model_objects) {
1739 1739
 					EE_Error::add_error($relation_obj->get_deletion_error_message(), __FILE__, __FUNCTION__, __LINE__);
1740 1740
 					$is_blocked = true;
1741 1741
 				}
@@ -1755,75 +1755,75 @@  discard block
 block discarded – undo
1755 1755
 	 * @throws EE_Error
1756 1756
 	 * @return string    everything that comes after the WHERE statement.
1757 1757
 	 */
1758
-	protected function _setup_ids_for_delete( $objects_for_deletion, $allow_blocking = true) {
1759
-		if($this->has_primary_key_field()){
1758
+	protected function _setup_ids_for_delete($objects_for_deletion, $allow_blocking = true) {
1759
+		if ($this->has_primary_key_field()) {
1760 1760
 			$primary_table = $this->_get_main_table();
1761 1761
 			$other_tables = $this->_get_other_tables();
1762 1762
 			$deletes = $query = array();
1763
-			foreach ( $objects_for_deletion as $delete_object ) {
1763
+			foreach ($objects_for_deletion as $delete_object) {
1764 1764
 				//before we mark this object for deletion,
1765 1765
 				//make sure there's no related objects blocking its deletion (if we're checking)
1766 1766
 				if (
1767 1767
 					$allow_blocking
1768 1768
 				    && $this->delete_is_blocked_by_related_models(
1769
-						$delete_object[ $primary_table->get_fully_qualified_pk_column() ]
1769
+						$delete_object[$primary_table->get_fully_qualified_pk_column()]
1770 1770
 					)
1771 1771
 				) {
1772 1772
 					continue;
1773 1773
 				}
1774 1774
 				//primary table deletes
1775
-				if ( isset( $delete_object[ $primary_table->get_fully_qualified_pk_column() ] ) ) {
1776
-					$deletes[ $primary_table->get_fully_qualified_pk_column() ][] = $delete_object[ $primary_table->get_fully_qualified_pk_column() ];
1775
+				if (isset($delete_object[$primary_table->get_fully_qualified_pk_column()])) {
1776
+					$deletes[$primary_table->get_fully_qualified_pk_column()][] = $delete_object[$primary_table->get_fully_qualified_pk_column()];
1777 1777
 				}
1778 1778
 				//other tables
1779
-				if ( ! empty( $other_tables ) ) {
1780
-					foreach ( $other_tables as $ot ) {
1779
+				if ( ! empty($other_tables)) {
1780
+					foreach ($other_tables as $ot) {
1781 1781
 						//first check if we've got the foreign key column here.
1782
-						if ( isset( $delete_object[ $ot->get_fully_qualified_fk_column() ] ) ) {
1783
-							$deletes[ $ot->get_fully_qualified_pk_column() ][] = $delete_object[ $ot->get_fully_qualified_fk_column() ];
1782
+						if (isset($delete_object[$ot->get_fully_qualified_fk_column()])) {
1783
+							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_fk_column()];
1784 1784
 						}
1785 1785
 						// wait! it's entirely possible that we'll have a the primary key
1786 1786
 						// for this table in here, if it's a foreign key for one of the other secondary tables
1787
-						if ( isset( $delete_object[ $ot->get_fully_qualified_pk_column() ] ) ) {
1788
-							$deletes[ $ot->get_fully_qualified_pk_column() ][] = $delete_object[ $ot->get_fully_qualified_pk_column() ];
1787
+						if (isset($delete_object[$ot->get_fully_qualified_pk_column()])) {
1788
+							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1789 1789
 						}
1790 1790
 						// finally, it is possible that the fk for this table is found
1791 1791
 						// in the fully qualified pk column for the fk table, so let's see if that's there!
1792
-						if ( isset( $delete_object[ $ot->get_fully_qualified_pk_on_fk_table() ] ) ) {
1793
-							$deletes[ $ot->get_fully_qualified_pk_column() ][] = $delete_object[ $ot->get_fully_qualified_pk_column() ];
1792
+						if (isset($delete_object[$ot->get_fully_qualified_pk_on_fk_table()])) {
1793
+							$deletes[$ot->get_fully_qualified_pk_column()][] = $delete_object[$ot->get_fully_qualified_pk_column()];
1794 1794
 						}
1795 1795
 					}
1796 1796
 				}
1797 1797
 			}
1798 1798
 
1799 1799
 			//we should have deletes now, so let's just go through and setup the where statement
1800
-			foreach ( $deletes as $column => $values ) {
1800
+			foreach ($deletes as $column => $values) {
1801 1801
 				//make sure we have unique $values;
1802 1802
 				$values = array_unique($values);
1803
-				$query[] = $column . ' IN(' . implode(",",$values) . ')';
1803
+				$query[] = $column.' IN('.implode(",", $values).')';
1804 1804
 			}
1805 1805
 
1806
-			return !empty($query) ? implode(' AND ', $query ) : '';
1807
-		}elseif(count($this->get_combined_primary_key_fields()) > 1){
1806
+			return ! empty($query) ? implode(' AND ', $query) : '';
1807
+		}elseif (count($this->get_combined_primary_key_fields()) > 1) {
1808 1808
 			$ways_to_identify_a_row = array();
1809 1809
 			$fields = $this->get_combined_primary_key_fields();
1810 1810
 			//note: because there' sno primary key, that means nothing else  can be pointing to this model, right?
1811
-			foreach($objects_for_deletion as  $delete_object){
1811
+			foreach ($objects_for_deletion as  $delete_object) {
1812 1812
 				$values_for_each_cpk_for_a_row = array();
1813
-				foreach($fields as $cpk_field){
1814
-					if ( $cpk_field instanceof EE_Model_Field_Base ){
1813
+				foreach ($fields as $cpk_field) {
1814
+					if ($cpk_field instanceof EE_Model_Field_Base) {
1815 1815
 						$values_for_each_cpk_for_a_row[] = $cpk_field->get_qualified_column()
1816 1816
 						                                   . "="
1817
-						                                   . $delete_object[ $cpk_field->get_qualified_column() ];
1817
+						                                   . $delete_object[$cpk_field->get_qualified_column()];
1818 1818
 					}
1819 1819
 				}
1820
-				$ways_to_identify_a_row[] = "(".implode(" AND ",$values_for_each_cpk_for_a_row).")";
1820
+				$ways_to_identify_a_row[] = "(".implode(" AND ", $values_for_each_cpk_for_a_row).")";
1821 1821
 			}
1822
-			return implode(" OR ",$ways_to_identify_a_row);
1823
-		}else{
1822
+			return implode(" OR ", $ways_to_identify_a_row);
1823
+		} else {
1824 1824
 			//so there's no primary key and no combined key...
1825 1825
 			//sorry, can't help you
1826
-			throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"),get_class($this)));
1826
+			throw new EE_Error(sprintf(__("Cannot delete objects of type %s because there is no primary key NOR combined key", "event_espresso"), get_class($this)));
1827 1827
 		}
1828 1828
 	}
1829 1829
 
@@ -1839,21 +1839,21 @@  discard block
 block discarded – undo
1839 1839
 	 * @return int
1840 1840
 	 * @throws \EE_Error
1841 1841
 	 */
1842
-	public function count($query_params =array(),$field_to_count = NULL, $distinct = FALSE){
1842
+	public function count($query_params = array(), $field_to_count = NULL, $distinct = FALSE) {
1843 1843
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1844
-		if($field_to_count){
1844
+		if ($field_to_count) {
1845 1845
 			$field_obj = $this->field_settings_for($field_to_count);
1846 1846
 			$column_to_count = $field_obj->get_qualified_column();
1847
-		}elseif($this->has_primary_key_field ()){
1847
+		}elseif ($this->has_primary_key_field()) {
1848 1848
 			$pk_field_obj = $this->get_primary_key_field();
1849 1849
 			$column_to_count = $pk_field_obj->get_qualified_column();
1850
-		}else{//there's no primary key
1850
+		} else {//there's no primary key
1851 1851
 			$column_to_count = '*';
1852 1852
 		}
1853 1853
 
1854
-		$column_to_count = $distinct ? "DISTINCT (" . $column_to_count . " )" : $column_to_count;
1855
-		$SQL ="SELECT COUNT(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1856
-		return (int)$this->_do_wpdb_query( 'get_var', array( $SQL) );
1854
+		$column_to_count = $distinct ? "DISTINCT (".$column_to_count." )" : $column_to_count;
1855
+		$SQL = "SELECT COUNT(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1856
+		return (int) $this->_do_wpdb_query('get_var', array($SQL));
1857 1857
 	}
1858 1858
 
1859 1859
 
@@ -1866,24 +1866,24 @@  discard block
 block discarded – undo
1866 1866
 	 * @return float
1867 1867
 	 * @throws \EE_Error
1868 1868
 	 */
1869
-	public function sum($query_params, $field_to_sum = NULL){
1869
+	public function sum($query_params, $field_to_sum = NULL) {
1870 1870
 		$model_query_info = $this->_create_model_query_info_carrier($query_params);
1871 1871
 
1872
-		if($field_to_sum){
1872
+		if ($field_to_sum) {
1873 1873
 			$field_obj = $this->field_settings_for($field_to_sum);
1874 1874
 
1875
-		}else{
1875
+		} else {
1876 1876
 			$field_obj = $this->get_primary_key_field();
1877 1877
 		}
1878 1878
 		$column_to_count = $field_obj->get_qualified_column();
1879 1879
 
1880
-		$SQL ="SELECT SUM(".$column_to_count.")" . $this->_construct_2nd_half_of_select_query($model_query_info);
1881
-		$return_value = $this->_do_wpdb_query('get_var',array( $SQL ) );
1880
+		$SQL = "SELECT SUM(".$column_to_count.")".$this->_construct_2nd_half_of_select_query($model_query_info);
1881
+		$return_value = $this->_do_wpdb_query('get_var', array($SQL));
1882 1882
 		$data_type = $field_obj->get_wpdb_data_type();
1883
-		if( $data_type === '%d' || $data_type === '%s' ){
1884
-			return (float)$return_value;
1885
-		}else{//must be %f
1886
-			return (float)$return_value;
1883
+		if ($data_type === '%d' || $data_type === '%s') {
1884
+			return (float) $return_value;
1885
+		} else {//must be %f
1886
+			return (float) $return_value;
1887 1887
 		}
1888 1888
 	}
1889 1889
 
@@ -1898,37 +1898,37 @@  discard block
 block discarded – undo
1898 1898
 	 * @global wpdb $wpdb
1899 1899
 	 * @return mixed
1900 1900
 	 */
1901
-	protected function _do_wpdb_query( $wpdb_method, $arguments_to_provide ){
1901
+	protected function _do_wpdb_query($wpdb_method, $arguments_to_provide) {
1902 1902
 		//if we're in maintenance mode level 2, DON'T run any queries
1903 1903
 		//because level 2 indicates the database needs updating and
1904 1904
 		//is probably out of sync with the code
1905
-		if( ! EE_Maintenance_Mode::instance()->models_can_query()){
1905
+		if ( ! EE_Maintenance_Mode::instance()->models_can_query()) {
1906 1906
 			throw new EE_Error(sprintf(__("Event Espresso Level 2 Maintenance mode is active. That means EE can not run ANY database queries until the necessary migration scripts have run which will take EE out of maintenance mode level 2. Please inform support of this error.", "event_espresso")));
1907 1907
 		}
1908 1908
 		/** @type WPDB $wpdb */
1909 1909
 		global $wpdb;
1910
-		if( ! method_exists( $wpdb, $wpdb_method ) ){
1911
-			throw new EE_Error( sprintf( __( 'There is no method named "%s" on Wordpress\' $wpdb object','event_espresso' ), $wpdb_method ) );
1910
+		if ( ! method_exists($wpdb, $wpdb_method)) {
1911
+			throw new EE_Error(sprintf(__('There is no method named "%s" on Wordpress\' $wpdb object', 'event_espresso'), $wpdb_method));
1912 1912
 		}
1913
-		if( WP_DEBUG ){
1913
+		if (WP_DEBUG) {
1914 1914
 			$old_show_errors_value = $wpdb->show_errors;
1915
-			$wpdb->show_errors( FALSE );
1916
-		}
1917
-		$result = $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide );
1918
-		$this->show_db_query_if_previously_requested( $wpdb->last_query );
1919
-		if( WP_DEBUG ){
1920
-			$wpdb->show_errors( $old_show_errors_value );
1921
-			if( ! empty( $wpdb->last_error ) ){
1922
-				throw new EE_Error( sprintf( __( 'WPDB Error: "%s"', 'event_espresso' ), $wpdb->last_error ) );
1923
-			}elseif( $result === false ){
1924
-				throw new EE_Error( sprintf( __( 'WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso' ), $wpdb_method, var_export( $arguments_to_provide, true ) ) );
1915
+			$wpdb->show_errors(FALSE);
1916
+		}
1917
+		$result = $this->_process_wpdb_query($wpdb_method, $arguments_to_provide);
1918
+		$this->show_db_query_if_previously_requested($wpdb->last_query);
1919
+		if (WP_DEBUG) {
1920
+			$wpdb->show_errors($old_show_errors_value);
1921
+			if ( ! empty($wpdb->last_error)) {
1922
+				throw new EE_Error(sprintf(__('WPDB Error: "%s"', 'event_espresso'), $wpdb->last_error));
1923
+			}elseif ($result === false) {
1924
+				throw new EE_Error(sprintf(__('WPDB Error occurred, but no error message was logged by wpdb! The wpdb method called was "%1$s" and the arguments were "%2$s"', 'event_espresso'), $wpdb_method, var_export($arguments_to_provide, true)));
1925 1925
 			}
1926
-		}elseif( $result === false ) {
1926
+		}elseif ($result === false) {
1927 1927
 			EE_Error::add_error(
1928 1928
 				sprintf(
1929
-					__( 'A database error has occurred. Turn on WP_DEBUG for more information.||A database error occurred doing wpdb method "%1$s", with arguments "%2$s". The error was "%3$s"', 'event_espresso' ),
1929
+					__('A database error has occurred. Turn on WP_DEBUG for more information.||A database error occurred doing wpdb method "%1$s", with arguments "%2$s". The error was "%3$s"', 'event_espresso'),
1930 1930
 					$wpdb_method,
1931
-					var_export( $arguments_to_provide, true ),
1931
+					var_export($arguments_to_provide, true),
1932 1932
 					$wpdb->last_error
1933 1933
 				),
1934 1934
 				__FILE__,
@@ -1950,26 +1950,26 @@  discard block
 block discarded – undo
1950 1950
 	 * @param array $arguments_to_provide
1951 1951
 	 * @return mixed
1952 1952
 	 */
1953
-	private function _process_wpdb_query( $wpdb_method, $arguments_to_provide ) {
1953
+	private function _process_wpdb_query($wpdb_method, $arguments_to_provide) {
1954 1954
 		/** @type WPDB $wpdb */
1955 1955
 		global $wpdb;
1956 1956
 		$wpdb->last_error = null;
1957
-		$result = call_user_func_array( array( $wpdb, $wpdb_method ), $arguments_to_provide );
1957
+		$result = call_user_func_array(array($wpdb, $wpdb_method), $arguments_to_provide);
1958 1958
 		// was there an error running the query? but we don't care on new activations
1959 1959
 		// (we're going to setup the DB anyway on new activations)
1960
-		if ( ( $result === false || ! empty( $wpdb->last_error ) )
1960
+		if (($result === false || ! empty($wpdb->last_error))
1961 1961
 			&& EE_System::instance()->detect_req_type() !== EE_System::req_type_new_activation
1962 1962
 		) {
1963
-			switch ( EEM_Base::$_db_verification_level ) {
1963
+			switch (EEM_Base::$_db_verification_level) {
1964 1964
 
1965 1965
 				case EEM_Base::db_verified_none :
1966 1966
 					// let's double-check core's DB
1967
-					$error_message = $this->_verify_core_db( $wpdb_method, $arguments_to_provide );
1967
+					$error_message = $this->_verify_core_db($wpdb_method, $arguments_to_provide);
1968 1968
 					break;
1969 1969
 
1970 1970
 				case EEM_Base::db_verified_core :
1971 1971
 					// STILL NO LOVE?? verify all the addons too. Maybe they need to be fixed
1972
-					$error_message = $this->_verify_addons_db( $wpdb_method, $arguments_to_provide );
1972
+					$error_message = $this->_verify_addons_db($wpdb_method, $arguments_to_provide);
1973 1973
 					break;
1974 1974
 
1975 1975
 				case EEM_Base::db_verified_addons :
@@ -1977,11 +1977,11 @@  discard block
 block discarded – undo
1977 1977
 					return $result;
1978 1978
 					break;
1979 1979
 			}
1980
-			if ( ! empty( $error_message ) ) {
1981
-				EE_Log::instance()->log( __FILE__, __FUNCTION__, $error_message, 'error' );
1982
-				trigger_error( $error_message );
1980
+			if ( ! empty($error_message)) {
1981
+				EE_Log::instance()->log(__FILE__, __FUNCTION__, $error_message, 'error');
1982
+				trigger_error($error_message);
1983 1983
 			}
1984
-			return $this->_process_wpdb_query( $wpdb_method, $arguments_to_provide );
1984
+			return $this->_process_wpdb_query($wpdb_method, $arguments_to_provide);
1985 1985
 
1986 1986
 		}
1987 1987
 
@@ -1997,18 +1997,18 @@  discard block
 block discarded – undo
1997 1997
 	 * @param array $arguments_to_provide
1998 1998
 	 * @return string
1999 1999
 	 */
2000
-	private function _verify_core_db( $wpdb_method, $arguments_to_provide ){
2000
+	private function _verify_core_db($wpdb_method, $arguments_to_provide) {
2001 2001
 		/** @type WPDB $wpdb */
2002 2002
 		global $wpdb;
2003 2003
 		//ok remember that we've already attempted fixing the core db, in case the problem persists
2004 2004
 		EEM_Base::$_db_verification_level = EEM_Base::db_verified_core;
2005 2005
 		$error_message = sprintf(
2006
-			__( 'WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso' ),
2006
+			__('WPDB Error "%1$s" while running wpdb method "%2$s" with arguments %3$s. Automatically attempting to fix EE Core DB', 'event_espresso'),
2007 2007
 			$wpdb->last_error,
2008 2008
 			$wpdb_method,
2009
-			json_encode( $arguments_to_provide )
2009
+			json_encode($arguments_to_provide)
2010 2010
 		);
2011
-		EE_System::instance()->initialize_db_if_no_migrations_required( false, true );
2011
+		EE_System::instance()->initialize_db_if_no_migrations_required(false, true);
2012 2012
 		return $error_message;
2013 2013
 	}
2014 2014
 
@@ -2021,16 +2021,16 @@  discard block
 block discarded – undo
2021 2021
 	 * @param $arguments_to_provide
2022 2022
 	 * @return string
2023 2023
 	 */
2024
-	private function _verify_addons_db( $wpdb_method, $arguments_to_provide ) {
2024
+	private function _verify_addons_db($wpdb_method, $arguments_to_provide) {
2025 2025
 		/** @type WPDB $wpdb */
2026 2026
 		global $wpdb;
2027 2027
 		//ok remember that we've already attempted fixing the addons dbs, in case the problem persists
2028 2028
 		EEM_Base::$_db_verification_level = EEM_Base::db_verified_addons;
2029 2029
 		$error_message = sprintf(
2030
-			__( 'WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso' ),
2030
+			__('WPDB AGAIN: Error "%1$s" while running the same method and arguments as before. Automatically attempting to fix EE Addons DB', 'event_espresso'),
2031 2031
 			$wpdb->last_error,
2032 2032
 			$wpdb_method,
2033
-			json_encode( $arguments_to_provide )
2033
+			json_encode($arguments_to_provide)
2034 2034
 		);
2035 2035
 		EE_System::instance()->initialize_addons();
2036 2036
 		return $error_message;
@@ -2045,7 +2045,7 @@  discard block
 block discarded – undo
2045 2045
 	 * @param EE_Model_Query_Info_Carrier $model_query_info
2046 2046
 	 * @return string
2047 2047
 	 */
2048
-	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info){
2048
+	private function _construct_2nd_half_of_select_query(EE_Model_Query_Info_Carrier $model_query_info) {
2049 2049
 		return " FROM ".$model_query_info->get_full_join_sql().
2050 2050
 				$model_query_info->get_where_sql().
2051 2051
 				$model_query_info->get_group_by_sql().
@@ -2058,7 +2058,7 @@  discard block
 block discarded – undo
2058 2058
 	 * Set to easily debug the next X queries ran from this model.
2059 2059
 	 * @param int $count
2060 2060
 	 */
2061
-	public function show_next_x_db_queries($count = 1){
2061
+	public function show_next_x_db_queries($count = 1) {
2062 2062
 		$this->_show_next_x_db_queries = $count;
2063 2063
 	}
2064 2064
 
@@ -2067,8 +2067,8 @@  discard block
 block discarded – undo
2067 2067
 	/**
2068 2068
 	 * @param $sql_query
2069 2069
 	 */
2070
-	public function show_db_query_if_previously_requested($sql_query){
2071
-		if($this->_show_next_x_db_queries > 0){
2070
+	public function show_db_query_if_previously_requested($sql_query) {
2071
+		if ($this->_show_next_x_db_queries > 0) {
2072 2072
 			echo $sql_query;
2073 2073
 			$this->_show_next_x_db_queries--;
2074 2074
 		}
@@ -2092,9 +2092,9 @@  discard block
 block discarded – undo
2092 2092
 	 * @return EE_Base_Class which was added as a relation. Object referred to by $other_model_id_or_obj
2093 2093
 	 * @throws \EE_Error
2094 2094
 	 */
2095
-	public function add_relationship_to($id_or_obj,$other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()){
2095
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $extra_join_model_fields_n_values = array()) {
2096 2096
 		$relation_obj = $this->related_settings_for($relationName);
2097
-		return $relation_obj->add_relation_to( $id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values);
2097
+		return $relation_obj->add_relation_to($id_or_obj, $other_model_id_or_obj, $extra_join_model_fields_n_values);
2098 2098
 	}
2099 2099
 
2100 2100
 
@@ -2113,9 +2113,9 @@  discard block
 block discarded – undo
2113 2113
 	 * @throws \EE_Error
2114 2114
 	 * @param array  $where_query  This allows you to enter further query params for the relation to for relation to methods that allow you to further specify extra columns to join by (such as HABTM).  Keep in mind that the only acceptable query_params is strict "col" => "value" pairs because these will be inserted in any new rows created as well.
2115 2115
 	 */
2116
-	public function remove_relationship_to($id_or_obj,  $other_model_id_or_obj, $relationName, $where_query= array() ){
2116
+	public function remove_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) {
2117 2117
 		$relation_obj = $this->related_settings_for($relationName);
2118
-		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query );
2118
+		return $relation_obj->remove_relation_to($id_or_obj, $other_model_id_or_obj, $where_query);
2119 2119
 	}
2120 2120
 
2121 2121
 
@@ -2128,9 +2128,9 @@  discard block
 block discarded – undo
2128 2128
 	 * @return \EE_Base_Class[]
2129 2129
 	 * @throws \EE_Error
2130 2130
 	 */
2131
-	public function remove_relations($id_or_obj,$relationName,$where_query_params = array()){
2131
+	public function remove_relations($id_or_obj, $relationName, $where_query_params = array()) {
2132 2132
 		$relation_obj = $this->related_settings_for($relationName);
2133
-		return $relation_obj->remove_relations($id_or_obj, $where_query_params );
2133
+		return $relation_obj->remove_relations($id_or_obj, $where_query_params);
2134 2134
 	}
2135 2135
 
2136 2136
 
@@ -2146,10 +2146,10 @@  discard block
 block discarded – undo
2146 2146
 	 * @return EE_Base_Class[]
2147 2147
 	 * @throws \EE_Error
2148 2148
 	 */
2149
-	public function get_all_related($id_or_obj, $model_name, $query_params = null){
2149
+	public function get_all_related($id_or_obj, $model_name, $query_params = null) {
2150 2150
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2151 2151
 		$relation_settings = $this->related_settings_for($model_name);
2152
-		return $relation_settings->get_all_related($model_obj,$query_params);
2152
+		return $relation_settings->get_all_related($model_obj, $query_params);
2153 2153
 	}
2154 2154
 
2155 2155
 
@@ -2166,10 +2166,10 @@  discard block
 block discarded – undo
2166 2166
 	 * @return int how many deleted
2167 2167
 	 * @throws \EE_Error
2168 2168
 	 */
2169
-	public function delete_related($id_or_obj,$model_name, $query_params = array()){
2169
+	public function delete_related($id_or_obj, $model_name, $query_params = array()) {
2170 2170
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2171 2171
 		$relation_settings = $this->related_settings_for($model_name);
2172
-		return $relation_settings->delete_all_related($model_obj,$query_params);
2172
+		return $relation_settings->delete_all_related($model_obj, $query_params);
2173 2173
 	}
2174 2174
 
2175 2175
 
@@ -2186,10 +2186,10 @@  discard block
 block discarded – undo
2186 2186
 	 * @return int how many deleted
2187 2187
 	 * @throws \EE_Error
2188 2188
 	 */
2189
-	public function delete_related_permanently($id_or_obj,$model_name, $query_params = array()){
2189
+	public function delete_related_permanently($id_or_obj, $model_name, $query_params = array()) {
2190 2190
 		$model_obj = $this->ensure_is_obj($id_or_obj);
2191 2191
 		$relation_settings = $this->related_settings_for($model_name);
2192
-		return $relation_settings->delete_related_permanently($model_obj,$query_params);
2192
+		return $relation_settings->delete_related_permanently($model_obj, $query_params);
2193 2193
 	}
2194 2194
 
2195 2195
 
@@ -2206,17 +2206,17 @@  discard block
 block discarded – undo
2206 2206
 	 * @return int
2207 2207
 	 * @throws \EE_Error
2208 2208
 	 */
2209
-	public function count_related($id_or_obj,$model_name,$query_params = array(),$field_to_count = null, $distinct = FALSE){
2209
+	public function count_related($id_or_obj, $model_name, $query_params = array(), $field_to_count = null, $distinct = FALSE) {
2210 2210
 		$related_model = $this->get_related_model_obj($model_name);
2211 2211
 		//we're just going to use the query params on the related model's normal get_all query,
2212 2212
 		//except add a condition to say to match the current mod
2213
-		if( ! isset($query_params['default_where_conditions'])){
2214
-			$query_params['default_where_conditions']='none';
2213
+		if ( ! isset($query_params['default_where_conditions'])) {
2214
+			$query_params['default_where_conditions'] = 'none';
2215 2215
 		}
2216 2216
 		$this_model_name = $this->get_this_model_name();
2217 2217
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
2218
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
2219
-		return $related_model->count($query_params,$field_to_count,$distinct);
2218
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
2219
+		return $related_model->count($query_params, $field_to_count, $distinct);
2220 2220
 	}
2221 2221
 
2222 2222
 
@@ -2232,21 +2232,21 @@  discard block
 block discarded – undo
2232 2232
 	 * @return float
2233 2233
 	 * @throws \EE_Error
2234 2234
 	 */
2235
-	public function sum_related($id_or_obj,$model_name,$query_params,$field_to_sum = null){
2235
+	public function sum_related($id_or_obj, $model_name, $query_params, $field_to_sum = null) {
2236 2236
 		$related_model = $this->get_related_model_obj($model_name);
2237
-		if( ! is_array( $query_params ) ){
2238
-			EE_Error::doing_it_wrong('EEM_Base::sum_related', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' );
2237
+		if ( ! is_array($query_params)) {
2238
+			EE_Error::doing_it_wrong('EEM_Base::sum_related', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0');
2239 2239
 			$query_params = array();
2240 2240
 		}
2241 2241
 		//we're just going to use the query params on the related model's normal get_all query,
2242 2242
 		//except add a condition to say to match the current mod
2243
-		if( ! isset($query_params['default_where_conditions'])){
2244
-			$query_params['default_where_conditions']='none';
2243
+		if ( ! isset($query_params['default_where_conditions'])) {
2244
+			$query_params['default_where_conditions'] = 'none';
2245 2245
 		}
2246 2246
 		$this_model_name = $this->get_this_model_name();
2247 2247
 		$this_pk_field_name = $this->get_primary_key_field()->get_name();
2248
-		$query_params[0][$this_model_name.".".$this_pk_field_name]=$id_or_obj;
2249
-		return $related_model->sum($query_params,$field_to_sum);
2248
+		$query_params[0][$this_model_name.".".$this_pk_field_name] = $id_or_obj;
2249
+		return $related_model->sum($query_params, $field_to_sum);
2250 2250
 	}
2251 2251
 
2252 2252
 
@@ -2260,12 +2260,12 @@  discard block
 block discarded – undo
2260 2260
 	 * @return EE_Base_Class
2261 2261
 	 * @throws \EE_Error
2262 2262
 	 */
2263
-	public function get_first_related( EE_Base_Class $id_or_obj, $other_model_name, $query_params ){
2264
-		$query_params['limit']=1;
2265
-		$results = $this->get_all_related($id_or_obj,$other_model_name,$query_params);
2266
-		if( $results ){
2263
+	public function get_first_related(EE_Base_Class $id_or_obj, $other_model_name, $query_params) {
2264
+		$query_params['limit'] = 1;
2265
+		$results = $this->get_all_related($id_or_obj, $other_model_name, $query_params);
2266
+		if ($results) {
2267 2267
 			return array_shift($results);
2268
-		}else{
2268
+		} else {
2269 2269
 			return null;
2270 2270
 		}
2271 2271
 
@@ -2275,8 +2275,8 @@  discard block
 block discarded – undo
2275 2275
 	 * Gets the model's name as it's expected in queries. For example, if this is EEM_Event model, that would be Event
2276 2276
 	 * @return string
2277 2277
 	 */
2278
-	public function get_this_model_name(){
2279
-		return str_replace("EEM_","",get_class($this));
2278
+	public function get_this_model_name() {
2279
+		return str_replace("EEM_", "", get_class($this));
2280 2280
 	}
2281 2281
 
2282 2282
 	/**
@@ -2284,14 +2284,14 @@  discard block
 block discarded – undo
2284 2284
 	 * @return EE_Any_Foreign_Model_Name_Field
2285 2285
 	 * @throws EE_Error
2286 2286
 	 */
2287
-	public function get_field_containing_related_model_name(){
2288
-		foreach($this->field_settings(true) as $field){
2289
-			if($field instanceof EE_Any_Foreign_Model_Name_Field){
2287
+	public function get_field_containing_related_model_name() {
2288
+		foreach ($this->field_settings(true) as $field) {
2289
+			if ($field instanceof EE_Any_Foreign_Model_Name_Field) {
2290 2290
 				$field_with_model_name = $field;
2291 2291
 			}
2292 2292
 		}
2293
-		if( !isset($field_with_model_name) || !$field_with_model_name ){
2294
-			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name() ));
2293
+		if ( ! isset($field_with_model_name) || ! $field_with_model_name) {
2294
+			throw new EE_Error(sprintf(__("There is no EE_Any_Foreign_Model_Name field on model %s", "event_espresso"), $this->get_this_model_name()));
2295 2295
 		}
2296 2296
 		return $field_with_model_name;
2297 2297
 	}
@@ -2312,19 +2312,19 @@  discard block
 block discarded – undo
2312 2312
 	 * @return int new primary key on main table that got inserted
2313 2313
 	 * @throws EE_Error
2314 2314
 	 */
2315
-	public function insert($field_n_values){
2315
+	public function insert($field_n_values) {
2316 2316
 		/**
2317 2317
 		 * Filters the fields and their values before inserting an item using the models
2318 2318
 		 * @param array $fields_n_values keys are the fields and values are their new values
2319 2319
 		 * @param EEM_Base $model the model used
2320 2320
 		 */
2321
-		$field_n_values = (array)apply_filters( 'FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this );
2322
-		if($this->_satisfies_unique_indexes($field_n_values)){
2321
+		$field_n_values = (array) apply_filters('FHEE__EEM_Base__insert__fields_n_values', $field_n_values, $this);
2322
+		if ($this->_satisfies_unique_indexes($field_n_values)) {
2323 2323
 			$main_table = $this->_get_main_table();
2324 2324
 			$new_id = $this->_insert_into_specific_table($main_table, $field_n_values, false);
2325
-			if( $new_id !== false ) {
2326
-				foreach($this->_get_other_tables() as $other_table){
2327
-					$this->_insert_into_specific_table($other_table, $field_n_values,$new_id);
2325
+			if ($new_id !== false) {
2326
+				foreach ($this->_get_other_tables() as $other_table) {
2327
+					$this->_insert_into_specific_table($other_table, $field_n_values, $new_id);
2328 2328
 				}
2329 2329
 			}
2330 2330
 			/**
@@ -2334,9 +2334,9 @@  discard block
 block discarded – undo
2334 2334
 			 * @param array $fields_n_values fields and their values
2335 2335
 			 * @param int|string the ID of the newly-inserted model object
2336 2336
 			 */
2337
-			do_action( 'AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id );
2337
+			do_action('AHEE__EEM_Base__insert__end', $this, $field_n_values, $new_id);
2338 2338
 			return $new_id;
2339
-		}else{
2339
+		} else {
2340 2340
 			return FALSE;
2341 2341
 		}
2342 2342
 	}
@@ -2351,10 +2351,10 @@  discard block
 block discarded – undo
2351 2351
 	 * @return boolean
2352 2352
 	 * @throws \EE_Error
2353 2353
 	 */
2354
-	protected function _satisfies_unique_indexes($field_n_values,$action = 'insert'){
2355
-		foreach($this->unique_indexes() as $index_name => $index){
2354
+	protected function _satisfies_unique_indexes($field_n_values, $action = 'insert') {
2355
+		foreach ($this->unique_indexes() as $index_name => $index) {
2356 2356
 			$uniqueness_where_params = array_intersect_key($field_n_values, $index->fields());
2357
-			if($this->exists(array($uniqueness_where_params))){
2357
+			if ($this->exists(array($uniqueness_where_params))) {
2358 2358
 				EE_Error::add_error(
2359 2359
 					sprintf(
2360 2360
 						__(
@@ -2364,8 +2364,8 @@  discard block
 block discarded – undo
2364 2364
 						$action,
2365 2365
 						$this->_get_class_name(),
2366 2366
 						$index_name,
2367
-						implode( ",", $index->field_names() ),
2368
-						http_build_query( $uniqueness_where_params )
2367
+						implode(",", $index->field_names()),
2368
+						http_build_query($uniqueness_where_params)
2369 2369
 					),
2370 2370
 					__FILE__,
2371 2371
 					__FUNCTION__,
@@ -2395,37 +2395,37 @@  discard block
 block discarded – undo
2395 2395
 	 * @throws EE_Error
2396 2396
 	 * @return EE_Base_Class|array
2397 2397
 	 */
2398
-	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true ){
2399
-		if($obj_or_fields_array instanceof EE_Base_Class){
2398
+	public function get_one_conflicting($obj_or_fields_array, $include_primary_key = true) {
2399
+		if ($obj_or_fields_array instanceof EE_Base_Class) {
2400 2400
 			$fields_n_values = $obj_or_fields_array->model_field_array();
2401
-		}elseif( is_array($obj_or_fields_array)){
2401
+		}elseif (is_array($obj_or_fields_array)) {
2402 2402
 			$fields_n_values = $obj_or_fields_array;
2403
-		}else{
2403
+		} else {
2404 2404
 			throw new EE_Error(
2405 2405
 				sprintf(
2406 2406
 					__(
2407 2407
 						"%s get_all_conflicting should be called with a model object or an array of field names and values, you provided %d",
2408 2408
 						"event_espresso"
2409 2409
 					),
2410
-					get_class( $this ),
2410
+					get_class($this),
2411 2411
 					$obj_or_fields_array
2412 2412
 				)
2413 2413
 			);
2414 2414
 		}
2415 2415
 		$query_params = array();
2416
-		if( $this->has_primary_key_field() &&
2417
-				( $include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
2418
-				isset($fields_n_values[$this->primary_key_name()])){
2416
+		if ($this->has_primary_key_field() &&
2417
+				($include_primary_key || $this->get_primary_key_field() instanceof EE_Primary_Key_String_Field) &&
2418
+				isset($fields_n_values[$this->primary_key_name()])) {
2419 2419
 			$query_params[0]['OR'][$this->primary_key_name()] = $fields_n_values[$this->primary_key_name()];
2420 2420
 		}
2421
-		foreach($this->unique_indexes() as $unique_index_name=>$unique_index){
2421
+		foreach ($this->unique_indexes() as $unique_index_name=>$unique_index) {
2422 2422
 			$uniqueness_where_params = array_intersect_key($fields_n_values, $unique_index->fields());
2423 2423
 			$query_params[0]['OR']['AND*'.$unique_index_name] = $uniqueness_where_params;
2424 2424
 		}
2425 2425
 		//if there is nothing to base this search on, then we shouldn't find anything
2426
-		if( empty( $query_params ) ){
2426
+		if (empty($query_params)) {
2427 2427
 			return array();
2428
-		}else{
2428
+		} else {
2429 2429
 			return $this->get_one($query_params);
2430 2430
 		}
2431 2431
 	}
@@ -2439,7 +2439,7 @@  discard block
 block discarded – undo
2439 2439
 	 * @return boolean
2440 2440
 	 * @throws \EE_Error
2441 2441
 	 */
2442
-	public function exists($query_params){
2442
+	public function exists($query_params) {
2443 2443
 		$query_params['limit'] = 1;
2444 2444
 		return $this->count($query_params) > 0;
2445 2445
 	}
@@ -2453,7 +2453,7 @@  discard block
 block discarded – undo
2453 2453
 	 * @return boolean
2454 2454
 	 * @throws \EE_Error
2455 2455
 	 */
2456
-	public function exists_by_ID($id){
2456
+	public function exists_by_ID($id) {
2457 2457
 		return $this->exists(array('default_where_conditions'=>'none', array($this->primary_key_name() => $id)));
2458 2458
 	}
2459 2459
 
@@ -2473,45 +2473,45 @@  discard block
 block discarded – undo
2473 2473
 	 * @global WPDB $wpdb only used to get the $wpdb->insert_id after performing an insert
2474 2474
 	 * @return int ID of new row inserted, or FALSE on failure
2475 2475
 	 */
2476
-	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0 ){
2476
+	protected function _insert_into_specific_table(EE_Table_Base $table, $fields_n_values, $new_id = 0) {
2477 2477
 		global $wpdb;
2478 2478
 		$insertion_col_n_values = array();
2479 2479
 		$format_for_insertion = array();
2480 2480
 		$fields_on_table = $this->_get_fields_for_table($table->get_table_alias());
2481
-		foreach($fields_on_table as $field_name => $field_obj){
2481
+		foreach ($fields_on_table as $field_name => $field_obj) {
2482 2482
 			//check if its an auto-incrementing column, in which case we should just leave it to do its autoincrement thing
2483
-			if($field_obj->is_auto_increment()){
2483
+			if ($field_obj->is_auto_increment()) {
2484 2484
 				continue;
2485 2485
 			}
2486 2486
 			$prepared_value = $this->_prepare_value_or_use_default($field_obj, $fields_n_values);
2487 2487
 			//if the value we want to assign it to is NULL, just don't mention it for the insertion
2488
-			if( $prepared_value !== NULL ){
2489
-				$insertion_col_n_values[ $field_obj->get_table_column() ] = $prepared_value;
2488
+			if ($prepared_value !== NULL) {
2489
+				$insertion_col_n_values[$field_obj->get_table_column()] = $prepared_value;
2490 2490
 				$format_for_insertion[] = $field_obj->get_wpdb_data_type();
2491 2491
 			}
2492 2492
 		}
2493 2493
 
2494
-		if($table instanceof EE_Secondary_Table && $new_id){
2494
+		if ($table instanceof EE_Secondary_Table && $new_id) {
2495 2495
 			//its not the main table, so we should have already saved the main table's PK which we just inserted
2496 2496
 			//so add the fk to the main table as a column
2497 2497
 			$insertion_col_n_values[$table->get_fk_on_table()] = $new_id;
2498
-			$format_for_insertion[]='%d';//yes right now we're only allowing these foreign keys to be INTs
2498
+			$format_for_insertion[] = '%d'; //yes right now we're only allowing these foreign keys to be INTs
2499 2499
 		}
2500 2500
 		//insert the new entry
2501
-		$result = $this->_do_wpdb_query( 'insert', array( $table->get_table_name(), $insertion_col_n_values, $format_for_insertion ) );
2502
-		if( $result === false ) {
2501
+		$result = $this->_do_wpdb_query('insert', array($table->get_table_name(), $insertion_col_n_values, $format_for_insertion));
2502
+		if ($result === false) {
2503 2503
 			return false;
2504 2504
 		}
2505 2505
 		//ok, now what do we return for the ID of the newly-inserted thing?
2506
-		if($this->has_primary_key_field()){
2507
-			if($this->get_primary_key_field()->is_auto_increment()){
2506
+		if ($this->has_primary_key_field()) {
2507
+			if ($this->get_primary_key_field()->is_auto_increment()) {
2508 2508
 				return $wpdb->insert_id;
2509
-			}else{
2509
+			} else {
2510 2510
 				//it's not an auto-increment primary key, so
2511 2511
 				//it must have been supplied
2512 2512
 				return $fields_n_values[$this->get_primary_key_field()->get_name()];
2513 2513
 			}
2514
-		}else{
2514
+		} else {
2515 2515
 			//we can't return a  primary key because there is none. instead return
2516 2516
 			//a unique string indicating this model
2517 2517
 			return $this->get_index_primary_key_string($fields_n_values);
@@ -2530,15 +2530,15 @@  discard block
 block discarded – undo
2530 2530
 	 * @return mixed string|int|float depending on what the table column will be expecting
2531 2531
 	 * @throws \EE_Error
2532 2532
 	 */
2533
-	protected function _prepare_value_or_use_default( $field_obj, $fields_n_values ){
2533
+	protected function _prepare_value_or_use_default($field_obj, $fields_n_values) {
2534 2534
 		//if this field doesn't allow nullable, don't allow it
2535
-		if( ! $field_obj->is_nullable() && (
2536
-				! isset( $fields_n_values[ $field_obj->get_name() ] ) ||
2537
-				$fields_n_values[ $field_obj->get_name() ] === NULL ) ){
2538
-			$fields_n_values[ $field_obj->get_name() ] = $field_obj->get_default_value();
2535
+		if ( ! $field_obj->is_nullable() && (
2536
+				! isset($fields_n_values[$field_obj->get_name()]) ||
2537
+				$fields_n_values[$field_obj->get_name()] === NULL )) {
2538
+			$fields_n_values[$field_obj->get_name()] = $field_obj->get_default_value();
2539 2539
 		}
2540
-		$unprepared_value = isset( $fields_n_values[ $field_obj->get_name() ] ) ? $fields_n_values[ $field_obj->get_name() ] : NULL;
2541
-		return $this->_prepare_value_for_use_in_db( $unprepared_value, $field_obj);
2540
+		$unprepared_value = isset($fields_n_values[$field_obj->get_name()]) ? $fields_n_values[$field_obj->get_name()] : NULL;
2541
+		return $this->_prepare_value_for_use_in_db($unprepared_value, $field_obj);
2542 2542
 	}
2543 2543
 
2544 2544
 
@@ -2550,9 +2550,9 @@  discard block
 block discarded – undo
2550 2550
 	 * @param EE_Model_Field_Base $field field which will be doing the preparing of the value. If null, we assume $value is a custom selection
2551 2551
 	 * @return mixed a value ready for use in the database for insertions, updating, or in a where clause
2552 2552
 	 */
2553
-	private function _prepare_value_for_use_in_db($value, $field){
2554
-		if($field && $field instanceof EE_Model_Field_Base){
2555
-			switch( $this->_values_already_prepared_by_model_object ){
2553
+	private function _prepare_value_for_use_in_db($value, $field) {
2554
+		if ($field && $field instanceof EE_Model_Field_Base) {
2555
+			switch ($this->_values_already_prepared_by_model_object) {
2556 2556
 				/** @noinspection PhpMissingBreakStatementInspection */
2557 2557
 				case self::not_prepared_by_model_object:
2558 2558
 					$value = $field->prepare_for_set($value);
@@ -2563,7 +2563,7 @@  discard block
 block discarded – undo
2563 2563
 					//leave the value alone
2564 2564
 			}
2565 2565
 			return $value;
2566
-		}else{
2566
+		} else {
2567 2567
 			return $value;
2568 2568
 		}
2569 2569
 	}
@@ -2573,13 +2573,13 @@  discard block
 block discarded – undo
2573 2573
 	 * @return EE_Primary_Table
2574 2574
 	 * @throws EE_Error
2575 2575
 	 */
2576
-	protected function _get_main_table(){
2577
-		foreach($this->_tables as $table){
2578
-			if($table instanceof EE_Primary_Table){
2576
+	protected function _get_main_table() {
2577
+		foreach ($this->_tables as $table) {
2578
+			if ($table instanceof EE_Primary_Table) {
2579 2579
 				return $table;
2580 2580
 			}
2581 2581
 		}
2582
-		throw new EE_Error(sprintf(__('There are no main tables on %s. They should be added to _tables array in the constructor','event_espresso'),get_class($this)));
2582
+		throw new EE_Error(sprintf(__('There are no main tables on %s. They should be added to _tables array in the constructor', 'event_espresso'), get_class($this)));
2583 2583
 	}
2584 2584
 
2585 2585
 
@@ -2602,7 +2602,7 @@  discard block
 block discarded – undo
2602 2602
 	 */
2603 2603
 	public function second_table() {
2604 2604
 		// grab second table from tables array
2605
-		$second_table = end( $this->_tables );
2605
+		$second_table = end($this->_tables);
2606 2606
 		return $second_table instanceof EE_Secondary_Table ? $second_table->get_table_name() : NULL;
2607 2607
 	}
2608 2608
 
@@ -2615,8 +2615,8 @@  discard block
 block discarded – undo
2615 2615
 	 * @param string $table_alias
2616 2616
 	 * @return EE_Primary_Table | EE_Secondary_Table
2617 2617
 	 */
2618
-	public function get_table_obj_by_alias( $table_alias = '' ) {
2619
-		return isset( $this->_tables[ $table_alias ] ) ? $this->_tables[ $table_alias ] : NULL;
2618
+	public function get_table_obj_by_alias($table_alias = '') {
2619
+		return isset($this->_tables[$table_alias]) ? $this->_tables[$table_alias] : NULL;
2620 2620
 	}
2621 2621
 
2622 2622
 
@@ -2625,10 +2625,10 @@  discard block
 block discarded – undo
2625 2625
 	 * Gets all the tables of type EE_Other_Table from EEM_CPT_Basel_Model::_tables
2626 2626
 	 * @return EE_Secondary_Table[]
2627 2627
 	 */
2628
-	protected function _get_other_tables(){
2629
-		$other_tables =array();
2630
-		foreach($this->_tables as $table_alias => $table){
2631
-			if($table instanceof EE_Secondary_Table){
2628
+	protected function _get_other_tables() {
2629
+		$other_tables = array();
2630
+		foreach ($this->_tables as $table_alias => $table) {
2631
+			if ($table instanceof EE_Secondary_Table) {
2632 2632
 				$other_tables[$table_alias] = $table;
2633 2633
 			}
2634 2634
 		}
@@ -2640,7 +2640,7 @@  discard block
 block discarded – undo
2640 2640
 	 * @param string $table_alias, array key in EEM_Base::_tables
2641 2641
 	 * @return EE_Model_Field_Base[]
2642 2642
 	 */
2643
-	public function _get_fields_for_table($table_alias){
2643
+	public function _get_fields_for_table($table_alias) {
2644 2644
 		return $this->_fields[$table_alias];
2645 2645
 	}
2646 2646
 
@@ -2656,19 +2656,19 @@  discard block
 block discarded – undo
2656 2656
 	 * @return EE_Model_Query_Info_Carrier
2657 2657
 	 * @throws \EE_Error
2658 2658
 	 */
2659
-	public function _extract_related_models_from_query($query_params){
2659
+	public function _extract_related_models_from_query($query_params) {
2660 2660
 		$query_info_carrier = new EE_Model_Query_Info_Carrier();
2661
-		if ( array_key_exists( 0, $query_params ) ) {
2662
-			$this->_extract_related_models_from_sub_params_array_keys( $query_params[0], $query_info_carrier, 0 );
2661
+		if (array_key_exists(0, $query_params)) {
2662
+			$this->_extract_related_models_from_sub_params_array_keys($query_params[0], $query_info_carrier, 0);
2663 2663
 		}
2664
-		if ( array_key_exists( 'group_by', $query_params ) ) {
2665
-			if ( is_array( $query_params['group_by'] ) ) {
2664
+		if (array_key_exists('group_by', $query_params)) {
2665
+			if (is_array($query_params['group_by'])) {
2666 2666
 				$this->_extract_related_models_from_sub_params_array_values(
2667 2667
 					$query_params['group_by'],
2668 2668
 					$query_info_carrier,
2669 2669
 					'group_by'
2670 2670
 				);
2671
-			} elseif ( ! empty ( $query_params['group_by'] ) ) {
2671
+			} elseif ( ! empty ($query_params['group_by'])) {
2672 2672
 				$this->_extract_related_model_info_from_query_param(
2673 2673
 					$query_params['group_by'],
2674 2674
 					$query_info_carrier,
@@ -2676,21 +2676,21 @@  discard block
 block discarded – undo
2676 2676
 				);
2677 2677
 			}
2678 2678
 		}
2679
-		if ( array_key_exists( 'having', $query_params ) ) {
2679
+		if (array_key_exists('having', $query_params)) {
2680 2680
 			$this->_extract_related_models_from_sub_params_array_keys(
2681 2681
 				$query_params[0],
2682 2682
 				$query_info_carrier,
2683 2683
 				'having'
2684 2684
 			);
2685 2685
 		}
2686
-		if ( array_key_exists( 'order_by', $query_params ) ) {
2687
-			if ( is_array( $query_params['order_by'] ) ) {
2686
+		if (array_key_exists('order_by', $query_params)) {
2687
+			if (is_array($query_params['order_by'])) {
2688 2688
 				$this->_extract_related_models_from_sub_params_array_keys(
2689 2689
 					$query_params['order_by'],
2690 2690
 					$query_info_carrier,
2691 2691
 					'order_by'
2692 2692
 				);
2693
-			} elseif ( ! empty( $query_params['order_by'] ) ) {
2693
+			} elseif ( ! empty($query_params['order_by'])) {
2694 2694
 				$this->_extract_related_model_info_from_query_param(
2695 2695
 					$query_params['order_by'],
2696 2696
 					$query_info_carrier,
@@ -2698,7 +2698,7 @@  discard block
 block discarded – undo
2698 2698
 				);
2699 2699
 			}
2700 2700
 		}
2701
-		if ( array_key_exists( 'force_join', $query_params ) ) {
2701
+		if (array_key_exists('force_join', $query_params)) {
2702 2702
 			$this->_extract_related_models_from_sub_params_array_values(
2703 2703
 				$query_params['force_join'],
2704 2704
 				$query_info_carrier,
@@ -2716,34 +2716,34 @@  discard block
 block discarded – undo
2716 2716
 	 * @throws EE_Error
2717 2717
 	 * @return \EE_Model_Query_Info_Carrier
2718 2718
 	 */
2719
-	private function _extract_related_models_from_sub_params_array_keys($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier,$query_param_type){
2720
-		if (!empty($sub_query_params)){
2719
+	private function _extract_related_models_from_sub_params_array_keys($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier, $query_param_type) {
2720
+		if ( ! empty($sub_query_params)) {
2721 2721
 			$sub_query_params = (array) $sub_query_params;
2722
-			foreach($sub_query_params as $param => $possibly_array_of_params){
2722
+			foreach ($sub_query_params as $param => $possibly_array_of_params) {
2723 2723
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2724
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier,$query_param_type);
2724
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2725 2725
 
2726 2726
 				//if $possibly_array_of_params is an array, try recursing into it, searching for keys which
2727 2727
 				//indicate needed joins. Eg, array('NOT'=>array('Registration.TXN_ID'=>23)). In this case, we tried
2728 2728
 				//extracting models out of the 'NOT', which obviously wasn't successful, and then we recurse into the value
2729 2729
 				//of array('Registration.TXN_ID'=>23)
2730 2730
 				$query_param_sans_stars = $this->_remove_stars_and_anything_after_from_condition_query_param_key($param);
2731
-				if(in_array($query_param_sans_stars, $this->_logic_query_param_keys,true)){
2732
-					if (! is_array($possibly_array_of_params)){
2731
+				if (in_array($query_param_sans_stars, $this->_logic_query_param_keys, true)) {
2732
+					if ( ! is_array($possibly_array_of_params)) {
2733 2733
 						throw new EE_Error(sprintf(__("You used a special where query param %s, but the value isn't an array of where query params, it's just %s'. It should be an array, eg array('EVT_ID'=>23,'OR'=>array('Venue.VNU_ID'=>32,'Venue.VNU_name'=>'monkey_land'))", "event_espresso"),
2734
-							$param,$possibly_array_of_params));
2735
-					}else{
2736
-						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier,$query_param_type);
2734
+							$param, $possibly_array_of_params));
2735
+					} else {
2736
+						$this->_extract_related_models_from_sub_params_array_keys($possibly_array_of_params, $model_query_info_carrier, $query_param_type);
2737 2737
 					}
2738
-				}elseif($query_param_type === 0 //ie WHERE
2738
+				}elseif ($query_param_type === 0 //ie WHERE
2739 2739
 						&& is_array($possibly_array_of_params)
2740 2740
 						&& isset($possibly_array_of_params[2])
2741
-						&& $possibly_array_of_params[2] == true){
2741
+						&& $possibly_array_of_params[2] == true) {
2742 2742
 					//then $possible_array_of_params looks something like array('<','DTT_sold',true)
2743 2743
 					//indicating that $possible_array_of_params[1] is actually a field name,
2744 2744
 					//from which we should extract query parameters!
2745
-					if( ! isset($possibly_array_of_params[0], $possibly_array_of_params[1] ) ) {
2746
-						throw new EE_Error(sprintf(__("Improperly formed query parameter %s. It should be numerically indexed like array('<','DTT_sold',true); but you provided %s", "event_espresso"),$query_param_type,implode(",",$possibly_array_of_params)));
2745
+					if ( ! isset($possibly_array_of_params[0], $possibly_array_of_params[1])) {
2746
+						throw new EE_Error(sprintf(__("Improperly formed query parameter %s. It should be numerically indexed like array('<','DTT_sold',true); but you provided %s", "event_espresso"), $query_param_type, implode(",", $possibly_array_of_params)));
2747 2747
 					}
2748 2748
 					$this->_extract_related_model_info_from_query_param($possibly_array_of_params[1], $model_query_info_carrier, $query_param_type);
2749 2749
 				}
@@ -2762,14 +2762,14 @@  discard block
 block discarded – undo
2762 2762
 	 * @throws EE_Error
2763 2763
 	 * @return \EE_Model_Query_Info_Carrier
2764 2764
 	 */
2765
-	private function _extract_related_models_from_sub_params_array_values($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier,$query_param_type){
2766
-		if (!empty($sub_query_params)){
2767
-			if(!is_array($sub_query_params)){
2768
-				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"),$sub_query_params));
2765
+	private function _extract_related_models_from_sub_params_array_values($sub_query_params, EE_Model_Query_Info_Carrier $model_query_info_carrier, $query_param_type) {
2766
+		if ( ! empty($sub_query_params)) {
2767
+			if ( ! is_array($sub_query_params)) {
2768
+				throw new EE_Error(sprintf(__("Query parameter %s should be an array, but it isn't.", "event_espresso"), $sub_query_params));
2769 2769
 			}
2770
-			foreach($sub_query_params as $param){
2770
+			foreach ($sub_query_params as $param) {
2771 2771
 				//$param could be simply 'EVT_ID', or it could be 'Registrations.REG_ID', or even 'Registrations.Transactions.Payments.PAY_amount'
2772
-				$this->_extract_related_model_info_from_query_param( $param, $model_query_info_carrier, $query_param_type);
2772
+				$this->_extract_related_model_info_from_query_param($param, $model_query_info_carrier, $query_param_type);
2773 2773
 			}
2774 2774
 		}
2775 2775
 		return $model_query_info_carrier;
@@ -2788,8 +2788,8 @@  discard block
 block discarded – undo
2788 2788
 	 * @throws EE_Error
2789 2789
 	 * @return EE_Model_Query_Info_Carrier
2790 2790
 	 */
2791
-	public function _create_model_query_info_carrier($query_params){
2792
-		if ( ! is_array( $query_params ) ) {
2791
+	public function _create_model_query_info_carrier($query_params) {
2792
+		if ( ! is_array($query_params)) {
2793 2793
 			EE_Error::doing_it_wrong(
2794 2794
 				'EEM_Base::_create_model_query_info_carrier',
2795 2795
 				sprintf(
@@ -2797,16 +2797,16 @@  discard block
 block discarded – undo
2797 2797
 						'$query_params should be an array, you passed a variable of type %s',
2798 2798
 						'event_espresso'
2799 2799
 					),
2800
-					gettype( $query_params )
2800
+					gettype($query_params)
2801 2801
 				),
2802 2802
 				'4.6.0'
2803 2803
 			);
2804 2804
 			$query_params = array();
2805 2805
 		}
2806
-		$where_query_params = isset( $query_params[0] ) ? $query_params[0] : array();
2806
+		$where_query_params = isset($query_params[0]) ? $query_params[0] : array();
2807 2807
 		//first check if we should alter the query to account for caps or not
2808 2808
 		//because the caps might require us to do extra joins
2809
-		if ( isset( $query_params['caps'] ) && $query_params['caps'] !== 'none' ) {
2809
+		if (isset($query_params['caps']) && $query_params['caps'] !== 'none') {
2810 2810
 			$query_params[0] = $where_query_params = array_replace_recursive(
2811 2811
 				$where_query_params,
2812 2812
 				$this->caps_where_conditions(
@@ -2814,10 +2814,10 @@  discard block
 block discarded – undo
2814 2814
 				)
2815 2815
 			);
2816 2816
 		}
2817
-		$query_object = $this->_extract_related_models_from_query( $query_params );
2817
+		$query_object = $this->_extract_related_models_from_query($query_params);
2818 2818
 		//verify where_query_params has NO numeric indexes.... that's simply not how you use it!
2819
-		foreach ( $where_query_params as $key => $value ) {
2820
-			if ( is_int( $key ) ) {
2819
+		foreach ($where_query_params as $key => $value) {
2820
+			if (is_int($key)) {
2821 2821
 				throw new EE_Error(
2822 2822
 					sprintf(
2823 2823
 						__(
@@ -2825,16 +2825,16 @@  discard block
 block discarded – undo
2825 2825
 							"event_espresso"
2826 2826
 						),
2827 2827
 						$key,
2828
-						var_export( $value, true ),
2829
-						var_export( $query_params, true ),
2830
-						get_class( $this )
2828
+						var_export($value, true),
2829
+						var_export($query_params, true),
2830
+						get_class($this)
2831 2831
 					)
2832 2832
 				);
2833 2833
 			}
2834 2834
 		}
2835 2835
 		if (
2836
-			array_key_exists( 'default_where_conditions', $query_params )
2837
-			&& ! empty( $query_params['default_where_conditions'] )
2836
+			array_key_exists('default_where_conditions', $query_params)
2837
+			&& ! empty($query_params['default_where_conditions'])
2838 2838
 		) {
2839 2839
 			$use_default_where_conditions = $query_params['default_where_conditions'];
2840 2840
 		} else {
@@ -2848,13 +2848,13 @@  discard block
 block discarded – undo
2848 2848
 			),
2849 2849
 			$where_query_params
2850 2850
 		);
2851
-		$query_object->set_where_sql( $this->_construct_where_clause( $where_query_params ) );
2851
+		$query_object->set_where_sql($this->_construct_where_clause($where_query_params));
2852 2852
 		// if this is a "on_join_limit" then we are limiting on on a specific table in a multi_table join.
2853 2853
 		// So we need to setup a subquery and use that for the main join.
2854 2854
 		// Note for now this only works on the primary table for the model.
2855 2855
 		// So for instance, you could set the limit array like this:
2856 2856
 		// array( 'on_join_limit' => array('Primary_Table_Alias', array(1,10) ) )
2857
-		if ( array_key_exists( 'on_join_limit', $query_params ) && ! empty( $query_params['on_join_limit'] ) ) {
2857
+		if (array_key_exists('on_join_limit', $query_params) && ! empty($query_params['on_join_limit'])) {
2858 2858
 			$query_object->set_main_model_join_sql(
2859 2859
 				$this->_construct_limit_join_select(
2860 2860
 					$query_params['on_join_limit'][0],
@@ -2863,40 +2863,40 @@  discard block
 block discarded – undo
2863 2863
 			);
2864 2864
 		}
2865 2865
 		//set limit
2866
-		if ( array_key_exists( 'limit', $query_params ) ) {
2867
-			if ( is_array( $query_params['limit'] ) ) {
2868
-				if ( ! isset( $query_params['limit'][0], $query_params['limit'][1] ) ) {
2866
+		if (array_key_exists('limit', $query_params)) {
2867
+			if (is_array($query_params['limit'])) {
2868
+				if ( ! isset($query_params['limit'][0], $query_params['limit'][1])) {
2869 2869
 					$e = sprintf(
2870 2870
 						__(
2871 2871
 							"Invalid DB query. You passed '%s' for the LIMIT, but only the following are valid: an integer, string representing an integer, a string like 'int,int', or an array like array(int,int)",
2872 2872
 							"event_espresso"
2873 2873
 						),
2874
-						http_build_query( $query_params['limit'] )
2874
+						http_build_query($query_params['limit'])
2875 2875
 					);
2876
-					throw new EE_Error( $e . "|" . $e );
2876
+					throw new EE_Error($e."|".$e);
2877 2877
 				}
2878 2878
 				//they passed us an array for the limit. Assume it's like array(50,25), meaning offset by 50, and get 25
2879
-				$query_object->set_limit_sql( " LIMIT " . $query_params['limit'][0] . "," . $query_params['limit'][1] );
2880
-			} elseif ( ! empty ( $query_params['limit'] ) ) {
2881
-				$query_object->set_limit_sql( " LIMIT " . $query_params['limit'] );
2879
+				$query_object->set_limit_sql(" LIMIT ".$query_params['limit'][0].",".$query_params['limit'][1]);
2880
+			} elseif ( ! empty ($query_params['limit'])) {
2881
+				$query_object->set_limit_sql(" LIMIT ".$query_params['limit']);
2882 2882
 			}
2883 2883
 		}
2884 2884
 		//set order by
2885
-		if ( array_key_exists( 'order_by', $query_params ) ) {
2886
-			if ( is_array( $query_params['order_by'] ) ) {
2885
+		if (array_key_exists('order_by', $query_params)) {
2886
+			if (is_array($query_params['order_by'])) {
2887 2887
 				//if they're using 'order_by' as an array, they can't use 'order' (because 'order_by' must
2888 2888
 				//specify whether to ascend or descend on each field. Eg 'order_by'=>array('EVT_ID'=>'ASC'). So
2889 2889
 				//including 'order' wouldn't make any sense if 'order_by' has already specified which way to order!
2890
-				if ( array_key_exists( 'order', $query_params ) ) {
2890
+				if (array_key_exists('order', $query_params)) {
2891 2891
 					throw new EE_Error(
2892 2892
 						sprintf(
2893 2893
 							__(
2894 2894
 								"In querying %s, we are using query parameter 'order_by' as an array (keys:%s,values:%s), and so we can't use query parameter 'order' (value %s). You should just use the 'order_by' parameter ",
2895 2895
 								"event_espresso"
2896 2896
 							),
2897
-							get_class( $this ),
2898
-							implode( ", ", array_keys( $query_params['order_by'] ) ),
2899
-							implode( ", ", $query_params['order_by'] ),
2897
+							get_class($this),
2898
+							implode(", ", array_keys($query_params['order_by'])),
2899
+							implode(", ", $query_params['order_by']),
2900 2900
 							$query_params['order']
2901 2901
 						)
2902 2902
 					);
@@ -2908,57 +2908,57 @@  discard block
 block discarded – undo
2908 2908
 				);
2909 2909
 				//assume it's an array of fields to order by
2910 2910
 				$order_array = array();
2911
-				foreach ( $query_params['order_by'] as $field_name_to_order_by => $order ) {
2912
-					$order = $this->_extract_order( $order );
2913
-					$order_array[] = $this->_deduce_column_name_from_query_param( $field_name_to_order_by ) . SP . $order;
2911
+				foreach ($query_params['order_by'] as $field_name_to_order_by => $order) {
2912
+					$order = $this->_extract_order($order);
2913
+					$order_array[] = $this->_deduce_column_name_from_query_param($field_name_to_order_by).SP.$order;
2914 2914
 				}
2915
-				$query_object->set_order_by_sql( " ORDER BY " . implode( ",", $order_array ) );
2916
-			} elseif ( ! empty ( $query_params['order_by'] ) ) {
2915
+				$query_object->set_order_by_sql(" ORDER BY ".implode(",", $order_array));
2916
+			} elseif ( ! empty ($query_params['order_by'])) {
2917 2917
 				$this->_extract_related_model_info_from_query_param(
2918 2918
 					$query_params['order_by'],
2919 2919
 					$query_object,
2920 2920
 					'order',
2921 2921
 					$query_params['order_by']
2922 2922
 				);
2923
-				$order = isset( $query_params['order'] )
2924
-					? $this->_extract_order( $query_params['order'] )
2923
+				$order = isset($query_params['order'])
2924
+					? $this->_extract_order($query_params['order'])
2925 2925
 					: 'DESC';
2926 2926
 				$query_object->set_order_by_sql(
2927
-					" ORDER BY " . $this->_deduce_column_name_from_query_param( $query_params['order_by'] ) . SP . $order
2927
+					" ORDER BY ".$this->_deduce_column_name_from_query_param($query_params['order_by']).SP.$order
2928 2928
 				);
2929 2929
 			}
2930 2930
 		}
2931 2931
 		//if 'order_by' wasn't set, maybe they are just using 'order' on its own?
2932
-		if ( ! array_key_exists( 'order_by', $query_params )
2933
-		     && array_key_exists( 'order', $query_params )
2934
-		     && ! empty( $query_params['order'] )
2932
+		if ( ! array_key_exists('order_by', $query_params)
2933
+		     && array_key_exists('order', $query_params)
2934
+		     && ! empty($query_params['order'])
2935 2935
 		) {
2936 2936
 			$pk_field = $this->get_primary_key_field();
2937
-			$order = $this->_extract_order( $query_params['order'] );
2938
-			$query_object->set_order_by_sql( " ORDER BY " . $pk_field->get_qualified_column() . SP . $order );
2937
+			$order = $this->_extract_order($query_params['order']);
2938
+			$query_object->set_order_by_sql(" ORDER BY ".$pk_field->get_qualified_column().SP.$order);
2939 2939
 		}
2940 2940
 		//set group by
2941
-		if ( array_key_exists( 'group_by', $query_params ) ) {
2942
-			if ( is_array( $query_params['group_by'] ) ) {
2941
+		if (array_key_exists('group_by', $query_params)) {
2942
+			if (is_array($query_params['group_by'])) {
2943 2943
 				//it's an array, so assume we'll be grouping by a bunch of stuff
2944 2944
 				$group_by_array = array();
2945
-				foreach ( $query_params['group_by'] as $field_name_to_group_by ) {
2946
-					$group_by_array[] = $this->_deduce_column_name_from_query_param( $field_name_to_group_by );
2945
+				foreach ($query_params['group_by'] as $field_name_to_group_by) {
2946
+					$group_by_array[] = $this->_deduce_column_name_from_query_param($field_name_to_group_by);
2947 2947
 				}
2948
-				$query_object->set_group_by_sql( " GROUP BY " . implode( ", ", $group_by_array ) );
2949
-			} elseif ( ! empty ( $query_params['group_by'] ) ) {
2948
+				$query_object->set_group_by_sql(" GROUP BY ".implode(", ", $group_by_array));
2949
+			} elseif ( ! empty ($query_params['group_by'])) {
2950 2950
 				$query_object->set_group_by_sql(
2951
-					" GROUP BY " . $this->_deduce_column_name_from_query_param( $query_params['group_by'] )
2951
+					" GROUP BY ".$this->_deduce_column_name_from_query_param($query_params['group_by'])
2952 2952
 				);
2953 2953
 			}
2954 2954
 		}
2955 2955
 		//set having
2956
-		if ( array_key_exists( 'having', $query_params ) && $query_params['having'] ) {
2957
-			$query_object->set_having_sql( $this->_construct_having_clause( $query_params['having'] ) );
2956
+		if (array_key_exists('having', $query_params) && $query_params['having']) {
2957
+			$query_object->set_having_sql($this->_construct_having_clause($query_params['having']));
2958 2958
 		}
2959 2959
 		//now, just verify they didn't pass anything wack
2960
-		foreach ( $query_params as $query_key => $query_value ) {
2961
-			if ( ! in_array( $query_key, $this->_allowed_query_params, true ) ) {
2960
+		foreach ($query_params as $query_key => $query_value) {
2961
+			if ( ! in_array($query_key, $this->_allowed_query_params, true)) {
2962 2962
 				throw new EE_Error(
2963 2963
 					sprintf(
2964 2964
 						__(
@@ -2966,16 +2966,16 @@  discard block
 block discarded – undo
2966 2966
 							'event_espresso'
2967 2967
 						),
2968 2968
 						$query_key,
2969
-						get_class( $this ),
2969
+						get_class($this),
2970 2970
 //						print_r( $this->_allowed_query_params, TRUE )
2971
-						implode( ',', $this->_allowed_query_params )
2971
+						implode(',', $this->_allowed_query_params)
2972 2972
 					)
2973 2973
 				);
2974 2974
 			}
2975 2975
 		}
2976 2976
 		$main_model_join_sql = $query_object->get_main_model_join_sql();
2977
-		if ( empty( $main_model_join_sql ) ) {
2978
-			$query_object->set_main_model_join_sql( $this->_construct_internal_join() );
2977
+		if (empty($main_model_join_sql)) {
2978
+			$query_object->set_main_model_join_sql($this->_construct_internal_join());
2979 2979
 		}
2980 2980
 		return $query_object;
2981 2981
 	}
@@ -2990,17 +2990,17 @@  discard block
 block discarded – undo
2990 2990
 	 * @return array like EEM_Base::get_all() 's $query_params[0]
2991 2991
 	 * @throws \EE_Error
2992 2992
 	 */
2993
-	public function caps_where_conditions( $context = self::caps_read ) {
2994
-		EEM_Base::verify_is_valid_cap_context( $context );
2993
+	public function caps_where_conditions($context = self::caps_read) {
2994
+		EEM_Base::verify_is_valid_cap_context($context);
2995 2995
 		$cap_where_conditions = array();
2996
-		$cap_restrictions = $this->caps_missing( $context );
2996
+		$cap_restrictions = $this->caps_missing($context);
2997 2997
 		/**
2998 2998
 		 * @var $cap_restrictions EE_Default_Where_Conditions[]
2999 2999
 		 */
3000
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
3001
-				$cap_where_conditions = array_replace_recursive( $cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions() );
3000
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
3001
+				$cap_where_conditions = array_replace_recursive($cap_where_conditions, $restriction_if_no_cap->get_default_where_conditions());
3002 3002
 		}
3003
-		return apply_filters( 'FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions );
3003
+		return apply_filters('FHEE__EEM_Base__caps_where_conditions__return', $cap_where_conditions, $this, $context, $cap_restrictions);
3004 3004
 	}
3005 3005
 
3006 3006
 	/**
@@ -3010,11 +3010,11 @@  discard block
 block discarded – undo
3010 3010
 	 * @return string either ASC, asc, DESC or desc
3011 3011
 	 * @throws EE_Error
3012 3012
 	 */
3013
-	private function _extract_order($should_be_order_string){
3014
-		if(in_array($should_be_order_string, $this->_allowed_order_values)){
3013
+	private function _extract_order($should_be_order_string) {
3014
+		if (in_array($should_be_order_string, $this->_allowed_order_values)) {
3015 3015
 			return $should_be_order_string;
3016
-		}else{
3017
-			throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"),get_class($this),$should_be_order_string));
3016
+		} else {
3017
+			throw new EE_Error(sprintf(__("While performing a query on '%s', tried to use '%s' as an order parameter. ", "event_espresso"), get_class($this), $should_be_order_string));
3018 3018
 		}
3019 3019
 	}
3020 3020
 
@@ -3032,7 +3032,7 @@  discard block
 block discarded – undo
3032 3032
 	 * @throws EE_Error
3033 3033
 	 * @return array like $query_params[0], see EEM_Base::get_all for documentation
3034 3034
 	 */
3035
-	private function _get_default_where_conditions_for_models_in_query(EE_Model_Query_Info_Carrier $query_info_carrier,$use_default_where_conditions = 'all',$where_query_params = array()){
3035
+	private function _get_default_where_conditions_for_models_in_query(EE_Model_Query_Info_Carrier $query_info_carrier, $use_default_where_conditions = 'all', $where_query_params = array()) {
3036 3036
 		$allowed_used_default_where_conditions_values = array(
3037 3037
 				'all',
3038 3038
 				'this_model_only',
@@ -3040,17 +3040,17 @@  discard block
 block discarded – undo
3040 3040
 				'minimum',
3041 3041
 				'none'
3042 3042
 			);
3043
-		if( ! in_array($use_default_where_conditions,$allowed_used_default_where_conditions_values)){
3044
-			throw new EE_Error(sprintf(__("You passed an invalid value to the query parameter 'default_where_conditions' of '%s'. Allowed values are %s", "event_espresso"),$use_default_where_conditions,implode(", ",$allowed_used_default_where_conditions_values)));
3043
+		if ( ! in_array($use_default_where_conditions, $allowed_used_default_where_conditions_values)) {
3044
+			throw new EE_Error(sprintf(__("You passed an invalid value to the query parameter 'default_where_conditions' of '%s'. Allowed values are %s", "event_espresso"), $use_default_where_conditions, implode(", ", $allowed_used_default_where_conditions_values)));
3045 3045
 		}
3046 3046
 		$universal_query_params = array();
3047
-		if( $use_default_where_conditions === 'all' || $use_default_where_conditions === 'this_model_only' ){
3047
+		if ($use_default_where_conditions === 'all' || $use_default_where_conditions === 'this_model_only') {
3048 3048
 			$universal_query_params = $this->_get_default_where_conditions();
3049
-		} else if( $use_default_where_conditions === 'minimum' ) {
3049
+		} else if ($use_default_where_conditions === 'minimum') {
3050 3050
 			$universal_query_params = $this->_get_minimum_where_conditions();
3051 3051
 		}
3052
-		if(in_array($use_default_where_conditions,array('all','other_models_only'))){
3053
-			foreach($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name){
3052
+		if (in_array($use_default_where_conditions, array('all', 'other_models_only'))) {
3053
+			foreach ($query_info_carrier->get_model_names_included() as $model_relation_path => $model_name) {
3054 3054
 				$related_model = $this->get_related_model_obj($model_name);
3055 3055
 				$related_model_universal_where_params = $related_model->_get_default_where_conditions($model_relation_path);
3056 3056
 				$overrides = $this->_override_defaults_or_make_null_friendly(
@@ -3083,20 +3083,20 @@  discard block
 block discarded – undo
3083 3083
 	 * @return array like EEM_Base::get_all's $query_params[0]
3084 3084
 	 * @throws \EE_Error
3085 3085
 	 */
3086
-	private function _override_defaults_or_make_null_friendly($default_where_conditions,$provided_where_conditions,$model,$model_relation_path){
3086
+	private function _override_defaults_or_make_null_friendly($default_where_conditions, $provided_where_conditions, $model, $model_relation_path) {
3087 3087
 		$null_friendly_where_conditions = array();
3088 3088
 		$none_overridden = true;
3089 3089
 		$or_condition_key_for_defaults = 'OR*'.get_class($model);
3090 3090
 
3091
-		foreach($default_where_conditions as $key => $val){
3092
-			if( isset($provided_where_conditions[$key])){
3091
+		foreach ($default_where_conditions as $key => $val) {
3092
+			if (isset($provided_where_conditions[$key])) {
3093 3093
 				$none_overridden = false;
3094
-			}else{
3094
+			} else {
3095 3095
 				$null_friendly_where_conditions[$or_condition_key_for_defaults]['AND'][$key] = $val;
3096 3096
 			}
3097 3097
 		}
3098
-		if( $none_overridden && $default_where_conditions){
3099
-			if($model->has_primary_key_field()){
3098
+		if ($none_overridden && $default_where_conditions) {
3099
+			if ($model->has_primary_key_field()) {
3100 3100
 				$null_friendly_where_conditions[$or_condition_key_for_defaults][$model_relation_path.".".$model->primary_key_name()] = array('IS NULL');
3101 3101
 			}/*else{
3102 3102
 				//@todo NO PK, use other defaults
@@ -3113,8 +3113,8 @@  discard block
 block discarded – undo
3113 3113
 	 * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment."
3114 3114
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
3115 3115
 	 */
3116
-	private function _get_default_where_conditions($model_relation_path = null){
3117
-		if ( $this->_ignore_where_strategy ){
3116
+	private function _get_default_where_conditions($model_relation_path = null) {
3117
+		if ($this->_ignore_where_strategy) {
3118 3118
 			return array();
3119 3119
 		}
3120 3120
 		return $this->_default_where_conditions_strategy->get_default_where_conditions($model_relation_path);
@@ -3128,8 +3128,8 @@  discard block
 block discarded – undo
3128 3128
 	 * @param string $model_relation_path eg, path from Event to Payment is "Registration.Transaction.Payment."
3129 3129
 	 * @return array like EEM_Base::get_all's $query_params[0] (where conditions)
3130 3130
 	 */
3131
-	protected function _get_minimum_where_conditions($model_relation_path = null){
3132
-		if ( $this->_ignore_where_strategy ){
3131
+	protected function _get_minimum_where_conditions($model_relation_path = null) {
3132
+		if ($this->_ignore_where_strategy) {
3133 3133
 			return array();
3134 3134
 		}
3135 3135
 		return $this->_minimum_where_conditions_strategy->get_default_where_conditions($model_relation_path);
@@ -3145,16 +3145,16 @@  discard block
 block discarded – undo
3145 3145
 	 * @return string
3146 3146
 	 * @throws \EE_Error
3147 3147
 	 */
3148
-	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info){
3148
+	private function _construct_default_select_sql(EE_Model_Query_Info_Carrier $model_query_info) {
3149 3149
 		$selects = $this->_get_columns_to_select_for_this_model();
3150
-		foreach($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included){
3150
+		foreach ($model_query_info->get_model_names_included() as $model_relation_chain => $name_of_other_model_included) {
3151 3151
 			$other_model_included = $this->get_related_model_obj($name_of_other_model_included);
3152
-			$other_model_selects = $other_model_included->_get_columns_to_select_for_this_model( $model_relation_chain );
3153
-			foreach ( $other_model_selects as $key => $value ) {
3152
+			$other_model_selects = $other_model_included->_get_columns_to_select_for_this_model($model_relation_chain);
3153
+			foreach ($other_model_selects as $key => $value) {
3154 3154
 				$selects[] = $value;
3155 3155
 			}
3156 3156
 		}
3157
-		return implode(", ",$selects);
3157
+		return implode(", ", $selects);
3158 3158
 	}
3159 3159
 
3160 3160
 	/**
@@ -3163,19 +3163,19 @@  discard block
 block discarded – undo
3163 3163
 	 * @param string $model_relation_chain like 'Question.Question_Group.Event'
3164 3164
 	 * @return array numerically indexed, values are columns to select and rename, eg "Event.ID AS 'Event.ID'"
3165 3165
 	 */
3166
-	public function _get_columns_to_select_for_this_model($model_relation_chain = ''){
3166
+	public function _get_columns_to_select_for_this_model($model_relation_chain = '') {
3167 3167
 		$fields = $this->field_settings();
3168 3168
 		$selects = array();
3169 3169
 		$table_alias_with_model_relation_chain_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this->get_this_model_name());
3170
-		foreach($fields as $field_obj){
3171
-			$selects[] = $table_alias_with_model_relation_chain_prefix . $field_obj->get_table_alias().".".$field_obj->get_table_column()." AS '".$table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()."'";
3170
+		foreach ($fields as $field_obj) {
3171
+			$selects[] = $table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()." AS '".$table_alias_with_model_relation_chain_prefix.$field_obj->get_table_alias().".".$field_obj->get_table_column()."'";
3172 3172
 		}
3173 3173
 		//make sure we are also getting the PKs of each table
3174 3174
 		$tables = $this->get_tables();
3175
-		if(count($tables) > 1){
3176
-			foreach($tables as $table_obj){
3177
-				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix . $table_obj->get_fully_qualified_pk_column();
3178
-				if( ! in_array($qualified_pk_column,$selects)){
3175
+		if (count($tables) > 1) {
3176
+			foreach ($tables as $table_obj) {
3177
+				$qualified_pk_column = $table_alias_with_model_relation_chain_prefix.$table_obj->get_fully_qualified_pk_column();
3178
+				if ( ! in_array($qualified_pk_column, $selects)) {
3179 3179
 					$selects[] = "$qualified_pk_column AS '$qualified_pk_column'";
3180 3180
 				}
3181 3181
 			}
@@ -3205,65 +3205,65 @@  discard block
 block discarded – undo
3205 3205
 		$query_param_type,
3206 3206
 		$original_query_param = null
3207 3207
 	) {
3208
-		if( $original_query_param === null ){
3208
+		if ($original_query_param === null) {
3209 3209
 			$original_query_param = $query_param;
3210 3210
 		}
3211 3211
 		$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);
3212 3212
 		/** @var $allow_logic_query_params bool whether or not to allow logic_query_params like 'NOT','OR', or 'AND' */
3213
-		$allow_logic_query_params = in_array($query_param_type,array('where','having'));
3214
-		$allow_fields = in_array($query_param_type,array('where','having','order_by','group_by','order'));
3213
+		$allow_logic_query_params = in_array($query_param_type, array('where', 'having'));
3214
+		$allow_fields = in_array($query_param_type, array('where', 'having', 'order_by', 'group_by', 'order'));
3215 3215
 		//check to see if we have a field on this model
3216 3216
 		$this_model_fields = $this->field_settings(true);
3217
-		if(array_key_exists($query_param,$this_model_fields)){
3218
-			if($allow_fields){
3217
+		if (array_key_exists($query_param, $this_model_fields)) {
3218
+			if ($allow_fields) {
3219 3219
 				return;
3220
-			}else{
3220
+			} else {
3221 3221
 				throw new EE_Error(sprintf(__("Using a field name (%s) on model %s is not allowed on this query param type '%s'. Original query param was %s", "event_espresso"),
3222
-						$query_param,get_class($this),$query_param_type,$original_query_param));
3222
+						$query_param, get_class($this), $query_param_type, $original_query_param));
3223 3223
 			}
3224 3224
 		}
3225 3225
 		//check if this is a special logic query param
3226
-		elseif(in_array($query_param, $this->_logic_query_param_keys, TRUE)){
3227
-			if($allow_logic_query_params){
3226
+		elseif (in_array($query_param, $this->_logic_query_param_keys, TRUE)) {
3227
+			if ($allow_logic_query_params) {
3228 3228
 				return;
3229
-			}else{
3229
+			} else {
3230 3230
 				throw new EE_Error(
3231 3231
 					sprintf(
3232
-						__( 'Logic query params ("%1$s") are being used incorrectly with the following query param ("%2$s") on model %3$s. %4$sAdditional Info:%4$s%5$s', 'event_espresso' ),
3233
-						implode( '", "', $this->_logic_query_param_keys ),
3234
-						$query_param ,
3235
-						get_class( $this ),
3232
+						__('Logic query params ("%1$s") are being used incorrectly with the following query param ("%2$s") on model %3$s. %4$sAdditional Info:%4$s%5$s', 'event_espresso'),
3233
+						implode('", "', $this->_logic_query_param_keys),
3234
+						$query_param,
3235
+						get_class($this),
3236 3236
 						'<br />',
3237
-						"\t" . ' $passed_in_query_info = <pre>' . print_r( $passed_in_query_info, TRUE ) . '</pre>' . "\n\t" . ' $query_param_type = ' . $query_param_type . "\n\t" . ' $original_query_param = ' . $original_query_param
3237
+						"\t".' $passed_in_query_info = <pre>'.print_r($passed_in_query_info, TRUE).'</pre>'."\n\t".' $query_param_type = '.$query_param_type."\n\t".' $original_query_param = '.$original_query_param
3238 3238
 					)
3239 3239
 				);
3240 3240
 			}
3241 3241
 		}
3242 3242
 
3243 3243
 		//check if it's a custom selection
3244
-		elseif(array_key_exists($query_param,$this->_custom_selections)){
3244
+		elseif (array_key_exists($query_param, $this->_custom_selections)) {
3245 3245
 			return;
3246 3246
 		}
3247 3247
 
3248 3248
 		//check if has a model name at the beginning
3249 3249
 		//and
3250 3250
 		//check if it's a field on a related model
3251
-		foreach($this->_model_relations as $valid_related_model_name=>$relation_obj){
3252
-			if(strpos($query_param, $valid_related_model_name.".") === 0){
3253
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
3251
+		foreach ($this->_model_relations as $valid_related_model_name=>$relation_obj) {
3252
+			if (strpos($query_param, $valid_related_model_name.".") === 0) {
3253
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
3254 3254
 				$query_param = substr($query_param, strlen($valid_related_model_name."."));
3255
-				if($query_param === ''){
3255
+				if ($query_param === '') {
3256 3256
 					//nothing left to $query_param
3257 3257
 					//we should actually end in a field name, not a model like this!
3258 3258
 					throw new EE_Error(sprintf(__("Query param '%s' (of type %s on model %s) shouldn't end on a period (.) ", "event_espresso"),
3259
-					$query_param,$query_param_type,get_class($this),$valid_related_model_name));
3260
-				}else{
3259
+					$query_param, $query_param_type, get_class($this), $valid_related_model_name));
3260
+				} else {
3261 3261
 					$related_model_obj = $this->get_related_model_obj($valid_related_model_name);
3262 3262
 					$related_model_obj->_extract_related_model_info_from_query_param($query_param, $passed_in_query_info, $query_param_type, $original_query_param);
3263 3263
 					return;
3264 3264
 				}
3265
-			}elseif($query_param === $valid_related_model_name){
3266
-				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info,$original_query_param);
3265
+			}elseif ($query_param === $valid_related_model_name) {
3266
+				$this->_add_join_to_model($valid_related_model_name, $passed_in_query_info, $original_query_param);
3267 3267
 				return;
3268 3268
 			}
3269 3269
 		}
@@ -3273,7 +3273,7 @@  discard block
 block discarded – undo
3273 3273
 		//and we previously confirmed it wasn't a logic query param or field on the current model
3274 3274
 		//it's wack, that's what it is
3275 3275
 		throw new EE_Error(sprintf(__("There is no model named '%s' related to %s. Query param type is %s and original query param is %s", "event_espresso"),
3276
-				$query_param,get_class($this),$query_param_type,$original_query_param));
3276
+				$query_param, get_class($this), $query_param_type, $original_query_param));
3277 3277
 
3278 3278
 	}
3279 3279
 
@@ -3292,26 +3292,26 @@  discard block
 block discarded – undo
3292 3292
 	 * @return void
3293 3293
 	 * @throws \EE_Error
3294 3294
 	 */
3295
-	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info,$original_query_param){
3295
+	private function _add_join_to_model($model_name, EE_Model_Query_Info_Carrier $passed_in_query_info, $original_query_param) {
3296 3296
 		$relation_obj = $this->related_settings_for($model_name);
3297 3297
 
3298 3298
 		$model_relation_chain = EE_Model_Parser::extract_model_relation_chain($model_name, $original_query_param);
3299 3299
 		//check if the relation is HABTM, because then we're essentially doing two joins
3300 3300
 		//If so, join first to the JOIN table, and add its data types, and then continue as normal
3301
-		if($relation_obj instanceof EE_HABTM_Relation){
3301
+		if ($relation_obj instanceof EE_HABTM_Relation) {
3302 3302
 			$join_model_obj = $relation_obj->get_join_model();
3303 3303
 			//replace the model specified with the join model for this relation chain, whi
3304 3304
 			$relation_chain_to_join_model = EE_Model_Parser::replace_model_name_with_join_model_name_in_model_relation_chain($model_name, $join_model_obj->get_this_model_name(), $model_relation_chain);
3305 3305
 			$new_query_info = new EE_Model_Query_Info_Carrier(
3306 3306
 					array($relation_chain_to_join_model => $join_model_obj->get_this_model_name()),
3307 3307
 					$relation_obj->get_join_to_intermediate_model_statement($relation_chain_to_join_model));
3308
-			$passed_in_query_info->merge( $new_query_info  );
3308
+			$passed_in_query_info->merge($new_query_info);
3309 3309
 		}
3310 3310
 		//now just join to the other table pointed to by the relation object, and add its data types
3311 3311
 		$new_query_info = new EE_Model_Query_Info_Carrier(
3312 3312
 				array($model_relation_chain=>$model_name),
3313 3313
 				$relation_obj->get_join_statement($model_relation_chain));
3314
-		$passed_in_query_info->merge( $new_query_info  );
3314
+		$passed_in_query_info->merge($new_query_info);
3315 3315
 	}
3316 3316
 
3317 3317
 
@@ -3323,11 +3323,11 @@  discard block
 block discarded – undo
3323 3323
 	 * @return string of SQL
3324 3324
 	 * @throws \EE_Error
3325 3325
 	 */
3326
-	private function _construct_where_clause($where_params){
3326
+	private function _construct_where_clause($where_params) {
3327 3327
 		$SQL = $this->_construct_condition_clause_recursive($where_params, ' AND ');
3328
-		if($SQL){
3329
-			return " WHERE ". $SQL;
3330
-		}else{
3328
+		if ($SQL) {
3329
+			return " WHERE ".$SQL;
3330
+		} else {
3331 3331
 			return '';
3332 3332
 		}
3333 3333
 	}
@@ -3342,11 +3342,11 @@  discard block
 block discarded – undo
3342 3342
 	 * @return string
3343 3343
 	 * @throws \EE_Error
3344 3344
 	 */
3345
-	private function _construct_having_clause($having_params){
3345
+	private function _construct_having_clause($having_params) {
3346 3346
 		$SQL = $this->_construct_condition_clause_recursive($having_params, ' AND ');
3347
-		if($SQL){
3348
-			return " HAVING ". $SQL;
3349
-		}else{
3347
+		if ($SQL) {
3348
+			return " HAVING ".$SQL;
3349
+		} else {
3350 3350
 			return '';
3351 3351
 		}
3352 3352
 
@@ -3360,16 +3360,16 @@  discard block
 block discarded – undo
3360 3360
 	 * @return EE_Model_Field_Base
3361 3361
 	 * @throws EE_Error
3362 3362
 	 */
3363
-	protected function _get_field_on_model($field_name,$model_name){
3363
+	protected function _get_field_on_model($field_name, $model_name) {
3364 3364
 		$model_class = 'EEM_'.$model_name;
3365 3365
 		$model_filepath = $model_class.".model.php";
3366
-		if ( is_readable($model_filepath)){
3366
+		if (is_readable($model_filepath)) {
3367 3367
 			require_once($model_filepath);
3368
-			$model_instance=call_user_func($model_name."::instance");
3368
+			$model_instance = call_user_func($model_name."::instance");
3369 3369
 			/* @var $model_instance EEM_Base */
3370 3370
 			return $model_instance->field_settings_for($field_name);
3371
-		}else{
3372
-			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s','event_espresso'),$model_name,$model_class,$model_filepath));
3371
+		} else {
3372
+			throw new EE_Error(sprintf(__('No model named %s exists, with classname %s and filepath %s', 'event_espresso'), $model_name, $model_class, $model_filepath));
3373 3373
 		}
3374 3374
 	}
3375 3375
 
@@ -3382,41 +3382,41 @@  discard block
 block discarded – undo
3382 3382
 	 * @throws EE_Error
3383 3383
 	 * @return string of SQL
3384 3384
 	 */
3385
-	private function _construct_condition_clause_recursive($where_params, $glue = ' AND'){
3386
-		$where_clauses=array();
3387
-		foreach($where_params as $query_param => $op_and_value_or_sub_condition){
3388
-			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param);//str_replace("*",'',$query_param);
3389
-			if(in_array($query_param,$this->_logic_query_param_keys)){
3390
-				switch($query_param){
3385
+	private function _construct_condition_clause_recursive($where_params, $glue = ' AND') {
3386
+		$where_clauses = array();
3387
+		foreach ($where_params as $query_param => $op_and_value_or_sub_condition) {
3388
+			$query_param = $this->_remove_stars_and_anything_after_from_condition_query_param_key($query_param); //str_replace("*",'',$query_param);
3389
+			if (in_array($query_param, $this->_logic_query_param_keys)) {
3390
+				switch ($query_param) {
3391 3391
 					case 'not':
3392 3392
 					case 'NOT':
3393
-						$where_clauses[] = "! (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
3393
+						$where_clauses[] = "! (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, $glue).")";
3394 3394
 						break;
3395 3395
 					case 'and':
3396 3396
 					case 'AND':
3397
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ') .")";
3397
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' AND ').")";
3398 3398
 						break;
3399 3399
 					case 'or':
3400 3400
 					case 'OR':
3401
-						$where_clauses[] = " (". $this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ') .")";
3401
+						$where_clauses[] = " (".$this->_construct_condition_clause_recursive($op_and_value_or_sub_condition, ' OR ').")";
3402 3402
 						break;
3403 3403
 				}
3404
-			}else{
3404
+			} else {
3405 3405
 				$field_obj = $this->_deduce_field_from_query_param($query_param);
3406 3406
 
3407 3407
 				//if it's not a normal field, maybe it's a custom selection?
3408
-				if( ! $field_obj){
3409
-					if(isset( $this->_custom_selections[$query_param][1])){
3408
+				if ( ! $field_obj) {
3409
+					if (isset($this->_custom_selections[$query_param][1])) {
3410 3410
 						$field_obj = $this->_custom_selections[$query_param][1];
3411
-					}else{
3412
-						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"),$query_param));
3411
+					} else {
3412
+						throw new EE_Error(sprintf(__("%s is neither a valid model field name, nor a custom selection", "event_espresso"), $query_param));
3413 3413
 					}
3414 3414
 				}
3415 3415
 				$op_and_value_sql = $this->_construct_op_and_value($op_and_value_or_sub_condition, $field_obj);
3416
-				$where_clauses[]=$this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
3416
+				$where_clauses[] = $this->_deduce_column_name_from_query_param($query_param).SP.$op_and_value_sql;
3417 3417
 			}
3418 3418
 		}
3419
-		return $where_clauses ? implode( $glue, $where_clauses ) : '';
3419
+		return $where_clauses ? implode($glue, $where_clauses) : '';
3420 3420
 	}
3421 3421
 
3422 3422
 
@@ -3427,18 +3427,18 @@  discard block
 block discarded – undo
3427 3427
 	 * @throws EE_Error
3428 3428
 	 * @return string table alias and column name for SQL, eg "Transaction.TXN_ID"
3429 3429
 	 */
3430
-	private function _deduce_column_name_from_query_param($query_param){
3430
+	private function _deduce_column_name_from_query_param($query_param) {
3431 3431
 		$field = $this->_deduce_field_from_query_param($query_param);
3432 3432
 
3433
-		if( $field ){
3434
-			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param( $field->get_model_name(), $query_param );
3435
-			return $table_alias_prefix . $field->get_qualified_column();
3436
-		}elseif(array_key_exists($query_param,$this->_custom_selections)){
3433
+		if ($field) {
3434
+			$table_alias_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_from_query_param($field->get_model_name(), $query_param);
3435
+			return $table_alias_prefix.$field->get_qualified_column();
3436
+		}elseif (array_key_exists($query_param, $this->_custom_selections)) {
3437 3437
 			//maybe it's custom selection item?
3438 3438
 			//if so, just use it as the "column name"
3439 3439
 			return $query_param;
3440
-		}else{
3441
-			throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"),$query_param,implode(",",$this->_custom_selections)));
3440
+		} else {
3441
+			throw new EE_Error(sprintf(__("%s is not a valid field on this model, nor a custom selection (%s)", "event_espresso"), $query_param, implode(",", $this->_custom_selections)));
3442 3442
 		}
3443 3443
 	}
3444 3444
 
@@ -3450,11 +3450,11 @@  discard block
 block discarded – undo
3450 3450
 	 * @param string $condition_query_param_key
3451 3451
 	 * @return string
3452 3452
 	 */
3453
-	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key){
3453
+	private function _remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) {
3454 3454
 		$pos_of_star = strpos($condition_query_param_key, '*');
3455
-		if($pos_of_star === FALSE){
3455
+		if ($pos_of_star === FALSE) {
3456 3456
 			return $condition_query_param_key;
3457
-		}else{
3457
+		} else {
3458 3458
 			$condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star);
3459 3459
 			return $condition_query_param_sans_star;
3460 3460
 		}
@@ -3469,12 +3469,12 @@  discard block
 block discarded – undo
3469 3469
 	 * @throws EE_Error
3470 3470
 	 * @return string
3471 3471
 	 */
3472
-	private function _construct_op_and_value($op_and_value, $field_obj){
3473
-		if ( is_array( $op_and_value ) ) {
3474
-			$operator = isset( $op_and_value[0] ) ? $this->_prepare_operator_for_sql( $op_and_value[0] ) : null;
3475
-			if ( ! $operator ) {
3472
+	private function _construct_op_and_value($op_and_value, $field_obj) {
3473
+		if (is_array($op_and_value)) {
3474
+			$operator = isset($op_and_value[0]) ? $this->_prepare_operator_for_sql($op_and_value[0]) : null;
3475
+			if ( ! $operator) {
3476 3476
 				$php_array_like_string = array();
3477
-				foreach ( $op_and_value as $key => $value ) {
3477
+				foreach ($op_and_value as $key => $value) {
3478 3478
 					$php_array_like_string[] = "$key=>$value";
3479 3479
 				}
3480 3480
 				throw new EE_Error(
@@ -3483,27 +3483,27 @@  discard block
 block discarded – undo
3483 3483
 							"You setup a query parameter like you were going to specify an operator, but didn't. You provided '(%s)', but the operator should be at array key index 0 (eg array('>',32))",
3484 3484
 							"event_espresso"
3485 3485
 						),
3486
-						implode( ",", $php_array_like_string )
3486
+						implode(",", $php_array_like_string)
3487 3487
 					)
3488 3488
 				);
3489 3489
 			}
3490
-			$value = isset( $op_and_value[1] ) ? $op_and_value[1] : null;
3490
+			$value = isset($op_and_value[1]) ? $op_and_value[1] : null;
3491 3491
 		} else {
3492 3492
 			$operator = '=';
3493 3493
 			$value = $op_and_value;
3494 3494
 		}
3495 3495
 		//check to see if the value is actually another field
3496
-		if ( is_array( $op_and_value ) && isset( $op_and_value[2] ) && $op_and_value[2] == true ) {
3497
-			return $operator . SP . $this->_deduce_column_name_from_query_param( $value );
3498
-		} elseif ( in_array( $operator, $this->_in_style_operators ) && is_array( $value ) ) {
3496
+		if (is_array($op_and_value) && isset($op_and_value[2]) && $op_and_value[2] == true) {
3497
+			return $operator.SP.$this->_deduce_column_name_from_query_param($value);
3498
+		} elseif (in_array($operator, $this->_in_style_operators) && is_array($value)) {
3499 3499
 			//in this case, the value should be an array, or at least a comma-separated list
3500 3500
 			//it will need to handle a little differently
3501
-			$cleaned_value = $this->_construct_in_value( $value, $field_obj );
3501
+			$cleaned_value = $this->_construct_in_value($value, $field_obj);
3502 3502
 			//note: $cleaned_value has already been run through $wpdb->prepare()
3503
-			return $operator . SP . $cleaned_value;
3504
-		} elseif ( in_array( $operator, $this->_between_style_operators ) && is_array( $value ) ) {
3503
+			return $operator.SP.$cleaned_value;
3504
+		} elseif (in_array($operator, $this->_between_style_operators) && is_array($value)) {
3505 3505
 			//the value should be an array with count of two.
3506
-			if ( count( $value ) !== 2 ) {
3506
+			if (count($value) !== 2) {
3507 3507
 				throw new EE_Error(
3508 3508
 					sprintf(
3509 3509
 						__(
@@ -3514,10 +3514,10 @@  discard block
 block discarded – undo
3514 3514
 					)
3515 3515
 				);
3516 3516
 			}
3517
-			$cleaned_value = $this->_construct_between_value( $value, $field_obj );
3518
-			return $operator . SP . $cleaned_value;
3519
-		} elseif ( in_array( $operator, $this->_null_style_operators ) ) {
3520
-			if ( $value !== null ) {
3517
+			$cleaned_value = $this->_construct_between_value($value, $field_obj);
3518
+			return $operator.SP.$cleaned_value;
3519
+		} elseif (in_array($operator, $this->_null_style_operators)) {
3520
+			if ($value !== null) {
3521 3521
 				throw new EE_Error(
3522 3522
 					sprintf(
3523 3523
 						__(
@@ -3530,13 +3530,13 @@  discard block
 block discarded – undo
3530 3530
 				);
3531 3531
 			}
3532 3532
 			return $operator;
3533
-		} elseif ( $operator === 'LIKE' && ! is_array( $value ) ) {
3533
+		} elseif ($operator === 'LIKE' && ! is_array($value)) {
3534 3534
 			//if the operator is 'LIKE', we want to allow percent signs (%) and not
3535 3535
 			//remove other junk. So just treat it as a string.
3536
-			return $operator . SP . $this->_wpdb_prepare_using_field( $value, '%s' );
3537
-		} elseif ( ! in_array( $operator, $this->_in_style_operators ) && ! is_array( $value ) ) {
3538
-			return $operator . SP . $this->_wpdb_prepare_using_field( $value, $field_obj );
3539
-		} elseif ( in_array( $operator, $this->_in_style_operators ) && ! is_array( $value ) ) {
3536
+			return $operator.SP.$this->_wpdb_prepare_using_field($value, '%s');
3537
+		} elseif ( ! in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
3538
+			return $operator.SP.$this->_wpdb_prepare_using_field($value, $field_obj);
3539
+		} elseif (in_array($operator, $this->_in_style_operators) && ! is_array($value)) {
3540 3540
 			throw new EE_Error(
3541 3541
 				sprintf(
3542 3542
 					__(
@@ -3547,7 +3547,7 @@  discard block
 block discarded – undo
3547 3547
 					$operator
3548 3548
 				)
3549 3549
 			);
3550
-		} elseif ( ! in_array( $operator, $this->_in_style_operators ) && is_array( $value ) ) {
3550
+		} elseif ( ! in_array($operator, $this->_in_style_operators) && is_array($value)) {
3551 3551
 			throw new EE_Error(
3552 3552
 				sprintf(
3553 3553
 					__(
@@ -3565,7 +3565,7 @@  discard block
 block discarded – undo
3565 3565
 						"It appears you've provided some totally invalid query parameters. Operator and value were:'%s', which isn't right at all",
3566 3566
 						"event_espresso"
3567 3567
 					),
3568
-					http_build_query( $op_and_value )
3568
+					http_build_query($op_and_value)
3569 3569
 				)
3570 3570
 			);
3571 3571
 		}
@@ -3581,12 +3581,12 @@  discard block
 block discarded – undo
3581 3581
 	 * @return string
3582 3582
 	 * @throws \EE_Error
3583 3583
 	 */
3584
-	public function _construct_between_value( $values, $field_obj ) {
3584
+	public function _construct_between_value($values, $field_obj) {
3585 3585
 		$cleaned_values = array();
3586
-		foreach ( $values as $value ) {
3587
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
3586
+		foreach ($values as $value) {
3587
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
3588 3588
 		}
3589
-		return  $cleaned_values[0] . " AND " . $cleaned_values[1];
3589
+		return  $cleaned_values[0]." AND ".$cleaned_values[1];
3590 3590
 	}
3591 3591
 
3592 3592
 
@@ -3603,26 +3603,26 @@  discard block
 block discarded – undo
3603 3603
 	 * @return string of SQL to follow an 'IN' or 'NOT IN' operator
3604 3604
 	 * @throws \EE_Error
3605 3605
 	 */
3606
-	public function _construct_in_value($values,  $field_obj){
3606
+	public function _construct_in_value($values, $field_obj) {
3607 3607
 		//check if the value is a CSV list
3608
-		if(is_string($values)){
3608
+		if (is_string($values)) {
3609 3609
 			//in which case, turn it into an array
3610
-			$values = explode(",",$values);
3610
+			$values = explode(",", $values);
3611 3611
 		}
3612 3612
 		$cleaned_values = array();
3613
-		foreach($values as $value){
3614
-			$cleaned_values[] = $this->_wpdb_prepare_using_field($value,$field_obj);
3613
+		foreach ($values as $value) {
3614
+			$cleaned_values[] = $this->_wpdb_prepare_using_field($value, $field_obj);
3615 3615
 		}
3616 3616
 		//we would just LOVE to leave $cleaned_values as an empty array, and return the value as "()",
3617 3617
 		//but unfortunately that's invalid SQL. So instead we return a string which we KNOW will evaluate to be the empty set
3618 3618
 		//which is effectively equivalent to returning "()". We don't return "(0)" because that only works for auto-incrementing columns
3619
-		if(empty($cleaned_values)){
3619
+		if (empty($cleaned_values)) {
3620 3620
 			$all_fields = $this->field_settings();
3621 3621
 			$a_field = array_shift($all_fields);
3622 3622
 			$main_table = $this->_get_main_table();
3623 3623
 			$cleaned_values[] = "SELECT ".$a_field->get_table_column()." FROM ".$main_table->get_table_name()." WHERE FALSE";
3624 3624
 		}
3625
-		return "(".implode(",",$cleaned_values).")";
3625
+		return "(".implode(",", $cleaned_values).")";
3626 3626
 	}
3627 3627
 
3628 3628
 
@@ -3634,16 +3634,16 @@  discard block
 block discarded – undo
3634 3634
 	 * @throws EE_Error
3635 3635
 	 * @return false|null|string
3636 3636
 	 */
3637
-	private function _wpdb_prepare_using_field($value,$field_obj){
3637
+	private function _wpdb_prepare_using_field($value, $field_obj) {
3638 3638
 		/** @type WPDB $wpdb */
3639 3639
 		global $wpdb;
3640
-		if($field_obj instanceof EE_Model_Field_Base){
3641
-			return $wpdb->prepare($field_obj->get_wpdb_data_type(),$this->_prepare_value_for_use_in_db($value, $field_obj));
3642
-		}else{//$field_obj should really just be a data type
3643
-			if( ! in_array($field_obj,$this->_valid_wpdb_data_types)){
3644
-				throw new EE_Error(sprintf(__("%s is not a valid wpdb datatype. Valid ones are %s", "event_espresso"),$field_obj,implode(",",$this->_valid_wpdb_data_types)));
3640
+		if ($field_obj instanceof EE_Model_Field_Base) {
3641
+			return $wpdb->prepare($field_obj->get_wpdb_data_type(), $this->_prepare_value_for_use_in_db($value, $field_obj));
3642
+		} else {//$field_obj should really just be a data type
3643
+			if ( ! in_array($field_obj, $this->_valid_wpdb_data_types)) {
3644
+				throw new EE_Error(sprintf(__("%s is not a valid wpdb datatype. Valid ones are %s", "event_espresso"), $field_obj, implode(",", $this->_valid_wpdb_data_types)));
3645 3645
 			}
3646
-			return $wpdb->prepare($field_obj,$value);
3646
+			return $wpdb->prepare($field_obj, $value);
3647 3647
 		}
3648 3648
 	}
3649 3649
 
@@ -3655,27 +3655,27 @@  discard block
 block discarded – undo
3655 3655
 	 * @throws EE_Error
3656 3656
 	 * @return EE_Model_Field_Base
3657 3657
 	 */
3658
-	protected function _deduce_field_from_query_param($query_param_name){
3658
+	protected function _deduce_field_from_query_param($query_param_name) {
3659 3659
 		//ok, now proceed with deducing which part is the model's name, and which is the field's name
3660 3660
 		//which will help us find the database table and column
3661 3661
 
3662
-		$query_param_parts = explode(".",$query_param_name);
3663
-		if(empty($query_param_parts)){
3664
-			throw new EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s",'event_espresso'),$query_param_name));
3662
+		$query_param_parts = explode(".", $query_param_name);
3663
+		if (empty($query_param_parts)) {
3664
+			throw new EE_Error(sprintf(__("_extract_column_name is empty when trying to extract column and table name from %s", 'event_espresso'), $query_param_name));
3665 3665
 		}
3666 3666
 		$number_of_parts = count($query_param_parts);
3667
-		$last_query_param_part = $query_param_parts[ count($query_param_parts) - 1 ];
3668
-		if($number_of_parts === 1){
3667
+		$last_query_param_part = $query_param_parts[count($query_param_parts) - 1];
3668
+		if ($number_of_parts === 1) {
3669 3669
 			$field_name = $last_query_param_part;
3670 3670
 			$model_obj = $this;
3671
-		}else{// $number_of_parts >= 2
3671
+		} else {// $number_of_parts >= 2
3672 3672
 			//the last part is the column name, and there are only 2parts. therefore...
3673 3673
 			$field_name = $last_query_param_part;
3674
-			$model_obj = $this->get_related_model_obj( $query_param_parts[ $number_of_parts - 2 ]);
3674
+			$model_obj = $this->get_related_model_obj($query_param_parts[$number_of_parts - 2]);
3675 3675
 		}
3676
-		try{
3676
+		try {
3677 3677
 			return $model_obj->field_settings_for($field_name);
3678
-		}catch(EE_Error $e){
3678
+		} catch (EE_Error $e) {
3679 3679
 			return null;
3680 3680
 		}
3681 3681
 	}
@@ -3689,13 +3689,13 @@  discard block
 block discarded – undo
3689 3689
 	 * @throws EE_Error
3690 3690
 	 * @return string
3691 3691
 	 */
3692
-	public function _get_qualified_column_for_field($field_name){
3692
+	public function _get_qualified_column_for_field($field_name) {
3693 3693
 		$all_fields = $this->field_settings();
3694 3694
 		$field = isset($all_fields[$field_name]) ? $all_fields[$field_name] : FALSE;
3695
-		if($field){
3695
+		if ($field) {
3696 3696
 			return $field->get_qualified_column();
3697
-		}else{
3698
-			throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.",'event_espresso'),$field_name,get_class($this)));
3697
+		} else {
3698
+			throw new EE_Error(sprintf(__("There is no field titled %s on model %s. Either the query trying to use it is bad, or you need to add it to the list of fields on the model.", 'event_espresso'), $field_name, get_class($this)));
3699 3699
 		}
3700 3700
 	}
3701 3701
 
@@ -3709,17 +3709,17 @@  discard block
 block discarded – undo
3709 3709
 	 * @param  mixed|string $limit The limit for this select
3710 3710
 	 * @return string                The final select join element for the query.
3711 3711
 	 */
3712
-	public function _construct_limit_join_select( $table_alias, $limit ) {
3712
+	public function _construct_limit_join_select($table_alias, $limit) {
3713 3713
 		$SQL = '';
3714
-		foreach ( $this->_tables as $table_obj ) {
3715
-			if ( $table_obj instanceof EE_Primary_Table ) {
3714
+		foreach ($this->_tables as $table_obj) {
3715
+			if ($table_obj instanceof EE_Primary_Table) {
3716 3716
 				$SQL .= $table_alias === $table_obj->get_table_alias()
3717
-					? $table_obj->get_select_join_limit( $limit )
3718
-					: SP . $table_obj->get_table_name() . " AS " . $table_obj->get_table_alias() . SP;
3719
-			} elseif ( $table_obj instanceof EE_Secondary_Table ) {
3717
+					? $table_obj->get_select_join_limit($limit)
3718
+					: SP.$table_obj->get_table_name()." AS ".$table_obj->get_table_alias().SP;
3719
+			} elseif ($table_obj instanceof EE_Secondary_Table) {
3720 3720
 				$SQL .= $table_alias === $table_obj->get_table_alias()
3721
-					? $table_obj->get_select_join_limit_join( $limit )
3722
-					: SP . $table_obj->get_join_sql( $table_alias ) . SP;
3721
+					? $table_obj->get_select_join_limit_join($limit)
3722
+					: SP.$table_obj->get_join_sql($table_alias).SP;
3723 3723
 			}
3724 3724
 		}
3725 3725
 		return $SQL;
@@ -3734,7 +3734,7 @@  discard block
 block discarded – undo
3734 3734
 	 * @return string SQL
3735 3735
 	 * @throws \EE_Error
3736 3736
 	 */
3737
-	public function _construct_internal_join(){
3737
+	public function _construct_internal_join() {
3738 3738
 		$SQL = $this->_get_main_table()->get_table_sql();
3739 3739
 		$SQL .= $this->_construct_internal_join_to_table_with_alias($this->_get_main_table()->get_table_alias());
3740 3740
 		return $SQL;
@@ -3755,17 +3755,17 @@  discard block
 block discarded – undo
3755 3755
 	 * @param string $alias_prefixed table alias to join to (this table should already be in the FROM SQL clause)
3756 3756
 	 * @return string
3757 3757
 	 */
3758
-	public function _construct_internal_join_to_table_with_alias($alias_prefixed){
3758
+	public function _construct_internal_join_to_table_with_alias($alias_prefixed) {
3759 3759
 		$SQL = '';
3760 3760
 		$alias_sans_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($alias_prefixed);
3761
-		foreach($this->_tables as $table_obj){
3762
-			if($table_obj instanceof EE_Secondary_Table){//table is secondary table
3763
-				if($alias_sans_prefix === $table_obj->get_table_alias()){
3761
+		foreach ($this->_tables as $table_obj) {
3762
+			if ($table_obj instanceof EE_Secondary_Table) {//table is secondary table
3763
+				if ($alias_sans_prefix === $table_obj->get_table_alias()) {
3764 3764
 					//so we're joining to this table, meaning the table is already in
3765 3765
 					//the FROM statement, BUT the primary table isn't. So we want
3766 3766
 					//to add the inverse join sql
3767 3767
 					$SQL .= $table_obj->get_inverse_join_sql($alias_prefixed);
3768
-				}else{
3768
+				} else {
3769 3769
 					//just add a regular JOIN to this table from the primary table
3770 3770
 					$SQL .= $table_obj->get_join_sql($alias_prefixed);
3771 3771
 				}
@@ -3779,9 +3779,9 @@  discard block
 block discarded – undo
3779 3779
 	 * This should be a growing array of keys being table-columns (eg 'EVT_ID' and 'Event.EVT_ID'), and values being their data type (eg, '%s', '%d', etc)
3780 3780
 	 * @return array
3781 3781
 	 */
3782
-	public function _get_data_types(){
3782
+	public function _get_data_types() {
3783 3783
 		$data_types = array();
3784
-		foreach( $this->field_settings() as $field_obj){
3784
+		foreach ($this->field_settings() as $field_obj) {
3785 3785
 			//$data_types[$field_obj->get_table_column()] = $field_obj->get_wpdb_data_type();
3786 3786
 			/** @var $field_obj EE_Model_Field_Base */
3787 3787
 			$data_types[$field_obj->get_qualified_column()] = $field_obj->get_wpdb_data_type();
@@ -3797,10 +3797,10 @@  discard block
 block discarded – undo
3797 3797
 	 * @throws EE_Error
3798 3798
 	 * @return EEM_Base
3799 3799
 	 */
3800
-	public function get_related_model_obj($model_name){
3800
+	public function get_related_model_obj($model_name) {
3801 3801
 		$model_classname = "EEM_".$model_name;
3802
-		if(!class_exists($model_classname)){
3803
-			throw new EE_Error(sprintf(__("You specified a related model named %s in your query. No such model exists, if it did, it would have the classname %s",'event_espresso'),$model_name,$model_classname));
3802
+		if ( ! class_exists($model_classname)) {
3803
+			throw new EE_Error(sprintf(__("You specified a related model named %s in your query. No such model exists, if it did, it would have the classname %s", 'event_espresso'), $model_name, $model_classname));
3804 3804
 		}
3805 3805
 		return call_user_func($model_classname."::instance");
3806 3806
 	}
@@ -3810,7 +3810,7 @@  discard block
 block discarded – undo
3810 3810
 	 * Returns the array of EE_ModelRelations for this model.
3811 3811
 	 * @return EE_Model_Relation_Base[]
3812 3812
 	 */
3813
-	public function relation_settings(){
3813
+	public function relation_settings() {
3814 3814
 		return $this->_model_relations;
3815 3815
 	}
3816 3816
 
@@ -3820,10 +3820,10 @@  discard block
 block discarded – undo
3820 3820
 	 * (Eg, without an event, datetimes have little purpose.)
3821 3821
 	 * @return EE_Belongs_To_Relation[]
3822 3822
 	 */
3823
-	public function belongs_to_relations(){
3823
+	public function belongs_to_relations() {
3824 3824
 		$belongs_to_relations = array();
3825
-		foreach($this->relation_settings() as $model_name => $relation_obj){
3826
-			if($relation_obj instanceof EE_Belongs_To_Relation){
3825
+		foreach ($this->relation_settings() as $model_name => $relation_obj) {
3826
+			if ($relation_obj instanceof EE_Belongs_To_Relation) {
3827 3827
 				$belongs_to_relations[$model_name] = $relation_obj;
3828 3828
 			}
3829 3829
 		}
@@ -3838,15 +3838,15 @@  discard block
 block discarded – undo
3838 3838
 	 * @throws EE_Error
3839 3839
 	 * @return EE_Model_Relation_Base
3840 3840
 	 */
3841
-	public function related_settings_for($relation_name){
3842
-		$relatedModels=$this->relation_settings();
3843
-		if(!array_key_exists($relation_name,$relatedModels)){
3841
+	public function related_settings_for($relation_name) {
3842
+		$relatedModels = $this->relation_settings();
3843
+		if ( ! array_key_exists($relation_name, $relatedModels)) {
3844 3844
 			throw new EE_Error(
3845 3845
 				sprintf(
3846
-					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...','event_espresso'),
3846
+					__('Cannot get %s related to %s. There is no model relation of that type. There is, however, %s...', 'event_espresso'),
3847 3847
 					$relation_name,
3848 3848
 					$this->_get_class_name(),
3849
-					implode( ', ', array_keys( $relatedModels ))
3849
+					implode(', ', array_keys($relatedModels))
3850 3850
 				)
3851 3851
 			);
3852 3852
 		}
@@ -3861,10 +3861,10 @@  discard block
 block discarded – undo
3861 3861
 	 * @throws EE_Error
3862 3862
 	 * @return EE_Model_Field_Base
3863 3863
 	 */
3864
-	public function field_settings_for($fieldName){
3865
-		$fieldSettings=$this->field_settings(true);
3866
-		if( ! array_key_exists($fieldName,$fieldSettings)){
3867
-			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'",'event_espresso'),$fieldName,get_class($this)));
3864
+	public function field_settings_for($fieldName) {
3865
+		$fieldSettings = $this->field_settings(true);
3866
+		if ( ! array_key_exists($fieldName, $fieldSettings)) {
3867
+			throw new EE_Error(sprintf(__("There is no field/column '%s' on '%s'", 'event_espresso'), $fieldName, get_class($this)));
3868 3868
 		}
3869 3869
 		return $fieldSettings[$fieldName];
3870 3870
 	}
@@ -3874,11 +3874,11 @@  discard block
 block discarded – undo
3874 3874
 	 * @param string $fieldName a key in the model's _field_settings array
3875 3875
 	 * @return boolean
3876 3876
 	 */
3877
-	public function has_field($fieldName){
3877
+	public function has_field($fieldName) {
3878 3878
 		$fieldSettings = $this->field_settings(true);
3879
-		if( isset($fieldSettings[$fieldName])){
3879
+		if (isset($fieldSettings[$fieldName])) {
3880 3880
 			return true;
3881
-		}else{
3881
+		} else {
3882 3882
 			return false;
3883 3883
 		}
3884 3884
 	}
@@ -3888,11 +3888,11 @@  discard block
 block discarded – undo
3888 3888
 	 * @param string $relation_name possibly one of the keys in the relation_settings array
3889 3889
 	 * @return boolean
3890 3890
 	 */
3891
-	public function has_relation($relation_name){
3891
+	public function has_relation($relation_name) {
3892 3892
 		$relations = $this->relation_settings();
3893
-		if(isset($relations[$relation_name])){
3893
+		if (isset($relations[$relation_name])) {
3894 3894
 			return true;
3895
-		}else{
3895
+		} else {
3896 3896
 			return false;
3897 3897
 		}
3898 3898
 	}
@@ -3904,7 +3904,7 @@  discard block
 block discarded – undo
3904 3904
 	 * @param $field_obj
3905 3905
 	 * @return boolean
3906 3906
 	 */
3907
-	public function is_primary_key_field( $field_obj ){
3907
+	public function is_primary_key_field($field_obj) {
3908 3908
 		return $field_obj instanceof EE_Primary_Key_Field_Base ? TRUE : FALSE;
3909 3909
 	}
3910 3910
 
@@ -3916,16 +3916,16 @@  discard block
 block discarded – undo
3916 3916
 	 * @return EE_Model_Field_Base
3917 3917
 	 * @throws EE_Error
3918 3918
 	 */
3919
-	public function get_primary_key_field(){
3920
-		if( $this->_primary_key_field === NULL ){
3921
-			foreach( $this->field_settings( TRUE ) as $field_obj ){
3922
-				if( $this->is_primary_key_field( $field_obj )){
3919
+	public function get_primary_key_field() {
3920
+		if ($this->_primary_key_field === NULL) {
3921
+			foreach ($this->field_settings(TRUE) as $field_obj) {
3922
+				if ($this->is_primary_key_field($field_obj)) {
3923 3923
 					$this->_primary_key_field = $field_obj;
3924 3924
 					break;
3925 3925
 				}
3926 3926
 			}
3927
-			if( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base ){
3928
-				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s",'event_espresso'),get_class($this)));
3927
+			if ( ! $this->_primary_key_field instanceof EE_Primary_Key_Field_Base) {
3928
+				throw new EE_Error(sprintf(__("There is no Primary Key defined on model %s", 'event_espresso'), get_class($this)));
3929 3929
 			}
3930 3930
 		}
3931 3931
 		return $this->_primary_key_field;
@@ -3938,12 +3938,12 @@  discard block
 block discarded – undo
3938 3938
 	 * Internally does some caching.
3939 3939
 	 * @return boolean
3940 3940
 	 */
3941
-	public function has_primary_key_field(){
3942
-		if($this->_has_primary_key_field === null){
3943
-			try{
3941
+	public function has_primary_key_field() {
3942
+		if ($this->_has_primary_key_field === null) {
3943
+			try {
3944 3944
 				$this->get_primary_key_field();
3945 3945
 				$this->_has_primary_key_field = true;
3946
-			}catch(EE_Error $e){
3946
+			} catch (EE_Error $e) {
3947 3947
 				$this->_has_primary_key_field = false;
3948 3948
 			}
3949 3949
 		}
@@ -3957,9 +3957,9 @@  discard block
 block discarded – undo
3957 3957
 	 * @param string $field_class_name class name of field that you want to find. Eg, EE_Datetime_Field, EE_Foreign_Key_Field, etc
3958 3958
 	 * @return EE_Model_Field_Base or null if none is found
3959 3959
 	 */
3960
-	public function get_a_field_of_type($field_class_name){
3961
-		foreach($this->field_settings() as $field){
3962
-			if( $field instanceof $field_class_name ){
3960
+	public function get_a_field_of_type($field_class_name) {
3961
+		foreach ($this->field_settings() as $field) {
3962
+			if ($field instanceof $field_class_name) {
3963 3963
 				return $field;
3964 3964
 			}
3965 3965
 		}
@@ -3973,22 +3973,22 @@  discard block
 block discarded – undo
3973 3973
 	 * @return EE_Foreign_Key_Field_Base
3974 3974
 	 * @throws EE_Error
3975 3975
 	 */
3976
-	public function get_foreign_key_to($model_name){
3977
-		if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3978
-			foreach($this->field_settings() as $field){
3979
-				if(
3976
+	public function get_foreign_key_to($model_name) {
3977
+		if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3978
+			foreach ($this->field_settings() as $field) {
3979
+				if (
3980 3980
 					$field instanceof EE_Foreign_Key_Field_Base
3981
-					&& in_array($model_name,$field->get_model_names_pointed_to() )
3981
+					&& in_array($model_name, $field->get_model_names_pointed_to())
3982 3982
 				) {
3983
-					$this->_cache_foreign_key_to_fields[ $model_name ] = $field;
3983
+					$this->_cache_foreign_key_to_fields[$model_name] = $field;
3984 3984
 					break;
3985 3985
 				}
3986 3986
 			}
3987
-			if( ! isset( $this->_cache_foreign_key_to_fields[ $model_name ] ) ){
3988
-				throw new EE_Error(sprintf(__("There is no foreign key field pointing to model %s on model %s",'event_espresso'),$model_name,get_class($this)));
3987
+			if ( ! isset($this->_cache_foreign_key_to_fields[$model_name])) {
3988
+				throw new EE_Error(sprintf(__("There is no foreign key field pointing to model %s on model %s", 'event_espresso'), $model_name, get_class($this)));
3989 3989
 			}
3990 3990
 		}
3991
-		return $this->_cache_foreign_key_to_fields[ $model_name ];
3991
+		return $this->_cache_foreign_key_to_fields[$model_name];
3992 3992
 	}
3993 3993
 
3994 3994
 
@@ -3999,7 +3999,7 @@  discard block
 block discarded – undo
3999 3999
 	 * a table alias with a model chain prefix, like 'Venue__Event_Venue___Event_Meta'. Either one works
4000 4000
 	 * @return EE_Table_Base
4001 4001
 	 */
4002
-	public function get_table_for_alias($table_alias){
4002
+	public function get_table_for_alias($table_alias) {
4003 4003
 		$table_alias_sans_model_relation_chain_prefix = EE_Model_Parser::remove_table_alias_model_relation_chain_prefix($table_alias);
4004 4004
 		return $this->_tables[$table_alias_sans_model_relation_chain_prefix]->get_table_name();
4005 4005
 	}
@@ -4012,25 +4012,25 @@  discard block
 block discarded – undo
4012 4012
 	 * @param bool $include_db_only_fields flag indicating whether or not to include the db-only fields
4013 4013
 	 * @return EE_Model_Field_Base[] where the keys are the field's name
4014 4014
 	 */
4015
-	public function field_settings($include_db_only_fields = false){
4016
-		if( $include_db_only_fields ){
4017
-			if( $this->_cached_fields === NULL ){
4015
+	public function field_settings($include_db_only_fields = false) {
4016
+		if ($include_db_only_fields) {
4017
+			if ($this->_cached_fields === NULL) {
4018 4018
 				$this->_cached_fields = array();
4019
-				foreach($this->_fields as $fields_corresponding_to_table){
4020
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
4021
-						$this->_cached_fields[$field_name]=$field_obj;
4019
+				foreach ($this->_fields as $fields_corresponding_to_table) {
4020
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
4021
+						$this->_cached_fields[$field_name] = $field_obj;
4022 4022
 					}
4023 4023
 				}
4024 4024
 			}
4025 4025
 			return $this->_cached_fields;
4026
-		}else{
4027
-			if( $this->_cached_fields_non_db_only === NULL ){
4026
+		} else {
4027
+			if ($this->_cached_fields_non_db_only === NULL) {
4028 4028
 				$this->_cached_fields_non_db_only = array();
4029
-				foreach($this->_fields as $fields_corresponding_to_table){
4030
-					foreach($fields_corresponding_to_table as $field_name => $field_obj){
4029
+				foreach ($this->_fields as $fields_corresponding_to_table) {
4030
+					foreach ($fields_corresponding_to_table as $field_name => $field_obj) {
4031 4031
 						/** @var $field_obj EE_Model_Field_Base */
4032
-						if( ! $field_obj->is_db_only_field() ){
4033
-							$this->_cached_fields_non_db_only[$field_name]=$field_obj;
4032
+						if ( ! $field_obj->is_db_only_field()) {
4033
+							$this->_cached_fields_non_db_only[$field_name] = $field_obj;
4034 4034
 						}
4035 4035
 					}
4036 4036
 				}
@@ -4049,60 +4049,60 @@  discard block
 block discarded – undo
4049 4049
 	 * @return \EE_Base_Class[] array keys are primary keys (if there is a primary key on the model. if not, numerically indexed)
4050 4050
 	 * @throws \EE_Error
4051 4051
 	 */
4052
-	protected function _create_objects( $rows = array() ) {
4053
-		$array_of_objects=array();
4054
-		if(empty($rows)){
4052
+	protected function _create_objects($rows = array()) {
4053
+		$array_of_objects = array();
4054
+		if (empty($rows)) {
4055 4055
 			return array();
4056 4056
 		}
4057 4057
 		$count_if_model_has_no_primary_key = 0;
4058 4058
 		$has_primary_key = $this->has_primary_key_field();
4059 4059
 		$primary_key_field = $has_primary_key ? $this->get_primary_key_field() : null;
4060
-		foreach ( (array)$rows as $row ) {
4061
-			if(empty($row)){
4060
+		foreach ((array) $rows as $row) {
4061
+			if (empty($row)) {
4062 4062
 				//wp did its weird thing where it returns an array like array(0=>null), which is totally not helpful...
4063 4063
 				return array();
4064 4064
 			}
4065 4065
 			//check if we've already set this object in the results array,
4066 4066
 			//in which case there's no need to process it further (again)
4067
-			if( $has_primary_key ) {
4067
+			if ($has_primary_key) {
4068 4068
 				$table_pk_value = $this->_get_column_value_with_table_alias_or_not(
4069 4069
 					$row,
4070 4070
 					$primary_key_field->get_qualified_column(),
4071 4071
 					$primary_key_field->get_table_column()
4072 4072
 				);
4073
-				if( $table_pk_value && isset( $array_of_objects[ $table_pk_value ] ) ) {
4073
+				if ($table_pk_value && isset($array_of_objects[$table_pk_value])) {
4074 4074
 					continue;
4075 4075
 				}
4076 4076
 			}
4077 4077
 			$classInstance = $this->instantiate_class_from_array_or_object($row);
4078
-			if( ! $classInstance ) {
4078
+			if ( ! $classInstance) {
4079 4079
 				throw new EE_Error(
4080 4080
 					sprintf(
4081
-						__( 'Could not create instance of class %s from row %s', 'event_espresso' ),
4081
+						__('Could not create instance of class %s from row %s', 'event_espresso'),
4082 4082
 						$this->get_this_model_name(),
4083
-						http_build_query( $row )
4083
+						http_build_query($row)
4084 4084
 					)
4085 4085
 				);
4086 4086
 			}
4087 4087
 			//set the timezone on the instantiated objects
4088
-			$classInstance->set_timezone( $this->_timezone );
4088
+			$classInstance->set_timezone($this->_timezone);
4089 4089
 			//make sure if there is any timezone setting present that we set the timezone for the object
4090 4090
 			$key = $has_primary_key ? $classInstance->ID() : $count_if_model_has_no_primary_key++;
4091
-			$array_of_objects[ $key ] = $classInstance;
4091
+			$array_of_objects[$key] = $classInstance;
4092 4092
 			//also, for all the relations of type BelongsTo, see if we can cache
4093 4093
 			//those related models
4094 4094
 			//(we could do this for other relations too, but if there are conditions
4095 4095
 			//that filtered out some fo the results, then we'd be caching an incomplete set
4096 4096
 			//so it requires a little more thought than just caching them immediately...)
4097
-			foreach($this->_model_relations as $modelName => $relation_obj){
4098
-				if( $relation_obj instanceof EE_Belongs_To_Relation){
4097
+			foreach ($this->_model_relations as $modelName => $relation_obj) {
4098
+				if ($relation_obj instanceof EE_Belongs_To_Relation) {
4099 4099
 					//check if this model's INFO is present. If so, cache it on the model
4100 4100
 					$other_model = $relation_obj->get_other_model();
4101 4101
 					$other_model_obj_maybe = $other_model->instantiate_class_from_array_or_object($row);
4102 4102
 					//if we managed to make a model object from the results, cache it on the main model object
4103
-					if( $other_model_obj_maybe ){
4103
+					if ($other_model_obj_maybe) {
4104 4104
 						//set timezone on these other model objects if they are present
4105
-						$other_model_obj_maybe->set_timezone( $this->_timezone );
4105
+						$other_model_obj_maybe->set_timezone($this->_timezone);
4106 4106
 						$classInstance->cache($modelName, $other_model_obj_maybe);
4107 4107
 					}
4108 4108
 				}
@@ -4123,12 +4123,12 @@  discard block
 block discarded – undo
4123 4123
 
4124 4124
 		$this_model_fields_and_values = array();
4125 4125
 		//setup the row using default values;
4126
-		foreach ( $this->field_settings() as $field_name => $field_obj ) {
4126
+		foreach ($this->field_settings() as $field_name => $field_obj) {
4127 4127
 			$this_model_fields_and_values[$field_name] = $field_obj->get_default_value();
4128 4128
 		}
4129 4129
 
4130 4130
 		$className = $this->_get_class_name();
4131
-		$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_and_values ), FALSE, FALSE );
4131
+		$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_and_values), FALSE, FALSE);
4132 4132
 
4133 4133
 		return $classInstance;
4134 4134
 	}
@@ -4141,45 +4141,45 @@  discard block
 block discarded – undo
4141 4141
 	 * @return EE_Base_Class
4142 4142
 	 * @throws \EE_Error
4143 4143
 	 */
4144
-	public function instantiate_class_from_array_or_object($cols_n_values){
4145
-		if( ! is_array( $cols_n_values ) && is_object( $cols_n_values )) {
4146
-			$cols_n_values = get_object_vars( $cols_n_values );
4144
+	public function instantiate_class_from_array_or_object($cols_n_values) {
4145
+		if ( ! is_array($cols_n_values) && is_object($cols_n_values)) {
4146
+			$cols_n_values = get_object_vars($cols_n_values);
4147 4147
 		}
4148 4148
 		$primary_key = NULL;
4149 4149
 		//make sure the array only has keys that are fields/columns on this model
4150
-		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
4151
-		if( $this->has_primary_key_field() && isset( $this_model_fields_n_values[ $this->primary_key_name() ] ) ){
4152
-			$primary_key = $this_model_fields_n_values[ $this->primary_key_name() ];
4150
+		$this_model_fields_n_values = $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
4151
+		if ($this->has_primary_key_field() && isset($this_model_fields_n_values[$this->primary_key_name()])) {
4152
+			$primary_key = $this_model_fields_n_values[$this->primary_key_name()];
4153 4153
 		}
4154
-		$className=$this->_get_class_name();
4154
+		$className = $this->_get_class_name();
4155 4155
 
4156 4156
 		//check we actually found results that we can use to build our model object
4157 4157
 		//if not, return null
4158
-		if( $this->has_primary_key_field()){
4159
-			if(empty( $this_model_fields_n_values[$this->primary_key_name()] )){
4158
+		if ($this->has_primary_key_field()) {
4159
+			if (empty($this_model_fields_n_values[$this->primary_key_name()])) {
4160 4160
 				return NULL;
4161 4161
 			}
4162
-		}else if($this->unique_indexes()){
4162
+		} else if ($this->unique_indexes()) {
4163 4163
 			$first_column = reset($this_model_fields_n_values);
4164
-			if(empty($first_column)){
4164
+			if (empty($first_column)) {
4165 4165
 				return NULL;
4166 4166
 			}
4167 4167
 		}
4168 4168
 
4169 4169
 		// if there is no primary key or the object doesn't already exist in the entity map, then create a new instance
4170
-		if ( $primary_key){
4171
-			$classInstance = $this->get_from_entity_map( $primary_key );
4172
-			if( ! $classInstance) {
4173
-				$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
4170
+		if ($primary_key) {
4171
+			$classInstance = $this->get_from_entity_map($primary_key);
4172
+			if ( ! $classInstance) {
4173
+				$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
4174 4174
 				// add this new object to the entity map
4175
-				$classInstance = $this->add_to_entity_map( $classInstance );
4175
+				$classInstance = $this->add_to_entity_map($classInstance);
4176 4176
 			}
4177
-		}else{
4178
-			$classInstance = EE_Registry::instance()->load_class( $className, array( $this_model_fields_n_values, $this->_timezone ), TRUE, FALSE );
4177
+		} else {
4178
+			$classInstance = EE_Registry::instance()->load_class($className, array($this_model_fields_n_values, $this->_timezone), TRUE, FALSE);
4179 4179
 		}
4180 4180
 
4181 4181
 			//it is entirely possible that the instantiated class object has a set timezone_string db field and has set it's internal _timezone property accordingly (see new_instance_from_db in model objects particularly EE_Event for example).  In this case, we want to make sure the model object doesn't have its timezone string overwritten by any timezone property currently set here on the model so, we intentionally override the model _timezone property with the model_object timezone property.
4182
-		$this->set_timezone( $classInstance->get_timezone() );
4182
+		$this->set_timezone($classInstance->get_timezone());
4183 4183
 		return $classInstance;
4184 4184
 	}
4185 4185
 	/**
@@ -4187,8 +4187,8 @@  discard block
 block discarded – undo
4187 4187
 	 * @param int|string $id the ID of the model object
4188 4188
 	 * @return EE_Base_Class
4189 4189
 	 */
4190
-	public function get_from_entity_map( $id ){
4191
-		return isset( $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $id ] ) ? $this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $id ] : NULL;
4190
+	public function get_from_entity_map($id) {
4191
+		return isset($this->_entity_map[EEM_Base::$_model_query_blog_id][$id]) ? $this->_entity_map[EEM_Base::$_model_query_blog_id][$id] : NULL;
4192 4192
 	}
4193 4193
 
4194 4194
 
@@ -4210,21 +4210,21 @@  discard block
 block discarded – undo
4210 4210
 	 * @throws EE_Error
4211 4211
 	 * @return \EE_Base_Class
4212 4212
 	 */
4213
-	public function add_to_entity_map( EE_Base_Class $object) {
4213
+	public function add_to_entity_map(EE_Base_Class $object) {
4214 4214
 		$className = $this->_get_class_name();
4215
-		if( ! $object instanceof $className ){
4216
-			throw new EE_Error(sprintf(__("You tried adding a %s to a mapping of %ss", "event_espresso"),is_object( $object ) ? get_class( $object ) : $object, $className ) );
4215
+		if ( ! $object instanceof $className) {
4216
+			throw new EE_Error(sprintf(__("You tried adding a %s to a mapping of %ss", "event_espresso"), is_object($object) ? get_class($object) : $object, $className));
4217 4217
 		}
4218 4218
 		/** @var $object EE_Base_Class */
4219
-		if ( ! $object->ID() ){
4220
-			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"),get_class($this)));
4219
+		if ( ! $object->ID()) {
4220
+			throw new EE_Error(sprintf(__("You tried storing a model object with NO ID in the %s entity mapper.", "event_espresso"), get_class($this)));
4221 4221
 		}
4222 4222
 		// double check it's not already there
4223
-		$classInstance = $this->get_from_entity_map( $object->ID() );
4224
-		if ( $classInstance ) {
4223
+		$classInstance = $this->get_from_entity_map($object->ID());
4224
+		if ($classInstance) {
4225 4225
 			return $classInstance;
4226 4226
 		} else {
4227
-			$this->_entity_map[ EEM_Base::$_model_query_blog_id ][ $object->ID() ] = $object;
4227
+			$this->_entity_map[EEM_Base::$_model_query_blog_id][$object->ID()] = $object;
4228 4228
 			return $object;
4229 4229
 		}
4230 4230
 	}
@@ -4237,8 +4237,8 @@  discard block
 block discarded – undo
4237 4237
 	 * @param array $cols_n_values
4238 4238
 	 * @return array
4239 4239
 	 */
4240
-	public function deduce_fields_n_values_from_cols_n_values( $cols_n_values ) {
4241
-		return $this->_deduce_fields_n_values_from_cols_n_values( $cols_n_values );
4240
+	public function deduce_fields_n_values_from_cols_n_values($cols_n_values) {
4241
+		return $this->_deduce_fields_n_values_from_cols_n_values($cols_n_values);
4242 4242
 	}
4243 4243
 
4244 4244
 
@@ -4251,23 +4251,23 @@  discard block
 block discarded – undo
4251 4251
 	 * @param string $cols_n_values
4252 4252
 	 * @return array
4253 4253
 	 */
4254
-	protected function _deduce_fields_n_values_from_cols_n_values( $cols_n_values ){
4254
+	protected function _deduce_fields_n_values_from_cols_n_values($cols_n_values) {
4255 4255
 		$this_model_fields_n_values = array();
4256
-		foreach( $this->get_tables() as $table_alias => $table_obj ) {
4257
-			$table_pk_value = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $table_obj->get_fully_qualified_pk_column(), $table_obj->get_pk_column() );
4256
+		foreach ($this->get_tables() as $table_alias => $table_obj) {
4257
+			$table_pk_value = $this->_get_column_value_with_table_alias_or_not($cols_n_values, $table_obj->get_fully_qualified_pk_column(), $table_obj->get_pk_column());
4258 4258
 			//there is a primary key on this table and its not set. Use defaults for all its columns
4259
-			if( $table_pk_value === null && $table_obj->get_pk_column() ){
4260
-				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
4261
-					if( ! $field_obj->is_db_only_field() ){
4259
+			if ($table_pk_value === null && $table_obj->get_pk_column()) {
4260
+				foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) {
4261
+					if ( ! $field_obj->is_db_only_field()) {
4262 4262
 						//prepare field as if its coming from db
4263
-						$prepared_value = $field_obj->prepare_for_set( $field_obj->get_default_value() );
4264
-						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db( $prepared_value );
4263
+						$prepared_value = $field_obj->prepare_for_set($field_obj->get_default_value());
4264
+						$this_model_fields_n_values[$field_name] = $field_obj->prepare_for_use_in_db($prepared_value);
4265 4265
 					}
4266 4266
 				}
4267
-			}else{
4267
+			} else {
4268 4268
 				//the table's rows existed. Use their values
4269
-				foreach( $this->_get_fields_for_table( $table_alias ) as $field_name => $field_obj ) {
4270
-					if( ! $field_obj->is_db_only_field() ){
4269
+				foreach ($this->_get_fields_for_table($table_alias) as $field_name => $field_obj) {
4270
+					if ( ! $field_obj->is_db_only_field()) {
4271 4271
 						$this_model_fields_n_values[$field_name] = $this->_get_column_value_with_table_alias_or_not(
4272 4272
 							$cols_n_values, $field_obj->get_qualified_column(),
4273 4273
 							$field_obj->get_table_column()
@@ -4287,15 +4287,15 @@  discard block
 block discarded – undo
4287 4287
 	 * @param $regular_column
4288 4288
 	 * @return null
4289 4289
 	 */
4290
-	protected function _get_column_value_with_table_alias_or_not( $cols_n_values, $qualified_column, $regular_column ){
4290
+	protected function _get_column_value_with_table_alias_or_not($cols_n_values, $qualified_column, $regular_column) {
4291 4291
 		$value = null;
4292 4292
 		//ask the field what it think it's table_name.column_name should be, and call it the "qualified column"
4293 4293
 		//does the field on the model relate to this column retrieved from the db?
4294 4294
 		//or is it a db-only field? (not relating to the model)
4295
-		if( isset( $cols_n_values[ $qualified_column ] ) ){
4296
-			$value = $cols_n_values[ $qualified_column ];
4297
-		}elseif( isset( $cols_n_values[ $regular_column ] ) ){
4298
-			$value = $cols_n_values[ $regular_column ];
4295
+		if (isset($cols_n_values[$qualified_column])) {
4296
+			$value = $cols_n_values[$qualified_column];
4297
+		}elseif (isset($cols_n_values[$regular_column])) {
4298
+			$value = $cols_n_values[$regular_column];
4299 4299
 		}
4300 4300
 		return $value;
4301 4301
 	}
@@ -4311,25 +4311,25 @@  discard block
 block discarded – undo
4311 4311
 	 * @return EE_Base_Class
4312 4312
 	 * @throws \EE_Error
4313 4313
 	 */
4314
-	public function refresh_entity_map_from_db( $id ){
4315
-		$obj_in_map = $this->get_from_entity_map( $id );
4316
-		if( $obj_in_map ){
4314
+	public function refresh_entity_map_from_db($id) {
4315
+		$obj_in_map = $this->get_from_entity_map($id);
4316
+		if ($obj_in_map) {
4317 4317
 			$wpdb_results = $this->_get_all_wpdb_results(
4318
-				array( array( $this->get_primary_key_field()->get_name() => $id ), 'limit' => 1 )
4318
+				array(array($this->get_primary_key_field()->get_name() => $id), 'limit' => 1)
4319 4319
 			);
4320
-			if( $wpdb_results && is_array( $wpdb_results ) ){
4321
-				$one_row = reset( $wpdb_results );
4322
-				foreach( $this->_deduce_fields_n_values_from_cols_n_values($one_row ) as $field_name => $db_value ) {
4323
-					$obj_in_map->set_from_db( $field_name, $db_value );
4320
+			if ($wpdb_results && is_array($wpdb_results)) {
4321
+				$one_row = reset($wpdb_results);
4322
+				foreach ($this->_deduce_fields_n_values_from_cols_n_values($one_row) as $field_name => $db_value) {
4323
+					$obj_in_map->set_from_db($field_name, $db_value);
4324 4324
 				}
4325 4325
 				//clear the cache of related model objects
4326
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
4327
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
4326
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
4327
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
4328 4328
 				}
4329 4329
 			}
4330 4330
 			return $obj_in_map;
4331
-		}else{
4332
-			return $this->get_one_by_ID( $id );
4331
+		} else {
4332
+			return $this->get_one_by_ID($id);
4333 4333
 		}
4334 4334
 	}
4335 4335
 
@@ -4347,24 +4347,24 @@  discard block
 block discarded – undo
4347 4347
 	 * @return \EE_Base_Class
4348 4348
 	 * @throws \EE_Error
4349 4349
 	 */
4350
-	public function refresh_entity_map_with( $id, $replacing_model_obj ) {
4351
-		$obj_in_map = $this->get_from_entity_map( $id );
4352
-		if( $obj_in_map ){
4353
-			if( $replacing_model_obj instanceof EE_Base_Class ){
4354
-				foreach( $replacing_model_obj->model_field_array() as $field_name => $value ) {
4355
-					$obj_in_map->set( $field_name, $value );
4350
+	public function refresh_entity_map_with($id, $replacing_model_obj) {
4351
+		$obj_in_map = $this->get_from_entity_map($id);
4352
+		if ($obj_in_map) {
4353
+			if ($replacing_model_obj instanceof EE_Base_Class) {
4354
+				foreach ($replacing_model_obj->model_field_array() as $field_name => $value) {
4355
+					$obj_in_map->set($field_name, $value);
4356 4356
 				}
4357 4357
 				//make the model object in the entity map's cache match the $replacing_model_obj
4358
-				foreach ( $this->relation_settings() as $relation_name => $relation_obj ){
4359
-					$obj_in_map->clear_cache($relation_name, NULL, TRUE );
4360
-					foreach( $replacing_model_obj->get_all_from_cache( $relation_name ) as $cache_id => $cached_obj ) {
4361
-						$obj_in_map->cache( $relation_name, $cached_obj, $cache_id );
4358
+				foreach ($this->relation_settings() as $relation_name => $relation_obj) {
4359
+					$obj_in_map->clear_cache($relation_name, NULL, TRUE);
4360
+					foreach ($replacing_model_obj->get_all_from_cache($relation_name) as $cache_id => $cached_obj) {
4361
+						$obj_in_map->cache($relation_name, $cached_obj, $cache_id);
4362 4362
 					}
4363 4363
 				}
4364 4364
 			}
4365 4365
 			return $obj_in_map;
4366
-		}else{
4367
-			$this->add_to_entity_map( $replacing_model_obj );
4366
+		} else {
4367
+			$this->add_to_entity_map($replacing_model_obj);
4368 4368
 			return $replacing_model_obj;
4369 4369
 		}
4370 4370
 	}
@@ -4377,7 +4377,7 @@  discard block
 block discarded – undo
4377 4377
 	 * require_once($this->_getClassName().".class.php");
4378 4378
 	 * @return string
4379 4379
 	 */
4380
-	private function _get_class_name(){
4380
+	private function _get_class_name() {
4381 4381
 		return "EE_".$this->get_this_model_name();
4382 4382
 	}
4383 4383
 
@@ -4390,8 +4390,8 @@  discard block
 block discarded – undo
4390 4390
 	 * @param int $quantity
4391 4391
 	 * @return string
4392 4392
 	 */
4393
-	public function item_name($quantity = 1){
4394
-		return (int)$quantity === 1 ? $this->singular_item : $this->plural_item;
4393
+	public function item_name($quantity = 1) {
4394
+		return (int) $quantity === 1 ? $this->singular_item : $this->plural_item;
4395 4395
 	}
4396 4396
 
4397 4397
 
@@ -4418,13 +4418,13 @@  discard block
 block discarded – undo
4418 4418
 	 * @throws EE_Error
4419 4419
 	 * @return mixed whatever the plugin which calls add_filter decides
4420 4420
 	 */
4421
-	public function __call($methodName,$args){
4422
-		$className=get_class($this);
4423
-		$tagName="FHEE__{$className}__{$methodName}";
4424
-		if(!has_filter($tagName)){
4421
+	public function __call($methodName, $args) {
4422
+		$className = get_class($this);
4423
+		$tagName = "FHEE__{$className}__{$methodName}";
4424
+		if ( ! has_filter($tagName)) {
4425 4425
 			throw new EE_Error(
4426 4426
 				sprintf(
4427
-					__( 'Method %1$s on model %2$s does not exist! You can create one with the following code in functions.php or in a plugin: %4$s function my_callback(%4$s \$previousReturnValue, EEM_Base \$object\ $argsArray=NULL ){%4$s     /*function body*/%4$s      return \$whatever;%4$s }%4$s add_filter( \'%3$s\', \'my_callback\', 10, 3 );', 'event_espresso' ),
4427
+					__('Method %1$s on model %2$s does not exist! You can create one with the following code in functions.php or in a plugin: %4$s function my_callback(%4$s \$previousReturnValue, EEM_Base \$object\ $argsArray=NULL ){%4$s     /*function body*/%4$s      return \$whatever;%4$s }%4$s add_filter( \'%3$s\', \'my_callback\', 10, 3 );', 'event_espresso'),
4428 4428
 					$methodName,
4429 4429
 					$className,
4430 4430
 					$tagName,
@@ -4433,7 +4433,7 @@  discard block
 block discarded – undo
4433 4433
 			);
4434 4434
 		}
4435 4435
 
4436
-		return apply_filters($tagName,null,$this,$args);
4436
+		return apply_filters($tagName, null, $this, $args);
4437 4437
 	}
4438 4438
 
4439 4439
 
@@ -4451,28 +4451,28 @@  discard block
 block discarded – undo
4451 4451
 	 * @throws EE_Error
4452 4452
 	 * @return EE_Base_Class
4453 4453
 	 */
4454
-	public function ensure_is_obj( $base_class_obj_or_id, $ensure_is_in_db = FALSE ){
4454
+	public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = FALSE) {
4455 4455
 		$className = $this->_get_class_name();
4456
-		if ( $base_class_obj_or_id instanceof $className ) {
4456
+		if ($base_class_obj_or_id instanceof $className) {
4457 4457
 			$model_object = $base_class_obj_or_id;
4458 4458
 		} else {
4459 4459
 			$primary_key_field = $this->get_primary_key_field();
4460 4460
 			if (
4461 4461
 				$primary_key_field instanceof EE_Primary_Key_Int_Field
4462 4462
 				&& (
4463
-					is_int( $base_class_obj_or_id )
4464
-					|| is_string( $base_class_obj_or_id )
4463
+					is_int($base_class_obj_or_id)
4464
+					|| is_string($base_class_obj_or_id)
4465 4465
 				)
4466 4466
 			) {
4467 4467
 				// assume it's an ID.
4468 4468
 				// either a proper integer or a string representing an integer (eg "101" instead of 101)
4469
-				$model_object = $this->get_one_by_ID( $base_class_obj_or_id );
4469
+				$model_object = $this->get_one_by_ID($base_class_obj_or_id);
4470 4470
 			} else if (
4471 4471
 				$primary_key_field instanceof EE_Primary_Key_String_Field
4472
-			    && is_string( $base_class_obj_or_id )
4472
+			    && is_string($base_class_obj_or_id)
4473 4473
 			) {
4474 4474
 				// assume its a string representation of the object
4475
-				$model_object = $this->get_one_by_ID( $base_class_obj_or_id );
4475
+				$model_object = $this->get_one_by_ID($base_class_obj_or_id);
4476 4476
 			} else {
4477 4477
 				throw new EE_Error(
4478 4478
 					sprintf(
@@ -4482,12 +4482,12 @@  discard block
 block discarded – undo
4482 4482
 						),
4483 4483
 						$base_class_obj_or_id,
4484 4484
 						$this->_get_class_name(),
4485
-						print_r( $base_class_obj_or_id, true )
4485
+						print_r($base_class_obj_or_id, true)
4486 4486
 					)
4487 4487
 				);
4488 4488
 			}
4489 4489
 		}
4490
-		if ( $ensure_is_in_db && $model_object->ID() !== null ) {
4490
+		if ($ensure_is_in_db && $model_object->ID() !== null) {
4491 4491
 			$model_object->save();
4492 4492
 		}
4493 4493
 		return $model_object;
@@ -4503,19 +4503,19 @@  discard block
 block discarded – undo
4503 4503
 	 * @return int|string depending on the type of this model object's ID
4504 4504
 	 * @throws EE_Error
4505 4505
 	 */
4506
-	public function ensure_is_ID($base_class_obj_or_id){
4506
+	public function ensure_is_ID($base_class_obj_or_id) {
4507 4507
 		$className = $this->_get_class_name();
4508
-		if( $base_class_obj_or_id instanceof $className ){
4508
+		if ($base_class_obj_or_id instanceof $className) {
4509 4509
 			/** @var $base_class_obj_or_id EE_Base_Class */
4510 4510
 			$id = $base_class_obj_or_id->ID();
4511
-		}elseif(is_int($base_class_obj_or_id)){
4511
+		}elseif (is_int($base_class_obj_or_id)) {
4512 4512
 			//assume it's an ID
4513 4513
 			$id = $base_class_obj_or_id;
4514
-		}elseif(is_string($base_class_obj_or_id)){
4514
+		}elseif (is_string($base_class_obj_or_id)) {
4515 4515
 			//assume its a string representation of the object
4516 4516
 			$id = $base_class_obj_or_id;
4517
-		}else{
4518
-			throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'",'event_espresso'),$base_class_obj_or_id,$this->_get_class_name(),print_r($base_class_obj_or_id,true)));
4517
+		} else {
4518
+			throw new EE_Error(sprintf(__("'%s' is neither an object of type %s, nor an ID! Its full value is '%s'", 'event_espresso'), $base_class_obj_or_id, $this->_get_class_name(), print_r($base_class_obj_or_id, true)));
4519 4519
 		}
4520 4520
 		return $id;
4521 4521
 	}
@@ -4538,14 +4538,14 @@  discard block
 block discarded – undo
4538 4538
 	 * @param int $values_already_prepared like one of the constants on EEM_Base
4539 4539
 	 * @return void
4540 4540
 	 */
4541
-	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object){
4541
+	public function assume_values_already_prepared_by_model_object($values_already_prepared = self::not_prepared_by_model_object) {
4542 4542
 		$this->_values_already_prepared_by_model_object = $values_already_prepared;
4543 4543
 	}
4544 4544
 	/**
4545 4545
 	 * Read comments for assume_values_already_prepared_by_model_object()
4546 4546
 	 * @return int
4547 4547
 	 */
4548
-	public function get_assumption_concerning_values_already_prepared_by_model_object(){
4548
+	public function get_assumption_concerning_values_already_prepared_by_model_object() {
4549 4549
 		return $this->_values_already_prepared_by_model_object;
4550 4550
 	}
4551 4551
 
@@ -4553,17 +4553,17 @@  discard block
 block discarded – undo
4553 4553
 	 * Gets all the indexes on this model
4554 4554
 	 * @return EE_Index[]
4555 4555
 	 */
4556
-	public function indexes(){
4556
+	public function indexes() {
4557 4557
 		return $this->_indexes;
4558 4558
 	}
4559 4559
 	/**
4560 4560
 	 * Gets all the Unique Indexes on this model
4561 4561
 	 * @return EE_Unique_Index[]
4562 4562
 	 */
4563
-	public function unique_indexes(){
4563
+	public function unique_indexes() {
4564 4564
 		$unique_indexes = array();
4565
-		foreach($this->_indexes as $name => $index){
4566
-			if($index instanceof EE_Unique_Index){
4565
+		foreach ($this->_indexes as $name => $index) {
4566
+			if ($index instanceof EE_Unique_Index) {
4567 4567
 				$unique_indexes [$name] = $index;
4568 4568
 			}
4569 4569
 		}
@@ -4581,13 +4581,13 @@  discard block
 block discarded – undo
4581 4581
 	 * @return EE_Model_Field_Base[] indexed by the field's name
4582 4582
 	 * @throws \EE_Error
4583 4583
 	 */
4584
-	public function get_combined_primary_key_fields(){
4585
-		foreach($this->indexes() as $index){
4586
-			if($index instanceof EE_Primary_Key_Index){
4584
+	public function get_combined_primary_key_fields() {
4585
+		foreach ($this->indexes() as $index) {
4586
+			if ($index instanceof EE_Primary_Key_Index) {
4587 4587
 				return $index->fields();
4588 4588
 			}
4589 4589
 		}
4590
-		return array( $this->primary_key_name() => $this->get_primary_key_field());
4590
+		return array($this->primary_key_name() => $this->get_primary_key_field());
4591 4591
 	}
4592 4592
 
4593 4593
 
@@ -4601,7 +4601,7 @@  discard block
 block discarded – undo
4601 4601
 	 * @return string
4602 4602
 	 * @throws \EE_Error
4603 4603
 	 */
4604
-	public function get_index_primary_key_string($cols_n_values){
4604
+	public function get_index_primary_key_string($cols_n_values) {
4605 4605
 		$cols_n_values_for_primary_key_index = array_intersect_key($cols_n_values, $this->get_combined_primary_key_fields());
4606 4606
 		return http_build_query($cols_n_values_for_primary_key_index);
4607 4607
 	}
@@ -4616,13 +4616,13 @@  discard block
 block discarded – undo
4616 4616
 	 * @return null|array
4617 4617
 	 * @throws \EE_Error
4618 4618
 	 */
4619
-	public function parse_index_primary_key_string( $index_primary_key_string) {
4619
+	public function parse_index_primary_key_string($index_primary_key_string) {
4620 4620
 		$key_fields = $this->get_combined_primary_key_fields();
4621 4621
 		//check all of them are in the $id
4622 4622
 		$key_vals_in_combined_pk = array();
4623
-		parse_str( $index_primary_key_string, $key_vals_in_combined_pk );
4624
-		foreach( $key_fields as $key_field_name => $field_obj ) {
4625
-			if( ! isset( $key_vals_in_combined_pk[ $key_field_name ] ) ){
4623
+		parse_str($index_primary_key_string, $key_vals_in_combined_pk);
4624
+		foreach ($key_fields as $key_field_name => $field_obj) {
4625
+			if ( ! isset($key_vals_in_combined_pk[$key_field_name])) {
4626 4626
 				return NULL;
4627 4627
 			}
4628 4628
 		}
@@ -4639,10 +4639,10 @@  discard block
 block discarded – undo
4639 4639
 	 * @return boolean
4640 4640
 	 * @throws \EE_Error
4641 4641
 	 */
4642
-	public function has_all_combined_primary_key_fields( $key_vals ) {
4643
-		$keys_it_should_have = array_keys( $this->get_combined_primary_key_fields() );
4644
-		foreach( $keys_it_should_have as $key ){
4645
-			if( ! isset( $key_vals[ $key ] ) ){
4642
+	public function has_all_combined_primary_key_fields($key_vals) {
4643
+		$keys_it_should_have = array_keys($this->get_combined_primary_key_fields());
4644
+		foreach ($keys_it_should_have as $key) {
4645
+			if ( ! isset($key_vals[$key])) {
4646 4646
 				return false;
4647 4647
 			}
4648 4648
 		}
@@ -4658,23 +4658,23 @@  discard block
 block discarded – undo
4658 4658
 	 * @throws EE_Error
4659 4659
 	 * @return \EE_Base_Class[] Array keys are object IDs (if there is a primary key on the model. if not, numerically indexed)
4660 4660
 	 */
4661
-	public function get_all_copies($model_object_or_attributes_array, $query_params = array()){
4661
+	public function get_all_copies($model_object_or_attributes_array, $query_params = array()) {
4662 4662
 
4663
-		if($model_object_or_attributes_array instanceof EE_Base_Class){
4663
+		if ($model_object_or_attributes_array instanceof EE_Base_Class) {
4664 4664
 			$attributes_array = $model_object_or_attributes_array->model_field_array();
4665
-		}elseif(is_array($model_object_or_attributes_array)){
4665
+		}elseif (is_array($model_object_or_attributes_array)) {
4666 4666
 			$attributes_array = $model_object_or_attributes_array;
4667
-		}else{
4668
-			throw new EE_Error(sprintf(__("get_all_copies should be provided with either a model object or an array of field-value-pairs, but was given %s", "event_espresso"),$model_object_or_attributes_array));
4667
+		} else {
4668
+			throw new EE_Error(sprintf(__("get_all_copies should be provided with either a model object or an array of field-value-pairs, but was given %s", "event_espresso"), $model_object_or_attributes_array));
4669 4669
 		}
4670 4670
 		//even copies obviously won't have the same ID, so remove the primary key
4671 4671
 		//from the WHERE conditions for finding copies (if there is a primary key, of course)
4672
-		if($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])){
4672
+		if ($this->has_primary_key_field() && isset($attributes_array[$this->primary_key_name()])) {
4673 4673
 			unset($attributes_array[$this->primary_key_name()]);
4674 4674
 		}
4675
-		if(isset($query_params[0])){
4676
-			$query_params[0] = array_merge($attributes_array,$query_params);
4677
-		}else{
4675
+		if (isset($query_params[0])) {
4676
+			$query_params[0] = array_merge($attributes_array, $query_params);
4677
+		} else {
4678 4678
 			$query_params[0] = $attributes_array;
4679 4679
 		}
4680 4680
 		return $this->get_all($query_params);
@@ -4690,16 +4690,16 @@  discard block
 block discarded – undo
4690 4690
 	 * @return EE_Base_Class
4691 4691
 	 * @throws \EE_Error
4692 4692
 	 */
4693
-	public function get_one_copy($model_object_or_attributes_array,$query_params = array()){
4694
-		if( ! is_array( $query_params ) ){
4695
-			EE_Error::doing_it_wrong('EEM_Base::get_one_copy', sprintf( __( '$query_params should be an array, you passed a variable of type %s', 'event_espresso' ), gettype( $query_params ) ), '4.6.0' );
4693
+	public function get_one_copy($model_object_or_attributes_array, $query_params = array()) {
4694
+		if ( ! is_array($query_params)) {
4695
+			EE_Error::doing_it_wrong('EEM_Base::get_one_copy', sprintf(__('$query_params should be an array, you passed a variable of type %s', 'event_espresso'), gettype($query_params)), '4.6.0');
4696 4696
 			$query_params = array();
4697 4697
 		}
4698 4698
 		$query_params['limit'] = 1;
4699
-		$copies = $this->get_all_copies($model_object_or_attributes_array,$query_params);
4700
-		if(is_array($copies)){
4699
+		$copies = $this->get_all_copies($model_object_or_attributes_array, $query_params);
4700
+		if (is_array($copies)) {
4701 4701
 			return array_shift($copies);
4702
-		}else{
4702
+		} else {
4703 4703
 			return null;
4704 4704
 		}
4705 4705
 	}
@@ -4715,10 +4715,10 @@  discard block
 block discarded – undo
4715 4715
 	 * @return int number of rows updated
4716 4716
 	 * @throws \EE_Error
4717 4717
 	 */
4718
-	public function update_by_ID($fields_n_values,$id){
4718
+	public function update_by_ID($fields_n_values, $id) {
4719 4719
 		$query_params = array(0=>array($this->get_primary_key_field()->get_name() => $id),
4720 4720
 			'default_where_conditions'=>'other_models_only',);
4721
-		return $this->update($fields_n_values,$query_params);
4721
+		return $this->update($fields_n_values, $query_params);
4722 4722
 	}
4723 4723
 
4724 4724
 
@@ -4729,12 +4729,12 @@  discard block
 block discarded – undo
4729 4729
 	 * @return string an operator which can be used in SQL
4730 4730
 	 * @throws EE_Error
4731 4731
 	 */
4732
-	private function _prepare_operator_for_sql($operator_supplied){
4732
+	private function _prepare_operator_for_sql($operator_supplied) {
4733 4733
 		$sql_operator = isset($this->_valid_operators[$operator_supplied]) ? $this->_valid_operators[$operator_supplied] : null;
4734
-		if($sql_operator){
4734
+		if ($sql_operator) {
4735 4735
 			return $sql_operator;
4736
-		}else{
4737
-			throw new EE_Error(sprintf(__("The operator '%s' is not in the list of valid operators: %s", "event_espresso"),$operator_supplied,implode(",",array_keys($this->_valid_operators))));
4736
+		} else {
4737
+			throw new EE_Error(sprintf(__("The operator '%s' is not in the list of valid operators: %s", "event_espresso"), $operator_supplied, implode(",", array_keys($this->_valid_operators))));
4738 4738
 		}
4739 4739
 	}
4740 4740
 
@@ -4748,10 +4748,10 @@  discard block
 block discarded – undo
4748 4748
 	 * @return string[]
4749 4749
 	 * @throws \EE_Error
4750 4750
 	 */
4751
-	public function get_all_names($query_params = array()){
4751
+	public function get_all_names($query_params = array()) {
4752 4752
 		$objs = $this->get_all($query_params);
4753 4753
 		$names = array();
4754
-		foreach($objs as $obj){
4754
+		foreach ($objs as $obj) {
4755 4755
 			$names[$obj->ID()] = $obj->name();
4756 4756
 		}
4757 4757
 		return $names;
@@ -4770,11 +4770,11 @@  discard block
 block discarded – undo
4770 4770
 	 * @return array
4771 4771
 	 * @throws \EE_Error
4772 4772
 	 */
4773
-	public function get_IDs( $model_objects, $filter_out_empty_ids = false) {
4774
-		if( ! $this->has_primary_key_field() ) {
4775
-			if( WP_DEBUG ) {
4773
+	public function get_IDs($model_objects, $filter_out_empty_ids = false) {
4774
+		if ( ! $this->has_primary_key_field()) {
4775
+			if (WP_DEBUG) {
4776 4776
 				EE_Error::add_error(
4777
-					__( 'Trying to get IDs from a model than has no primary key', 'event_espresso' ),
4777
+					__('Trying to get IDs from a model than has no primary key', 'event_espresso'),
4778 4778
 					__FILE__,
4779 4779
 					__FUNCTION__,
4780 4780
 					__LINE__
@@ -4782,13 +4782,13 @@  discard block
 block discarded – undo
4782 4782
 			}
4783 4783
 		}
4784 4784
 		$IDs = array();
4785
-		foreach( $model_objects as $model_object ) {
4785
+		foreach ($model_objects as $model_object) {
4786 4786
 			$id = $model_object->ID();
4787
-			if( ! $id ) {
4788
-				if( $filter_out_empty_ids ) {
4787
+			if ( ! $id) {
4788
+				if ($filter_out_empty_ids) {
4789 4789
 					continue;
4790 4790
 				}
4791
-				if ( WP_DEBUG ) {
4791
+				if (WP_DEBUG) {
4792 4792
 					EE_Error::add_error(
4793 4793
 						__(
4794 4794
 							'Called %1$s on a model object that has no ID and so probably hasn\'t been saved to the database',
@@ -4810,8 +4810,8 @@  discard block
 block discarded – undo
4810 4810
 	 * are no capabilities that relate to this model returns false
4811 4811
 	 * @return string|false
4812 4812
 	 */
4813
-	public function cap_slug(){
4814
-		return apply_filters( 'FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4813
+	public function cap_slug() {
4814
+		return apply_filters('FHEE__EEM_Base__cap_slug', $this->_caps_slug, $this);
4815 4815
 	}
4816 4816
 
4817 4817
 
@@ -4826,34 +4826,34 @@  discard block
 block discarded – undo
4826 4826
 	 * @return EE_Default_Where_Conditions[] indexed by associated capability
4827 4827
 	 * @throws \EE_Error
4828 4828
 	 */
4829
-	public function cap_restrictions( $context = EEM_Base::caps_read ) {
4830
-		EEM_Base::verify_is_valid_cap_context( $context );
4829
+	public function cap_restrictions($context = EEM_Base::caps_read) {
4830
+		EEM_Base::verify_is_valid_cap_context($context);
4831 4831
 		//check if we ought to run the restriction generator first
4832
-		if(
4833
-			isset( $this->_cap_restriction_generators[ $context ] )
4834
-			&& $this->_cap_restriction_generators[ $context ] instanceof EE_Restriction_Generator_Base
4835
-			&& ! $this->_cap_restriction_generators[ $context ]->has_generated_cap_restrictions()
4832
+		if (
4833
+			isset($this->_cap_restriction_generators[$context])
4834
+			&& $this->_cap_restriction_generators[$context] instanceof EE_Restriction_Generator_Base
4835
+			&& ! $this->_cap_restriction_generators[$context]->has_generated_cap_restrictions()
4836 4836
 		) {
4837
-			$this->_cap_restrictions[ $context ] = array_merge(
4838
-				$this->_cap_restrictions[ $context ],
4839
-				$this->_cap_restriction_generators[ $context ]->generate_restrictions()
4837
+			$this->_cap_restrictions[$context] = array_merge(
4838
+				$this->_cap_restrictions[$context],
4839
+				$this->_cap_restriction_generators[$context]->generate_restrictions()
4840 4840
 			);
4841 4841
 		}
4842 4842
 		//and make sure we've finalized the construction of each restriction
4843
-		foreach( $this->_cap_restrictions[ $context ] as $where_conditions_obj ) {
4844
-			if ( $where_conditions_obj instanceof EE_Default_Where_Conditions ) {
4845
-				$where_conditions_obj->_finalize_construct( $this );
4843
+		foreach ($this->_cap_restrictions[$context] as $where_conditions_obj) {
4844
+			if ($where_conditions_obj instanceof EE_Default_Where_Conditions) {
4845
+				$where_conditions_obj->_finalize_construct($this);
4846 4846
 			}
4847 4847
 		}
4848 4848
 
4849
-		return $this->_cap_restrictions[ $context ];
4849
+		return $this->_cap_restrictions[$context];
4850 4850
 	}
4851 4851
 
4852 4852
 	/**
4853 4853
 	 * Indicating whether or not this model thinks its a wp core model
4854 4854
 	 * @return boolean
4855 4855
 	 */
4856
-	public function is_wp_core_model(){
4856
+	public function is_wp_core_model() {
4857 4857
 		return $this->_wp_core_model;
4858 4858
 	}
4859 4859
 
@@ -4867,12 +4867,12 @@  discard block
 block discarded – undo
4867 4867
 	 * @return EE_Default_Where_Conditions[] indexed by capability name
4868 4868
 	 * @throws \EE_Error
4869 4869
 	 */
4870
-	public function caps_missing( $context = EEM_Base::caps_read ) {
4870
+	public function caps_missing($context = EEM_Base::caps_read) {
4871 4871
 		$missing_caps = array();
4872
-		$cap_restrictions = $this->cap_restrictions( $context );
4873
-		foreach( $cap_restrictions as $cap => $restriction_if_no_cap ) {
4874
-			if( ! EE_Capabilities::instance()->current_user_can( $cap, $this->get_this_model_name() . '_model_applying_caps') ) {
4875
-				$missing_caps[ $cap ] = $restriction_if_no_cap;
4872
+		$cap_restrictions = $this->cap_restrictions($context);
4873
+		foreach ($cap_restrictions as $cap => $restriction_if_no_cap) {
4874
+			if ( ! EE_Capabilities::instance()->current_user_can($cap, $this->get_this_model_name().'_model_applying_caps')) {
4875
+				$missing_caps[$cap] = $restriction_if_no_cap;
4876 4876
 			}
4877 4877
 		}
4878 4878
 		return $missing_caps;
@@ -4884,7 +4884,7 @@  discard block
 block discarded – undo
4884 4884
 	 * one of 'read', 'edit', or 'delete'
4885 4885
 	 */
4886 4886
 	public function cap_contexts_to_cap_action_map() {
4887
-		return apply_filters( 'FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this );
4887
+		return apply_filters('FHEE__EEM_Base__cap_contexts_to_cap_action_map', $this->_cap_contexts_to_cap_action_map, $this);
4888 4888
 	}
4889 4889
 
4890 4890
 
@@ -4895,19 +4895,19 @@  discard block
 block discarded – undo
4895 4895
 	 * @return string one of EEM_Base::cap_contexts_to_cap_action_map() values
4896 4896
 	 * @throws \EE_Error
4897 4897
 	 */
4898
-	public function cap_action_for_context( $context ) {
4898
+	public function cap_action_for_context($context) {
4899 4899
 		$mapping = $this->cap_contexts_to_cap_action_map();
4900
-		if( isset( $mapping[ $context ] ) ) {
4901
-			return $mapping[ $context ];
4900
+		if (isset($mapping[$context])) {
4901
+			return $mapping[$context];
4902 4902
 		}
4903
-		if( $action = apply_filters( 'FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context ) ) {
4903
+		if ($action = apply_filters('FHEE__EEM_Base__cap_action_for_context', null, $this, $mapping, $context)) {
4904 4904
 			return $action;
4905 4905
 		}
4906 4906
 		throw new EE_Error(
4907 4907
 			sprintf(
4908
-				__( 'Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso' ),
4908
+				__('Cannot find capability restrictions for context "%1$s", allowed values are:%2$s', 'event_espresso'),
4909 4909
 				$context,
4910
-				implode(',', array_keys( $this->cap_contexts_to_cap_action_map() ) )
4910
+				implode(',', array_keys($this->cap_contexts_to_cap_action_map()))
4911 4911
 			)
4912 4912
 		);
4913 4913
 
@@ -4918,7 +4918,7 @@  discard block
 block discarded – undo
4918 4918
 	 * @return array
4919 4919
 	 */
4920 4920
 	static public function valid_cap_contexts() {
4921
-		return apply_filters( 'FHEE__EEM_Base__valid_cap_contexts', array(
4921
+		return apply_filters('FHEE__EEM_Base__valid_cap_contexts', array(
4922 4922
 			self::caps_read,
4923 4923
 			self::caps_read_admin,
4924 4924
 			self::caps_edit,
@@ -4934,17 +4934,17 @@  discard block
 block discarded – undo
4934 4934
 	 * @return bool
4935 4935
 	 * @throws \EE_Error
4936 4936
 	 */
4937
-	static public function verify_is_valid_cap_context( $context ) {
4937
+	static public function verify_is_valid_cap_context($context) {
4938 4938
 		$valid_cap_contexts = EEM_Base::valid_cap_contexts();
4939
-		if( in_array( $context, $valid_cap_contexts ) ) {
4939
+		if (in_array($context, $valid_cap_contexts)) {
4940 4940
 			return true;
4941
-		}else{
4941
+		} else {
4942 4942
 			throw new EE_Error(
4943 4943
 				sprintf(
4944
-					__( 'Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso' ),
4944
+					__('Context "%1$s" passed into model "%2$s" is not a valid context. They are: %3$s', 'event_espresso'),
4945 4945
 					$context,
4946
-					'EEM_Base' ,
4947
-					implode(',', $valid_cap_contexts )
4946
+					'EEM_Base',
4947
+					implode(',', $valid_cap_contexts)
4948 4948
 				)
4949 4949
 			);
4950 4950
 		}
Please login to merge, or discard this patch.
core/db_models/EEM_Soft_Delete_Base.model.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 	 * Sum all the deleted items.
147 147
 	 * @param array $query_params like EEM_Base::get_all
148 148
 	 * @param string $field_to_sum
149
-	 * @return int
149
+	 * @return double
150 150
 	 */
151 151
 	public function sum_deleted($query_params = null, $field_to_sum = null){
152 152
 		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	 * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
196 196
 	 * that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects
197 197
 	 * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
198
-	 * @return boolean success
198
+	 * @return integer success
199 199
 	 */
200 200
 	public function delete_permanently($query_params = array(), $allow_blocking = true){
201 201
 		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed');
2
-require_once( EE_MODELS . 'EEM_Base.model.php');
2
+require_once(EE_MODELS.'EEM_Base.model.php');
3 3
 /**
4 4
  * EEM_Soft_Delete_Base
5 5
  *
@@ -25,13 +25,13 @@  discard block
 block discarded – undo
25 25
  * @subpackage		includes/models/
26 26
  * @author				Michael Nelson
27 27
  */
28
-abstract class EEM_Soft_Delete_Base extends EEM_Base{
28
+abstract class EEM_Soft_Delete_Base extends EEM_Base {
29 29
 
30 30
 	/**
31 31
 	 * @param null $timezone
32 32
 	 */
33 33
 	protected function __construct($timezone = NULL) {
34
-		if( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions ){
34
+		if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
35 35
 			$this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions();
36 36
 		}
37 37
 		parent::__construct($timezone);
@@ -42,12 +42,12 @@  discard block
 block discarded – undo
42 42
 	 * @return string
43 43
 	 * @throws EE_Error
44 44
 	 */
45
-	public function deleted_field_name(){
45
+	public function deleted_field_name() {
46 46
 		$field = $this->get_a_field_of_type('EE_Trashed_Flag_Field');
47
-		if($field){
47
+		if ($field) {
48 48
 			return $field->get_name();
49
-		}else{
50
-			throw new EE_Error(sprintf(__('We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?','event_espresso'),get_class($this),get_class($this)));
49
+		} else {
50
+			throw new EE_Error(sprintf(__('We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?', 'event_espresso'), get_class($this), get_class($this)));
51 51
 		}
52 52
 	}
53 53
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	 * @param array $query_params like EEM_Base::get_all's $query_params
58 58
 	 * @return EE_Soft_Delete_Base_Class
59 59
 	 */
60
-	public function get_one_deleted($query_params = array()){
60
+	public function get_one_deleted($query_params = array()) {
61 61
 		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
62 62
 		return parent::get_one($query_params);
63 63
 	}
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	 * @param array $query_params like EEM_base::get_all's $query_params
68 68
 	 * @return EE_Soft_Delete_Base_Class
69 69
 	 */
70
-	public function get_one_deleted_or_undeleted($query_params = array()){
70
+	public function get_one_deleted_or_undeleted($query_params = array()) {
71 71
 		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
72 72
 		return parent::get_one($query_params);
73 73
 	}
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
 	 * @param int|string $id
78 78
 	 * @return EE_Soft_Delete_Base_Class
79 79
 	 */
80
-	public function get_one_by_ID_but_ignore_deleted($id){
80
+	public function get_one_by_ID_but_ignore_deleted($id) {
81 81
 		return $this->get_one(
82 82
 			$this->alter_query_params_to_restrict_by_ID(
83 83
 				$id,
84
-				array( 'default_where_conditions' => 'default' )
84
+				array('default_where_conditions' => 'default')
85 85
 			)
86 86
 		);
87 87
 	}
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 * @param bool 	 $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE;
94 94
 	 * @return int
95 95
 	 */
96
-	public function count_deleted($query_params = null, $field_to_count = null, $distinct = FALSE){
96
+	public function count_deleted($query_params = null, $field_to_count = null, $distinct = FALSE) {
97 97
 		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
98 98
 		return parent::count($query_params, $field_to_count, $distinct);
99 99
 	}
@@ -103,9 +103,9 @@  discard block
 block discarded – undo
103 103
 	 * @param array $query_params like EEM_Base::get_all's $query_params
104 104
 	 * @return array like EEM_Base::get_all's $query_params
105 105
 	 */
106
-	protected function _alter_query_params_so_only_trashed_items_included($query_params){
107
-		$deletedFlagFieldName=$this->deleted_field_name();
108
-		$query_params[0][$deletedFlagFieldName]=true;
106
+	protected function _alter_query_params_so_only_trashed_items_included($query_params) {
107
+		$deletedFlagFieldName = $this->deleted_field_name();
108
+		$query_params[0][$deletedFlagFieldName] = true;
109 109
 		return $query_params;
110 110
 	}
111 111
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 	 * @param array $query_params
115 115
 	 * @return array
116 116
 	 */
117
-	public function alter_query_params_so_deleted_and_undeleted_items_included( $query_params = array() ){
117
+	public function alter_query_params_so_deleted_and_undeleted_items_included($query_params = array()) {
118 118
 		return $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
119 119
 	}
120 120
 
@@ -123,8 +123,8 @@  discard block
 block discarded – undo
123 123
 	 * @param array $query_params
124 124
 	 * @return array
125 125
 	 */
126
-	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params){
127
-		if( ! isset( $query_params[ 'default_where_conditions' ] ) ) {
126
+	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params) {
127
+		if ( ! isset($query_params['default_where_conditions'])) {
128 128
 			$query_params['default_where_conditions'] = 'minimum';
129 129
 		}
130 130
 		return $query_params;
@@ -137,9 +137,9 @@  discard block
 block discarded – undo
137 137
 	 * @param bool 	 $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE;
138 138
 	 * @return int
139 139
 	 */
140
-	public function count_deleted_and_undeleted($query_params = null, $field_to_count = null, $distinct = FALSE){
140
+	public function count_deleted_and_undeleted($query_params = null, $field_to_count = null, $distinct = FALSE) {
141 141
 		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
142
-		return parent::count($query_params,$field_to_count, $distinct);
142
+		return parent::count($query_params, $field_to_count, $distinct);
143 143
 	}
144 144
 
145 145
 	/**
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 	 * @param string $field_to_sum
149 149
 	 * @return int
150 150
 	 */
151
-	public function sum_deleted($query_params = null, $field_to_sum = null){
151
+	public function sum_deleted($query_params = null, $field_to_sum = null) {
152 152
 		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
153 153
 		return parent::sum($query_params, $field_to_sum);
154 154
 	}
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	 * @param string $field_to_sum
160 160
 	 * @return int
161 161
 	 */
162
-	public function sum_deleted_and_undeleted($query_params = null, $field_to_sum = null){
162
+	public function sum_deleted_and_undeleted($query_params = null, $field_to_sum = null) {
163 163
 		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
164 164
 		parent::sum($query_params, $field_to_sum);
165 165
 	}
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
 	 * @param array $query_params like EEM_Base::get_all
170 170
 	 * @return EE_Soft_Delete_Base_Class[]
171 171
 	 */
172
-	public function get_all_deleted_and_undeleted($query_params = array()){
172
+	public function get_all_deleted_and_undeleted($query_params = array()) {
173 173
 		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
174 174
 		return parent::get_all($query_params);
175 175
 	}
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	 * @param array $query_params like EEM_Base::get_all
180 180
 	 * @return EE_Soft_Delete_Base_Class[]
181 181
 	 */
182
-	public function get_all_deleted($query_params = array()){
182
+	public function get_all_deleted($query_params = array()) {
183 183
 		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
184 184
 		return parent::get_all($query_params);
185 185
 	}
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	 * which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
198 198
 	 * @return boolean success
199 199
 	 */
200
-	public function delete_permanently($query_params = array(), $allow_blocking = true){
200
+	public function delete_permanently($query_params = array(), $allow_blocking = true) {
201 201
 		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
202 202
 		return parent::delete_permanently($query_params, $allow_blocking);
203 203
 	}
@@ -208,8 +208,8 @@  discard block
 block discarded – undo
208 208
 	 * @param mixed $ID int if primary key is an int, string otherwise
209 209
 	 * @return boolean success
210 210
 	 */
211
-	public function restore_by_ID($ID=FALSE){
212
-		return $this->delete_or_restore_by_ID(false,$ID);
211
+	public function restore_by_ID($ID = FALSE) {
212
+		return $this->delete_or_restore_by_ID(false, $ID);
213 213
 	}
214 214
 	/**
215 215
 	 * For deleting or restoring a particular item. Note that this model is a SOFT-DELETABLE model! However,
@@ -218,14 +218,14 @@  discard block
 block discarded – undo
218 218
 	 * @param mixed $ID int if primary key is an int, string otherwise
219 219
 	 * @return boolean
220 220
 	 */
221
-	public function delete_or_restore_by_ID($delete=true,$ID=FALSE){
222
-		if ( ! $ID ) {
221
+	public function delete_or_restore_by_ID($delete = true, $ID = FALSE) {
222
+		if ( ! $ID) {
223 223
 			return FALSE;
224 224
 		}
225 225
 		if (
226 226
 			$this->delete_or_restore(
227 227
 				$delete,
228
-				$this->alter_query_params_to_restrict_by_ID( $ID )
228
+				$this->alter_query_params_to_restrict_by_ID($ID)
229 229
 			)
230 230
 		) {
231 231
 			return TRUE;
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 	 * @param bool  $block_deletes
246 246
 	 * @return boolean
247 247
 	 */
248
-	public function delete($query_params = array(), $block_deletes = false){
248
+	public function delete($query_params = array(), $block_deletes = false) {
249 249
 		//no matter what, we WON'T block soft deletes.
250 250
 		return $this->delete_or_restore(true, $query_params);
251 251
 	}
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 	 * @param array $query_params like EEM_Base::get_all
257 257
 	 * @return boolean
258 258
 	 */
259
-	public function restore($query_params = array()){
259
+	public function restore($query_params = array()) {
260 260
 		return $this->delete_or_restore(false, $query_params);
261 261
 	}
262 262
 	/**
@@ -265,10 +265,10 @@  discard block
 block discarded – undo
265 265
 	 * @param array $query_params like EEM_Base::get_all
266 266
 	 * @return boolean
267 267
 	 */
268
-	function delete_or_restore($delete=true,$query_params = array()){
269
-		$deletedFlagFieldName=$this->deleted_field_name();
268
+	function delete_or_restore($delete = true, $query_params = array()) {
269
+		$deletedFlagFieldName = $this->deleted_field_name();
270 270
 		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
271
-		if ( $this->update (array($deletedFlagFieldName=>$delete), $query_params )) {
271
+		if ($this->update(array($deletedFlagFieldName=>$delete), $query_params)) {
272 272
 			return TRUE;
273 273
 		} else {
274 274
 			return FALSE;
@@ -286,8 +286,8 @@  discard block
 block discarded – undo
286 286
 	 * be aware that model objects being used could get out-of-sync with the database
287 287
 	 * @return int number of items updated
288 288
 	 */
289
-	public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE ){
289
+	public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = TRUE) {
290 290
 		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
291
-		return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync );
291
+		return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync);
292 292
 	}
293 293
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Line_Item.helper.php 1 patch
Spacing   +342 added lines, -342 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (!defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); }
2 2
 /**
3 3
  *
4 4
  * EEH_Line_Item
@@ -45,8 +45,8 @@  discard block
 block discarded – undo
45 45
 	 * @return boolean success
46 46
 	 * @throws \EE_Error
47 47
 	 */
48
-	public static function add_unrelated_item( EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL  ){
49
-		$items_subtotal = self::get_pre_tax_subtotal( $parent_line_item );
48
+	public static function add_unrelated_item(EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL) {
49
+		$items_subtotal = self::get_pre_tax_subtotal($parent_line_item);
50 50
 		$line_item = EE_Line_Item::new_instance(array(
51 51
 			'LIN_name' => $name,
52 52
 			'LIN_desc' => $description,
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 			'LIN_quantity' => $quantity,
55 55
 			'LIN_percent' => null,
56 56
 			'LIN_is_taxable' => $taxable,
57
-			'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count( $items_subtotal->children() ) : 0,
57
+			'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0,
58 58
 			'LIN_total' => (float) $unit_price * (int) $quantity,
59 59
 			'LIN_type'=>  EEM_Line_Item::type_line_item,
60 60
 			'LIN_code' => $code,
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 			$line_item,
65 65
 			$parent_line_item
66 66
 		);
67
-		return self::add_item( $parent_line_item, $line_item );
67
+		return self::add_item($parent_line_item, $line_item);
68 68
 	}
69 69
 
70 70
 
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 	 * @return boolean success
87 87
 	 * @throws \EE_Error
88 88
 	 */
89
-	public static function add_percentage_based_item( EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE ){
89
+	public static function add_percentage_based_item(EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE) {
90 90
 		$line_item = EE_Line_Item::new_instance(array(
91 91
 			'LIN_name' => $name,
92 92
 			'LIN_desc' => $description,
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 			'LIN_percent' => $percentage_amount,
95 95
 			'LIN_quantity' => NULL,
96 96
 			'LIN_is_taxable' => $taxable,
97
-			'LIN_total' => (float) ( $percentage_amount * ( $parent_line_item->total() / 100 ) ),
97
+			'LIN_total' => (float) ($percentage_amount * ($parent_line_item->total() / 100)),
98 98
 			'LIN_type'=>  EEM_Line_Item::type_line_item,
99 99
 			'LIN_parent' => $parent_line_item->ID()
100 100
 		));
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 			'FHEE__EEH_Line_Item__add_percentage_based_item__line_item',
103 103
 			$line_item
104 104
 		);
105
-		return self::add_item( $parent_line_item, $line_item );
105
+		return self::add_item($parent_line_item, $line_item);
106 106
 	}
107 107
 
108 108
 
@@ -123,15 +123,15 @@  discard block
 block discarded – undo
123 123
 	 * @return \EE_Line_Item
124 124
 	 * @throws \EE_Error
125 125
 	 */
126
-	public static function add_ticket_purchase( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ){
127
-		if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total() ) {
128
-			throw new EE_Error( sprintf( __( 'A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso' ), $ticket->ID(), $total_line_item->ID() ) );
126
+	public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) {
127
+		if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) {
128
+			throw new EE_Error(sprintf(__('A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso'), $ticket->ID(), $total_line_item->ID()));
129 129
 		}
130 130
 		// either increment the qty for an existing ticket
131
-		$line_item = self::increment_ticket_qty_if_already_in_cart( $total_line_item, $ticket, $qty );
131
+		$line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty);
132 132
 		// or add a new one
133
-		if ( ! $line_item instanceof EE_Line_Item ) {
134
-			$line_item = self::create_ticket_line_item( $total_line_item, $ticket, $qty );
133
+		if ( ! $line_item instanceof EE_Line_Item) {
134
+			$line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty);
135 135
 		}
136 136
 		$total_line_item->recalculate_total_including_taxes();
137 137
 		return $line_item;
@@ -147,11 +147,11 @@  discard block
 block discarded – undo
147 147
 	 * @return \EE_Line_Item
148 148
 	 * @throws \EE_Error
149 149
 	 */
150
-	public static function increment_ticket_qty_if_already_in_cart( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) {
150
+	public static function increment_ticket_qty_if_already_in_cart(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) {
151 151
 		$line_item = null;
152
-		if ( $total_line_item instanceof EE_Line_Item && $total_line_item->is_total() ) {
153
-			$ticket_line_items = EEH_Line_Item::get_ticket_line_items( $total_line_item );
154
-			foreach ( (array)$ticket_line_items as $ticket_line_item ) {
152
+		if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) {
153
+			$ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item);
154
+			foreach ((array) $ticket_line_items as $ticket_line_item) {
155 155
 				if (
156 156
 					$ticket_line_item instanceof EE_Line_Item
157 157
 					&& (int) $ticket_line_item->OBJ_ID() === (int) $ticket->ID()
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
 				}
162 162
 			}
163 163
 		}
164
-		if ( $line_item instanceof EE_Line_Item ) {
165
-			EEH_Line_Item::increment_quantity( $line_item, $qty );
164
+		if ($line_item instanceof EE_Line_Item) {
165
+			EEH_Line_Item::increment_quantity($line_item, $qty);
166 166
 			return $line_item;
167 167
 		}
168 168
 		return null;
@@ -179,16 +179,16 @@  discard block
 block discarded – undo
179 179
 	 * @return void
180 180
 	 * @throws \EE_Error
181 181
 	 */
182
-	public static function increment_quantity( EE_Line_Item $line_item, $qty = 1 ) {
183
-		if( ! $line_item->is_percent() ) {
182
+	public static function increment_quantity(EE_Line_Item $line_item, $qty = 1) {
183
+		if ( ! $line_item->is_percent()) {
184 184
 			$qty += $line_item->quantity();
185
-			$line_item->set_quantity( $qty );
186
-			$line_item->set_total( $line_item->unit_price() * $qty );
185
+			$line_item->set_quantity($qty);
186
+			$line_item->set_total($line_item->unit_price() * $qty);
187 187
 			$line_item->save();
188 188
 		}
189
-		foreach( $line_item->children() as $child ) {
190
-			if( $child->is_sub_line_item() ) {
191
-				EEH_Line_Item::update_quantity( $child, $qty );
189
+		foreach ($line_item->children() as $child) {
190
+			if ($child->is_sub_line_item()) {
191
+				EEH_Line_Item::update_quantity($child, $qty);
192 192
 			}
193 193
 		}
194 194
 	}
@@ -204,17 +204,17 @@  discard block
 block discarded – undo
204 204
 	 * @return void
205 205
 	 * @throws \EE_Error
206 206
 	 */
207
-	public static function decrement_quantity( EE_Line_Item $line_item, $qty = 1 ) {
208
-		if( ! $line_item->is_percent() ) {
207
+	public static function decrement_quantity(EE_Line_Item $line_item, $qty = 1) {
208
+		if ( ! $line_item->is_percent()) {
209 209
 			$qty = $line_item->quantity() - $qty;
210
-			$qty = max( $qty, 0 );
211
-			$line_item->set_quantity( $qty );
212
-			$line_item->set_total( $line_item->unit_price() * $qty );
210
+			$qty = max($qty, 0);
211
+			$line_item->set_quantity($qty);
212
+			$line_item->set_total($line_item->unit_price() * $qty);
213 213
 			$line_item->save();
214 214
 		}
215
-		foreach( $line_item->children() as $child ) {
216
-			if( $child->is_sub_line_item() ) {
217
-				EEH_Line_Item::update_quantity( $child, $qty );
215
+		foreach ($line_item->children() as $child) {
216
+			if ($child->is_sub_line_item()) {
217
+				EEH_Line_Item::update_quantity($child, $qty);
218 218
 			}
219 219
 		}
220 220
 	}
@@ -229,15 +229,15 @@  discard block
 block discarded – undo
229 229
 	 * @param int          $new_quantity
230 230
 	 * @throws \EE_Error
231 231
 	 */
232
-	public static function update_quantity( EE_Line_Item $line_item, $new_quantity ) {
233
-		if( ! $line_item->is_percent() ) {
234
-			$line_item->set_quantity( $new_quantity );
235
-			$line_item->set_total( $line_item->unit_price() * $new_quantity );
232
+	public static function update_quantity(EE_Line_Item $line_item, $new_quantity) {
233
+		if ( ! $line_item->is_percent()) {
234
+			$line_item->set_quantity($new_quantity);
235
+			$line_item->set_total($line_item->unit_price() * $new_quantity);
236 236
 			$line_item->save();
237 237
 		}
238
-		foreach( $line_item->children() as $child ) {
239
-			if( $child->is_sub_line_item() ) {
240
-				EEH_Line_Item::update_quantity( $child, $new_quantity );
238
+		foreach ($line_item->children() as $child) {
239
+			if ($child->is_sub_line_item()) {
240
+				EEH_Line_Item::update_quantity($child, $new_quantity);
241 241
 			}
242 242
 		}
243 243
 	}
@@ -252,43 +252,43 @@  discard block
 block discarded – undo
252 252
 	 * @return \EE_Line_Item
253 253
 	 * @throws \EE_Error
254 254
 	 */
255
-	public static function create_ticket_line_item( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) {
255
+	public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) {
256 256
 		$datetimes = $ticket->datetimes();
257
-		$first_datetime = reset( $datetimes );
258
-		if( $first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event ) {
257
+		$first_datetime = reset($datetimes);
258
+		if ($first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event) {
259 259
 			$first_datetime_name = $first_datetime->event()->name();
260 260
 		} else {
261
-			$first_datetime_name = __( 'Event', 'event_espresso' );
261
+			$first_datetime_name = __('Event', 'event_espresso');
262 262
 		}
263
-		$event = sprintf( _x( '(For %1$s)', '(For Event Name)', 'event_espresso' ), $first_datetime_name );
263
+		$event = sprintf(_x('(For %1$s)', '(For Event Name)', 'event_espresso'), $first_datetime_name);
264 264
 		// get event subtotal line
265
-		$events_sub_total = self::get_event_line_item_for_ticket( $total_line_item, $ticket );
265
+		$events_sub_total = self::get_event_line_item_for_ticket($total_line_item, $ticket);
266 266
 		// add $ticket to cart
267
-		$line_item = EE_Line_Item::new_instance( array(
267
+		$line_item = EE_Line_Item::new_instance(array(
268 268
 			'LIN_name'       	=> $ticket->name(),
269
-			'LIN_desc'       		=> $ticket->description() !== '' ? $ticket->description() . ' ' . $event : $event,
269
+			'LIN_desc'       		=> $ticket->description() !== '' ? $ticket->description().' '.$event : $event,
270 270
 			'LIN_unit_price' 	=> $ticket->price(),
271 271
 			'LIN_quantity'   	=> $qty,
272 272
 			'LIN_is_taxable' 	=> $ticket->taxable(),
273
-			'LIN_order'      	=> count( $events_sub_total->children() ),
273
+			'LIN_order'      	=> count($events_sub_total->children()),
274 274
 			'LIN_total'      		=> $ticket->price() * $qty,
275 275
 			'LIN_type'       		=> EEM_Line_Item::type_line_item,
276 276
 			'OBJ_ID'         		=> $ticket->ID(),
277 277
 			'OBJ_type'       	=> 'Ticket'
278
-		) );
278
+		));
279 279
 		$line_item = apply_filters(
280 280
 			'FHEE__EEH_Line_Item__create_ticket_line_item__line_item',
281 281
 			$line_item
282 282
 		);
283
-		$events_sub_total->add_child_line_item( $line_item );
283
+		$events_sub_total->add_child_line_item($line_item);
284 284
 		//now add the sub-line items
285 285
 		$running_total_for_ticket = 0;
286
-		foreach ( $ticket->prices( array( 'order_by' => array( 'PRC_order' => 'ASC' ) ) ) as $price ) {
286
+		foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) {
287 287
 			$sign = $price->is_discount() ? -1 : 1;
288 288
 			$price_total = $price->is_percent()
289 289
 				? $running_total_for_ticket * $price->amount() / 100
290 290
 				: $price->amount() * $qty;
291
-			$sub_line_item = EE_Line_Item::new_instance( array(
291
+			$sub_line_item = EE_Line_Item::new_instance(array(
292 292
 				'LIN_name'       	=> $price->name(),
293 293
 				'LIN_desc'       		=> $price->desc(),
294 294
 				'LIN_quantity'   	=> $price->is_percent() ? null : $qty,
@@ -298,18 +298,18 @@  discard block
 block discarded – undo
298 298
 				'LIN_type'       		=> EEM_Line_Item::type_sub_line_item,
299 299
 				'OBJ_ID'         		=> $price->ID(),
300 300
 				'OBJ_type'       	=> 'Price'
301
-			) );
301
+			));
302 302
 			$sub_line_item = apply_filters(
303 303
 				'FHEE__EEH_Line_Item__create_ticket_line_item__sub_line_item',
304 304
 				$sub_line_item
305 305
 			);
306
-			if ( $price->is_percent() ) {
307
-				$sub_line_item->set_percent( $sign * $price->amount() );
306
+			if ($price->is_percent()) {
307
+				$sub_line_item->set_percent($sign * $price->amount());
308 308
 			} else {
309
-				$sub_line_item->set_unit_price( $sign * $price->amount() );
309
+				$sub_line_item->set_unit_price($sign * $price->amount());
310 310
 			}
311 311
 			$running_total_for_ticket += $price_total;
312
-			$line_item->add_child_line_item( $sub_line_item );
312
+			$line_item->add_child_line_item($sub_line_item);
313 313
 		}
314 314
 		return $line_item;
315 315
 	}
@@ -329,11 +329,11 @@  discard block
 block discarded – undo
329 329
 	 * @return boolean
330 330
 	 * @throws \EE_Error
331 331
 	 */
332
-	public static function add_item( EE_Line_Item $total_line_item, EE_Line_Item $item ){
333
-		$pre_tax_subtotal = self::get_pre_tax_subtotal( $total_line_item );
334
-		if ( $pre_tax_subtotal instanceof EE_Line_Item ){
332
+	public static function add_item(EE_Line_Item $total_line_item, EE_Line_Item $item) {
333
+		$pre_tax_subtotal = self::get_pre_tax_subtotal($total_line_item);
334
+		if ($pre_tax_subtotal instanceof EE_Line_Item) {
335 335
 			$success = $pre_tax_subtotal->add_child_line_item($item);
336
-		}else{
336
+		} else {
337 337
 			return FALSE;
338 338
 		}
339 339
 		$total_line_item->recalculate_total_including_taxes();
@@ -352,34 +352,34 @@  discard block
 block discarded – undo
352 352
 	 * @return bool success
353 353
 	 * @throws \EE_Error
354 354
 	 */
355
-	public static function cancel_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) {
355
+	public static function cancel_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) {
356 356
 		// validate incoming line_item
357
-		if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) {
357
+		if ($ticket_line_item->OBJ_type() !== 'Ticket') {
358 358
 			throw new EE_Error(
359 359
 				sprintf(
360
-					__( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ),
360
+					__('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'),
361 361
 					$ticket_line_item->type()
362 362
 				)
363 363
 			);
364 364
 		}
365
-		if ( $ticket_line_item->quantity() < $qty ) {
365
+		if ($ticket_line_item->quantity() < $qty) {
366 366
 			throw new EE_Error(
367 367
 				sprintf(
368
-					__( 'Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso' ),
368
+					__('Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso'),
369 369
 					$qty,
370 370
 					$ticket_line_item->quantity()
371 371
 				)
372 372
 			);
373 373
 		}
374 374
 		// decrement ticket quantity; don't rely on auto-fixing when recalculating totals to do this
375
-		$ticket_line_item->set_quantity( $ticket_line_item->quantity() - $qty );
376
-		foreach( $ticket_line_item->children() as $child_line_item ) {
377
-			if(
375
+		$ticket_line_item->set_quantity($ticket_line_item->quantity() - $qty);
376
+		foreach ($ticket_line_item->children() as $child_line_item) {
377
+			if (
378 378
 				$child_line_item->is_sub_line_item()
379 379
 				&& ! $child_line_item->is_percent()
380 380
 				&& ! $child_line_item->is_cancellation()
381 381
 			) {
382
-				$child_line_item->set_quantity( $child_line_item->quantity() - $qty );
382
+				$child_line_item->set_quantity($child_line_item->quantity() - $qty);
383 383
 			}
384 384
 		}
385 385
 		// get cancellation sub line item
@@ -387,31 +387,31 @@  discard block
 block discarded – undo
387 387
 			$ticket_line_item,
388 388
 			EEM_Line_Item::type_cancellation
389 389
 		);
390
-		$cancellation_line_item = reset( $cancellation_line_item );
390
+		$cancellation_line_item = reset($cancellation_line_item);
391 391
 		// verify that this ticket was indeed previously cancelled
392
-		if ( $cancellation_line_item instanceof EE_Line_Item ) {
392
+		if ($cancellation_line_item instanceof EE_Line_Item) {
393 393
 			// increment cancelled quantity
394
-			$cancellation_line_item->set_quantity( $cancellation_line_item->quantity() + $qty );
394
+			$cancellation_line_item->set_quantity($cancellation_line_item->quantity() + $qty);
395 395
 		} else {
396 396
 			// create cancellation sub line item
397
-			$cancellation_line_item = EE_Line_Item::new_instance( array(
398
-				'LIN_name'       => __( 'Cancellation', 'event_espresso' ),
397
+			$cancellation_line_item = EE_Line_Item::new_instance(array(
398
+				'LIN_name'       => __('Cancellation', 'event_espresso'),
399 399
 				'LIN_desc'       => sprintf(
400
-					_x( 'Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso' ),
400
+					_x('Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso'),
401 401
 					$ticket_line_item->name(),
402
-					current_time( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) )
402
+					current_time(get_option('date_format').' '.get_option('time_format'))
403 403
 				),
404 404
 				'LIN_unit_price' => 0, // $ticket_line_item->unit_price()
405 405
 				'LIN_quantity'   => $qty,
406 406
 				'LIN_is_taxable' => $ticket_line_item->is_taxable(),
407
-				'LIN_order'      => count( $ticket_line_item->children() ),
407
+				'LIN_order'      => count($ticket_line_item->children()),
408 408
 				'LIN_total'      => 0, // $ticket_line_item->unit_price()
409 409
 				'LIN_type'       => EEM_Line_Item::type_cancellation,
410
-			) );
411
-			$ticket_line_item->add_child_line_item( $cancellation_line_item );
410
+			));
411
+			$ticket_line_item->add_child_line_item($cancellation_line_item);
412 412
 		}
413
-		if ( $ticket_line_item->save_this_and_descendants() > 0 ) {
414
-			EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item );
413
+		if ($ticket_line_item->save_this_and_descendants() > 0) {
414
+			EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item);
415 415
 			return true;
416 416
 		}
417 417
 		return false;
@@ -429,12 +429,12 @@  discard block
 block discarded – undo
429 429
 	 * @return bool success
430 430
 	 * @throws \EE_Error
431 431
 	 */
432
-	public static function reinstate_canceled_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) {
432
+	public static function reinstate_canceled_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) {
433 433
 		// validate incoming line_item
434
-		if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) {
434
+		if ($ticket_line_item->OBJ_type() !== 'Ticket') {
435 435
 			throw new EE_Error(
436 436
 				sprintf(
437
-					__( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ),
437
+					__('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'),
438 438
 					$ticket_line_item->type()
439 439
 				)
440 440
 			);
@@ -444,37 +444,37 @@  discard block
 block discarded – undo
444 444
 			$ticket_line_item,
445 445
 			EEM_Line_Item::type_cancellation
446 446
 		);
447
-		$cancellation_line_item = reset( $cancellation_line_item );
447
+		$cancellation_line_item = reset($cancellation_line_item);
448 448
 		// verify that this ticket was indeed previously cancelled
449
-		if ( ! $cancellation_line_item instanceof EE_Line_Item ) {
449
+		if ( ! $cancellation_line_item instanceof EE_Line_Item) {
450 450
 			return false;
451 451
 		}
452
-		if ( $cancellation_line_item->quantity() > $qty ) {
452
+		if ($cancellation_line_item->quantity() > $qty) {
453 453
 			// decrement cancelled quantity
454
-			$cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty );
455
-		} else if ( $cancellation_line_item->quantity() == $qty ) {
454
+			$cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty);
455
+		} else if ($cancellation_line_item->quantity() == $qty) {
456 456
 			// decrement cancelled quantity in case anyone still has the object kicking around
457
-			$cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty );
457
+			$cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty);
458 458
 			// delete because quantity will end up as 0
459 459
 			$cancellation_line_item->delete();
460 460
 			// and attempt to destroy the object,
461 461
 			// even though PHP won't actually destroy it until it needs the memory
462
-			unset( $cancellation_line_item );
462
+			unset($cancellation_line_item);
463 463
 		} else {
464 464
 			// what ?!?! negative quantity ?!?!
465 465
 			throw new EE_Error(
466 466
 				sprintf(
467
-					__( 'Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.',
468
-						'event_espresso' ),
467
+					__('Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.',
468
+						'event_espresso'),
469 469
 					$qty,
470 470
 					$cancellation_line_item->quantity()
471 471
 				)
472 472
 			);
473 473
 		}
474 474
 		// increment ticket quantity
475
-		$ticket_line_item->set_quantity( $ticket_line_item->quantity() + $qty );
476
-		if ( $ticket_line_item->save_this_and_descendants() > 0 ) {
477
-			EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item );
475
+		$ticket_line_item->set_quantity($ticket_line_item->quantity() + $qty);
476
+		if ($ticket_line_item->save_this_and_descendants() > 0) {
477
+			EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item);
478 478
 			return true;
479 479
 		}
480 480
 		return false;
@@ -489,8 +489,8 @@  discard block
 block discarded – undo
489 489
 	 * @param EE_Line_Item $line_item
490 490
 	 * @return \EE_Line_Item
491 491
 	 */
492
-	public static function get_grand_total_and_recalculate_everything( EE_Line_Item $line_item ){
493
-		$grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item );
492
+	public static function get_grand_total_and_recalculate_everything(EE_Line_Item $line_item) {
493
+		$grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item);
494 494
 		return $grand_total_line_item->recalculate_total_including_taxes();
495 495
 	}
496 496
 
@@ -503,11 +503,11 @@  discard block
 block discarded – undo
503 503
 	 * @return \EE_Line_Item
504 504
 	 * @throws \EE_Error
505 505
 	 */
506
-	public static function get_pre_tax_subtotal( EE_Line_Item $total_line_item ){
507
-		$pre_tax_subtotal = $total_line_item->get_child_line_item( 'pre-tax-subtotal' );
506
+	public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item) {
507
+		$pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal');
508 508
 		return $pre_tax_subtotal instanceof EE_Line_Item
509 509
 			? $pre_tax_subtotal
510
-			: self::create_pre_tax_subtotal( $total_line_item );
510
+			: self::create_pre_tax_subtotal($total_line_item);
511 511
 	}
512 512
 
513 513
 
@@ -519,9 +519,9 @@  discard block
 block discarded – undo
519 519
 	 * @return \EE_Line_Item
520 520
 	 * @throws \EE_Error
521 521
 	 */
522
-	public static function get_taxes_subtotal( EE_Line_Item $total_line_item ){
523
-		$taxes = $total_line_item->get_child_line_item( 'taxes' );
524
-		return $taxes ? $taxes : self::create_taxes_subtotal( $total_line_item );
522
+	public static function get_taxes_subtotal(EE_Line_Item $total_line_item) {
523
+		$taxes = $total_line_item->get_child_line_item('taxes');
524
+		return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item);
525 525
 	}
526 526
 
527 527
 
@@ -534,12 +534,12 @@  discard block
 block discarded – undo
534 534
 	 * @return void
535 535
 	 * @throws \EE_Error
536 536
 	 */
537
-	public static function set_TXN_ID( EE_Line_Item $line_item, $transaction = NULL ){
538
-		if( $transaction ){
537
+	public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = NULL) {
538
+		if ($transaction) {
539 539
 			/** @type EEM_Transaction $EEM_Transaction */
540
-			$EEM_Transaction = EE_Registry::instance()->load_model( 'Transaction' );
541
-			$TXN_ID = $EEM_Transaction->ensure_is_ID( $transaction );
542
-			$line_item->set_TXN_ID( $TXN_ID );
540
+			$EEM_Transaction = EE_Registry::instance()->load_model('Transaction');
541
+			$TXN_ID = $EEM_Transaction->ensure_is_ID($transaction);
542
+			$line_item->set_TXN_ID($TXN_ID);
543 543
 		}
544 544
 	}
545 545
 
@@ -554,8 +554,8 @@  discard block
 block discarded – undo
554 554
 	 * @return \EE_Line_Item of type total
555 555
 	 * @throws \EE_Error
556 556
 	 */
557
-	public static function create_total_line_item( $transaction = NULL ){
558
-		$total_line_item = EE_Line_Item::new_instance( array(
557
+	public static function create_total_line_item($transaction = NULL) {
558
+		$total_line_item = EE_Line_Item::new_instance(array(
559 559
 			'LIN_code'	=> 'total',
560 560
 			'LIN_name'	=> __('Grand Total', 'event_espresso'),
561 561
 			'LIN_type'	=> EEM_Line_Item::type_total,
@@ -565,9 +565,9 @@  discard block
 block discarded – undo
565 565
 			'FHEE__EEH_Line_Item__create_total_line_item__total_line_item',
566 566
 			$total_line_item
567 567
 		);
568
-		self::set_TXN_ID( $total_line_item, $transaction );
569
-		self::create_pre_tax_subtotal( $total_line_item, $transaction );
570
-		self::create_taxes_subtotal( $total_line_item, $transaction );
568
+		self::set_TXN_ID($total_line_item, $transaction);
569
+		self::create_pre_tax_subtotal($total_line_item, $transaction);
570
+		self::create_taxes_subtotal($total_line_item, $transaction);
571 571
 		return $total_line_item;
572 572
 	}
573 573
 
@@ -581,19 +581,19 @@  discard block
 block discarded – undo
581 581
 	 * @return EE_Line_Item
582 582
 	 * @throws \EE_Error
583 583
 	 */
584
-	protected static function create_pre_tax_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){
585
-		$pre_tax_line_item = EE_Line_Item::new_instance( array(
584
+	protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
585
+		$pre_tax_line_item = EE_Line_Item::new_instance(array(
586 586
 			'LIN_code' 	=> 'pre-tax-subtotal',
587
-			'LIN_name' 	=> __( 'Pre-Tax Subtotal', 'event_espresso' ),
587
+			'LIN_name' 	=> __('Pre-Tax Subtotal', 'event_espresso'),
588 588
 			'LIN_type' 	=> EEM_Line_Item::type_sub_total
589
-		) );
589
+		));
590 590
 		$pre_tax_line_item = apply_filters(
591 591
 			'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item',
592 592
 			$pre_tax_line_item
593 593
 		);
594
-		self::set_TXN_ID( $pre_tax_line_item, $transaction );
595
-		$total_line_item->add_child_line_item( $pre_tax_line_item );
596
-		self::create_event_subtotal( $pre_tax_line_item, $transaction );
594
+		self::set_TXN_ID($pre_tax_line_item, $transaction);
595
+		$total_line_item->add_child_line_item($pre_tax_line_item);
596
+		self::create_event_subtotal($pre_tax_line_item, $transaction);
597 597
 		return $pre_tax_line_item;
598 598
 	}
599 599
 
@@ -608,21 +608,21 @@  discard block
 block discarded – undo
608 608
 	 * @return EE_Line_Item
609 609
 	 * @throws \EE_Error
610 610
 	 */
611
-	protected static function create_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){
611
+	protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
612 612
 		$tax_line_item = EE_Line_Item::new_instance(array(
613 613
 			'LIN_code'	=> 'taxes',
614 614
 			'LIN_name' 	=> __('Taxes', 'event_espresso'),
615 615
 			'LIN_type'	=> EEM_Line_Item::type_tax_sub_total,
616
-			'LIN_order' => 1000,//this should always come last
616
+			'LIN_order' => 1000, //this should always come last
617 617
 		));
618 618
 		$tax_line_item = apply_filters(
619 619
 			'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item',
620 620
 			$tax_line_item
621 621
 		);
622
-		self::set_TXN_ID( $tax_line_item, $transaction );
623
-		$total_line_item->add_child_line_item( $tax_line_item );
622
+		self::set_TXN_ID($tax_line_item, $transaction);
623
+		$total_line_item->add_child_line_item($tax_line_item);
624 624
 		//and lastly, add the actual taxes
625
-		self::apply_taxes( $total_line_item );
625
+		self::apply_taxes($total_line_item);
626 626
 		return $tax_line_item;
627 627
 	}
628 628
 
@@ -637,11 +637,11 @@  discard block
 block discarded – undo
637 637
 	 * @return EE_Line_Item
638 638
 	 * @throws \EE_Error
639 639
 	 */
640
-	public static function create_event_subtotal( EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL ){
640
+	public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL) {
641 641
 		$event_line_item = EE_Line_Item::new_instance(array(
642
-			'LIN_code'	=> self::get_event_code( $event ),
643
-			'LIN_name' 	=> self::get_event_name( $event ),
644
-			'LIN_desc' 	=> self::get_event_desc( $event ),
642
+			'LIN_code'	=> self::get_event_code($event),
643
+			'LIN_name' 	=> self::get_event_name($event),
644
+			'LIN_desc' 	=> self::get_event_desc($event),
645 645
 			'LIN_type'	=> EEM_Line_Item::type_sub_total,
646 646
 			'OBJ_type' 	=> 'Event',
647 647
 			'OBJ_ID' 		=>  $event instanceof EE_Event ? $event->ID() : 0
@@ -650,8 +650,8 @@  discard block
 block discarded – undo
650 650
 			'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item',
651 651
 			$event_line_item
652 652
 		);
653
-		self::set_TXN_ID( $event_line_item, $transaction );
654
-		$pre_tax_line_item->add_child_line_item( $event_line_item );
653
+		self::set_TXN_ID($event_line_item, $transaction);
654
+		$pre_tax_line_item->add_child_line_item($event_line_item);
655 655
 		return $event_line_item;
656 656
 	}
657 657
 
@@ -664,8 +664,8 @@  discard block
 block discarded – undo
664 664
 	 * @return string
665 665
 	 * @throws \EE_Error
666 666
 	 */
667
-	public static function get_event_code( $event ) {
668
-		return 'event-' . ( $event instanceof EE_Event ? $event->ID() : '0' );
667
+	public static function get_event_code($event) {
668
+		return 'event-'.($event instanceof EE_Event ? $event->ID() : '0');
669 669
 	}
670 670
 
671 671
 	/**
@@ -673,8 +673,8 @@  discard block
 block discarded – undo
673 673
 	 * @param EE_Event $event
674 674
 	 * @return string
675 675
 	 */
676
-	public static function get_event_name( $event ) {
677
-		return $event instanceof EE_Event ? $event->name() : __( 'Event', 'event_espresso' );
676
+	public static function get_event_name($event) {
677
+		return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso');
678 678
 	}
679 679
 
680 680
 	/**
@@ -682,7 +682,7 @@  discard block
 block discarded – undo
682 682
 	 * @param EE_Event $event
683 683
 	 * @return string
684 684
 	 */
685
-	public static function get_event_desc( $event ) {
685
+	public static function get_event_desc($event) {
686 686
 		return $event instanceof EE_Event ? $event->short_description() : '';
687 687
 	}
688 688
 
@@ -696,27 +696,27 @@  discard block
 block discarded – undo
696 696
 	  * @throws \EE_Error
697 697
 	  * @return EE_Line_Item
698 698
 	  */
699
-	public static function get_event_line_item_for_ticket( EE_Line_Item $grand_total, EE_Ticket $ticket ) {
699
+	public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) {
700 700
 		$first_datetime = $ticket->first_datetime();
701
-		if ( ! $first_datetime instanceof EE_Datetime ) {
701
+		if ( ! $first_datetime instanceof EE_Datetime) {
702 702
 			throw new EE_Error(
703
-				sprintf( __( 'The supplied ticket (ID %d) has no datetimes', 'event_espresso' ), $ticket->ID() )
703
+				sprintf(__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), $ticket->ID())
704 704
 			);
705 705
 		}
706 706
 		$event = $first_datetime->event();
707
-		if ( ! $event instanceof EE_Event ) {
707
+		if ( ! $event instanceof EE_Event) {
708 708
 			throw new EE_Error(
709 709
 				sprintf(
710
-					__( 'The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso' ),
710
+					__('The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso'),
711 711
 					$ticket->ID()
712 712
 				)
713 713
 			);
714 714
 		}
715
-		$events_sub_total = EEH_Line_Item::get_event_line_item( $grand_total, $event );
716
-		if ( ! $events_sub_total instanceof EE_Line_Item ) {
715
+		$events_sub_total = EEH_Line_Item::get_event_line_item($grand_total, $event);
716
+		if ( ! $events_sub_total instanceof EE_Line_Item) {
717 717
 			throw new EE_Error(
718 718
 				sprintf(
719
-					__( 'There is no events sub-total for ticket %s on total line item %d', 'event_espresso' ),
719
+					__('There is no events sub-total for ticket %s on total line item %d', 'event_espresso'),
720 720
 					$ticket->ID(),
721 721
 					$grand_total->ID()
722 722
 				)
@@ -735,31 +735,31 @@  discard block
 block discarded – undo
735 735
 	 * @return EE_Line_Item for the event subtotal which is a child of $grand_total
736 736
 	 * @throws \EE_Error
737 737
 	 */
738
-	public static function get_event_line_item( EE_Line_Item $grand_total, $event ) {
738
+	public static function get_event_line_item(EE_Line_Item $grand_total, $event) {
739 739
 		/** @type EE_Event $event */
740
-		$event = EEM_Event::instance()->ensure_is_obj( $event, true );
740
+		$event = EEM_Event::instance()->ensure_is_obj($event, true);
741 741
 		$event_line_item = NULL;
742 742
 		$found = false;
743
-		foreach ( EEH_Line_Item::get_event_subtotals( $grand_total ) as $event_line_item ) {
743
+		foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) {
744 744
 			// default event subtotal, we should only ever find this the first time this method is called
745
-			if ( ! $event_line_item->OBJ_ID() ) {
745
+			if ( ! $event_line_item->OBJ_ID()) {
746 746
 				// let's use this! but first... set the event details
747
-				EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event );
747
+				EEH_Line_Item::set_event_subtotal_details($event_line_item, $event);
748 748
 				$found = true;
749 749
 				break;
750
-			} else if ( $event_line_item->OBJ_ID() === $event->ID() ) {
750
+			} else if ($event_line_item->OBJ_ID() === $event->ID()) {
751 751
 				// found existing line item for this event in the cart, so break out of loop and use this one
752 752
 				$found = true;
753 753
 				break;
754 754
 			}
755 755
 		}
756
-		if ( ! $found ) {
756
+		if ( ! $found) {
757 757
 			//there is no event sub-total yet, so add it
758
-			$pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal( $grand_total );
758
+			$pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total);
759 759
 			// create a new "event" subtotal below that
760
-			$event_line_item = EEH_Line_Item::create_event_subtotal( $pre_tax_subtotal, null, $event );
760
+			$event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event);
761 761
 			// and set the event details
762
-			EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event );
762
+			EEH_Line_Item::set_event_subtotal_details($event_line_item, $event);
763 763
 		}
764 764
 		return $event_line_item;
765 765
 	}
@@ -780,13 +780,13 @@  discard block
 block discarded – undo
780 780
 		EE_Event $event,
781 781
 		$transaction = null
782 782
 	) {
783
-		if ( $event instanceof EE_Event ) {
784
-			$event_line_item->set_code( self::get_event_code( $event ) );
785
-			$event_line_item->set_name( self::get_event_name( $event ) );
786
-			$event_line_item->set_desc( self::get_event_desc( $event ) );
787
-			$event_line_item->set_OBJ_ID( $event->ID() );
783
+		if ($event instanceof EE_Event) {
784
+			$event_line_item->set_code(self::get_event_code($event));
785
+			$event_line_item->set_name(self::get_event_name($event));
786
+			$event_line_item->set_desc(self::get_event_desc($event));
787
+			$event_line_item->set_OBJ_ID($event->ID());
788 788
 		}
789
-		self::set_TXN_ID( $event_line_item, $transaction );
789
+		self::set_TXN_ID($event_line_item, $transaction);
790 790
 	}
791 791
 
792 792
 
@@ -799,19 +799,19 @@  discard block
 block discarded – undo
799 799
 	 * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total
800 800
 	 * @throws \EE_Error
801 801
 	 */
802
-	public static function apply_taxes( EE_Line_Item $total_line_item ){
802
+	public static function apply_taxes(EE_Line_Item $total_line_item) {
803 803
 		/** @type EEM_Price $EEM_Price */
804
-		$EEM_Price = EE_Registry::instance()->load_model( 'Price' );
804
+		$EEM_Price = EE_Registry::instance()->load_model('Price');
805 805
 		// get array of taxes via Price Model
806 806
 		$ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes();
807
-		ksort( $ordered_taxes );
808
-		$taxes_line_item = self::get_taxes_subtotal( $total_line_item );
807
+		ksort($ordered_taxes);
808
+		$taxes_line_item = self::get_taxes_subtotal($total_line_item);
809 809
 		//just to be safe, remove its old tax line items
810 810
 		$taxes_line_item->delete_children_line_items();
811 811
 		//loop thru taxes
812
-		foreach ( $ordered_taxes as $order => $taxes ) {
813
-			foreach ( $taxes as $tax ) {
814
-				if ( $tax instanceof EE_Price ) {
812
+		foreach ($ordered_taxes as $order => $taxes) {
813
+			foreach ($taxes as $tax) {
814
+				if ($tax instanceof EE_Price) {
815 815
 					$tax_line_item = EE_Line_Item::new_instance(
816 816
 						array(
817 817
 							'LIN_name'       => $tax->name(),
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
 						'FHEE__EEH_Line_Item__apply_taxes__tax_line_item',
830 830
 						$tax_line_item
831 831
 					);
832
-					$taxes_line_item->add_child_line_item( $tax_line_item );
832
+					$taxes_line_item->add_child_line_item($tax_line_item);
833 833
 				}
834 834
 			}
835 835
 		}
@@ -846,10 +846,10 @@  discard block
 block discarded – undo
846 846
 	 * @return float
847 847
 	 * @throws \EE_Error
848 848
 	 */
849
-	public static function ensure_taxes_applied( $total_line_item ){
850
-		$taxes_subtotal = self::get_taxes_subtotal( $total_line_item );
851
-		if( ! $taxes_subtotal->children()){
852
-			self::apply_taxes( $total_line_item );
849
+	public static function ensure_taxes_applied($total_line_item) {
850
+		$taxes_subtotal = self::get_taxes_subtotal($total_line_item);
851
+		if ( ! $taxes_subtotal->children()) {
852
+			self::apply_taxes($total_line_item);
853 853
 		}
854 854
 		return $taxes_subtotal->total();
855 855
 	}
@@ -863,16 +863,16 @@  discard block
 block discarded – undo
863 863
 	 * @return bool
864 864
 	 * @throws \EE_Error
865 865
 	 */
866
-	public static function delete_all_child_items( EE_Line_Item $parent_line_item ) {
866
+	public static function delete_all_child_items(EE_Line_Item $parent_line_item) {
867 867
 		$deleted = 0;
868
-		foreach ( $parent_line_item->children() as $child_line_item ) {
869
-			if ( $child_line_item instanceof EE_Line_Item ) {
870
-				$deleted += EEH_Line_Item::delete_all_child_items( $child_line_item );
871
-				if ( $child_line_item->ID() ) {
868
+		foreach ($parent_line_item->children() as $child_line_item) {
869
+			if ($child_line_item instanceof EE_Line_Item) {
870
+				$deleted += EEH_Line_Item::delete_all_child_items($child_line_item);
871
+				if ($child_line_item->ID()) {
872 872
 					$child_line_item->delete();
873
-					unset( $child_line_item );
873
+					unset($child_line_item);
874 874
 				} else {
875
-					$parent_line_item->delete_child_line_item( $child_line_item->code() );
875
+					$parent_line_item->delete_child_line_item($child_line_item->code());
876 876
 				}
877 877
 				$deleted++;
878 878
 			}
@@ -894,9 +894,9 @@  discard block
 block discarded – undo
894 894
 	 * @param array|bool|string $line_item_codes
895 895
 	 * @return int number of items successfully removed
896 896
 	 */
897
-	public static function delete_items( EE_Line_Item $total_line_item, $line_item_codes = FALSE ) {
897
+	public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = FALSE) {
898 898
 
899
-		if( $total_line_item->type() !== EEM_Line_Item::type_total ){
899
+		if ($total_line_item->type() !== EEM_Line_Item::type_total) {
900 900
 			EE_Error::doing_it_wrong(
901 901
 				'EEH_Line_Item::delete_items',
902 902
 				__(
@@ -906,20 +906,20 @@  discard block
 block discarded – undo
906 906
 				'4.6.18'
907 907
 			);
908 908
 		}
909
-		do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' );
909
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
910 910
 
911 911
 		// check if only a single line_item_id was passed
912
-		if ( ! empty( $line_item_codes ) && ! is_array( $line_item_codes )) {
912
+		if ( ! empty($line_item_codes) && ! is_array($line_item_codes)) {
913 913
 			// place single line_item_id in an array to appear as multiple line_item_ids
914
-			$line_item_codes = array ( $line_item_codes );
914
+			$line_item_codes = array($line_item_codes);
915 915
 		}
916 916
 		$removals = 0;
917 917
 		// cycle thru line_item_ids
918
-		foreach ( $line_item_codes as $line_item_id ) {
918
+		foreach ($line_item_codes as $line_item_id) {
919 919
 			$removals += $total_line_item->delete_child_line_item($line_item_id);
920 920
 		}
921 921
 
922
-		if ( $removals > 0 ) {
922
+		if ($removals > 0) {
923 923
 			$total_line_item->recalculate_taxes_and_tax_total();
924 924
 			return $removals;
925 925
 		} else {
@@ -952,33 +952,33 @@  discard block
 block discarded – undo
952 952
 		$code = null,
953 953
 		$add_to_existing_line_item = false
954 954
 	) {
955
-		$tax_subtotal = self::get_taxes_subtotal( $total_line_item );
955
+		$tax_subtotal = self::get_taxes_subtotal($total_line_item);
956 956
             $taxable_total = $total_line_item->taxable_total();
957 957
 
958
-            if( $add_to_existing_line_item ) {
959
-                $new_tax = $tax_subtotal->get_child_line_item( $code );
958
+            if ($add_to_existing_line_item) {
959
+                $new_tax = $tax_subtotal->get_child_line_item($code);
960 960
 	            EEM_Line_Item::instance()->delete(
961
-		            array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) )
961
+		            array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID()))
962 962
 	            );
963 963
             } else {
964 964
                 $new_tax = null;
965 965
                 $tax_subtotal->delete_children_line_items();
966 966
             }
967
-            if( $new_tax ) {
968
-                $new_tax->set_total( $new_tax->total() + $amount );
969
-                $new_tax->set_percent( $taxable_total ? $new_tax->total() / $taxable_total * 100 : 0 );
967
+            if ($new_tax) {
968
+                $new_tax->set_total($new_tax->total() + $amount);
969
+                $new_tax->set_percent($taxable_total ? $new_tax->total() / $taxable_total * 100 : 0);
970 970
             } else {
971 971
                 //no existing tax item. Create it
972
-				$new_tax = EE_Line_Item::new_instance( array(
972
+				$new_tax = EE_Line_Item::new_instance(array(
973 973
 					'TXN_ID'      => $total_line_item->TXN_ID(),
974
-					'LIN_name'    => $name ? $name : __( 'Tax', 'event_espresso' ),
974
+					'LIN_name'    => $name ? $name : __('Tax', 'event_espresso'),
975 975
 					'LIN_desc'    => $description ? $description : '',
976
-					'LIN_percent' => $taxable_total ? ( $amount / $taxable_total * 100 ) : 0,
976
+					'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0,
977 977
 					'LIN_total'   => $amount,
978 978
 					'LIN_parent'  => $tax_subtotal->ID(),
979 979
 					'LIN_type'    => EEM_Line_Item::type_tax,
980 980
 					'LIN_code'    => $code
981
-				) );
981
+				));
982 982
 			}
983 983
 
984 984
             $new_tax = apply_filters(
@@ -987,7 +987,7 @@  discard block
 block discarded – undo
987 987
 				$total_line_item
988 988
             );
989 989
             $new_tax->save();
990
-            $tax_subtotal->set_total( $new_tax->total() );
990
+            $tax_subtotal->set_total($new_tax->total());
991 991
             $tax_subtotal->save();
992 992
             $total_line_item->recalculate_total_including_taxes();
993 993
             return $new_tax;
@@ -1009,14 +1009,14 @@  discard block
 block discarded – undo
1009 1009
 		$code_substring_for_whitelist = null
1010 1010
 	) {
1011 1011
 		$whitelisted = false;
1012
-		if( $code_substring_for_whitelist !== null ) {
1013
-			$whitelisted = strpos( $line_item->code(), $code_substring_for_whitelist ) !== false ? true : false;
1012
+		if ($code_substring_for_whitelist !== null) {
1013
+			$whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false ? true : false;
1014 1014
 		}
1015
-		if( ! $whitelisted && $line_item->is_line_item() ) {
1016
-			$line_item->set_is_taxable( $taxable );
1015
+		if ( ! $whitelisted && $line_item->is_line_item()) {
1016
+			$line_item->set_is_taxable($taxable);
1017 1017
 		}
1018
-		foreach( $line_item->children() as $child_line_item ) {
1019
-			EEH_Line_Item::set_line_items_taxable( $child_line_item, $taxable, $code_substring_for_whitelist );
1018
+		foreach ($line_item->children() as $child_line_item) {
1019
+			EEH_Line_Item::set_line_items_taxable($child_line_item, $taxable, $code_substring_for_whitelist);
1020 1020
 		}
1021 1021
 	}
1022 1022
 
@@ -1029,8 +1029,8 @@  discard block
 block discarded – undo
1029 1029
 	 * @param \EE_Line_Item $parent_line_item - the line item to find descendants of
1030 1030
 	 * @return EE_Line_Item[]
1031 1031
 	 */
1032
-	public static function get_event_subtotals( EE_Line_Item $parent_line_item ) {
1033
-		return self::get_subtotals_of_object_type( $parent_line_item, 'Event' );
1032
+	public static function get_event_subtotals(EE_Line_Item $parent_line_item) {
1033
+		return self::get_subtotals_of_object_type($parent_line_item, 'Event');
1034 1034
 	}
1035 1035
 
1036 1036
 
@@ -1043,7 +1043,7 @@  discard block
 block discarded – undo
1043 1043
 	 * @param string $obj_type
1044 1044
 	 * @return EE_Line_Item[]
1045 1045
 	 */
1046
-	public static function get_subtotals_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) {
1046
+	public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') {
1047 1047
 		return self::_get_descendants_by_type_and_object_type(
1048 1048
 			$parent_line_item,
1049 1049
 			EEM_Line_Item::type_sub_total,
@@ -1060,8 +1060,8 @@  discard block
 block discarded – undo
1060 1060
 	 * @param \EE_Line_Item $parent_line_item - the line item to find descendants of
1061 1061
 	 * @return EE_Line_Item[]
1062 1062
 	 */
1063
-	public static function get_ticket_line_items( EE_Line_Item $parent_line_item ) {
1064
-		return self::get_line_items_of_object_type( $parent_line_item, 'Ticket' );
1063
+	public static function get_ticket_line_items(EE_Line_Item $parent_line_item) {
1064
+		return self::get_line_items_of_object_type($parent_line_item, 'Ticket');
1065 1065
 	}
1066 1066
 
1067 1067
 
@@ -1074,8 +1074,8 @@  discard block
 block discarded – undo
1074 1074
 	 * @param string $obj_type
1075 1075
 	 * @return EE_Line_Item[]
1076 1076
 	 */
1077
-	public static function get_line_items_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) {
1078
-		return self::_get_descendants_by_type_and_object_type( $parent_line_item, EEM_Line_Item::type_line_item, $obj_type );
1077
+	public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') {
1078
+		return self::_get_descendants_by_type_and_object_type($parent_line_item, EEM_Line_Item::type_line_item, $obj_type);
1079 1079
 	}
1080 1080
 
1081 1081
 
@@ -1086,8 +1086,8 @@  discard block
 block discarded – undo
1086 1086
 	 * @param \EE_Line_Item $parent_line_item - the line item to find descendants of
1087 1087
 	 * @return EE_Line_Item[]
1088 1088
 	 */
1089
-	public static function get_tax_descendants( EE_Line_Item $parent_line_item ) {
1090
-		return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_tax );
1089
+	public static function get_tax_descendants(EE_Line_Item $parent_line_item) {
1090
+		return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_tax);
1091 1091
 	}
1092 1092
 
1093 1093
 
@@ -1098,8 +1098,8 @@  discard block
 block discarded – undo
1098 1098
 	 * @param \EE_Line_Item $parent_line_item - the line item to find descendants of
1099 1099
 	 * @return EE_Line_Item[]
1100 1100
 	 */
1101
-	public static function get_line_item_descendants( EE_Line_Item $parent_line_item ) {
1102
-		return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_line_item );
1101
+	public static function get_line_item_descendants(EE_Line_Item $parent_line_item) {
1102
+		return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_line_item);
1103 1103
 	}
1104 1104
 
1105 1105
 
@@ -1112,8 +1112,8 @@  discard block
 block discarded – undo
1112 1112
 	 * @param string $line_item_type one of the EEM_Line_Item constants
1113 1113
 	 * @return EE_Line_Item[]
1114 1114
 	 */
1115
-	public static function get_descendants_of_type( EE_Line_Item $parent_line_item, $line_item_type ) {
1116
-		return self::_get_descendants_by_type_and_object_type( $parent_line_item, $line_item_type, NULL );
1115
+	public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type) {
1116
+		return self::_get_descendants_by_type_and_object_type($parent_line_item, $line_item_type, NULL);
1117 1117
 	}
1118 1118
 
1119 1119
 
@@ -1132,8 +1132,8 @@  discard block
 block discarded – undo
1132 1132
 		$obj_type = null
1133 1133
 	) {
1134 1134
 		$objects = array();
1135
-		foreach ( $parent_line_item->children() as $child_line_item ) {
1136
-			if ( $child_line_item instanceof EE_Line_Item ) {
1135
+		foreach ($parent_line_item->children() as $child_line_item) {
1136
+			if ($child_line_item instanceof EE_Line_Item) {
1137 1137
 				if (
1138 1138
 					$child_line_item->type() === $line_item_type
1139 1139
 				    && (
@@ -1173,7 +1173,7 @@  discard block
 block discarded – undo
1173 1173
 		$OBJ_type = '',
1174 1174
 		$OBJ_IDs = array()
1175 1175
 	) {
1176
-		return self::_get_descendants_by_object_type_and_object_ID( $parent_line_item, $OBJ_type, $OBJ_IDs );
1176
+		return self::_get_descendants_by_object_type_and_object_ID($parent_line_item, $OBJ_type, $OBJ_IDs);
1177 1177
 	}
1178 1178
 
1179 1179
 
@@ -1192,12 +1192,12 @@  discard block
 block discarded – undo
1192 1192
 		$OBJ_IDs
1193 1193
 	) {
1194 1194
 		$objects = array();
1195
-		foreach ( $parent_line_item->children() as $child_line_item ) {
1196
-			if ( $child_line_item instanceof EE_Line_Item ) {
1195
+		foreach ($parent_line_item->children() as $child_line_item) {
1196
+			if ($child_line_item instanceof EE_Line_Item) {
1197 1197
 				if (
1198
-					is_array( $OBJ_IDs )
1198
+					is_array($OBJ_IDs)
1199 1199
 					&& $child_line_item->OBJ_type() === $OBJ_type
1200
-					&& in_array( $child_line_item->OBJ_ID(), $OBJ_IDs )
1200
+					&& in_array($child_line_item->OBJ_ID(), $OBJ_IDs)
1201 1201
 				) {
1202 1202
 					$objects[] = $child_line_item;
1203 1203
 				} else {
@@ -1227,8 +1227,8 @@  discard block
 block discarded – undo
1227 1227
 	 * @param string $type like one of the EEM_Line_Item::type_*
1228 1228
 	 * @return EE_Line_Item
1229 1229
 	 */
1230
-	public static function get_nearest_descendant_of_type( EE_Line_Item $parent_line_item, $type ) {
1231
-		return self::_get_nearest_descendant( $parent_line_item, 'LIN_type' , $type );
1230
+	public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type) {
1231
+		return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type);
1232 1232
 	}
1233 1233
 
1234 1234
 
@@ -1242,8 +1242,8 @@  discard block
 block discarded – undo
1242 1242
 	 * @param string $code any value used for LIN_code
1243 1243
 	 * @return EE_Line_Item
1244 1244
 	 */
1245
-	public static function get_nearest_descendant_having_code( EE_Line_Item $parent_line_item, $code ) {
1246
-		return self::_get_nearest_descendant( $parent_line_item, 'LIN_code' , $code );
1245
+	public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code) {
1246
+		return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code);
1247 1247
 	}
1248 1248
 
1249 1249
 
@@ -1257,15 +1257,15 @@  discard block
 block discarded – undo
1257 1257
 	 * @param string $value any value stored in $search_field
1258 1258
 	 * @return EE_Line_Item
1259 1259
 	 */
1260
-	protected static function _get_nearest_descendant( EE_Line_Item $parent_line_item, $search_field, $value ) {
1261
-		foreach( $parent_line_item->children() as $child ){
1262
-			if ( $child->get( $search_field ) == $value ){
1260
+	protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value) {
1261
+		foreach ($parent_line_item->children() as $child) {
1262
+			if ($child->get($search_field) == $value) {
1263 1263
 				return $child;
1264 1264
 			}
1265 1265
 		}
1266
-		foreach( $parent_line_item->children() as $child ){
1267
-			$descendant_found = self::_get_nearest_descendant( $child, $search_field, $value );
1268
-			if ( $descendant_found ){
1266
+		foreach ($parent_line_item->children() as $child) {
1267
+			$descendant_found = self::_get_nearest_descendant($child, $search_field, $value);
1268
+			if ($descendant_found) {
1269 1269
 				return $descendant_found;
1270 1270
 			}
1271 1271
 		}
@@ -1282,24 +1282,24 @@  discard block
 block discarded – undo
1282 1282
 	 * @return \EE_Line_Item
1283 1283
 	 * @throws \EE_Error
1284 1284
 	 */
1285
-	public static function find_transaction_grand_total_for_line_item( EE_Line_Item $line_item ){
1286
-		if ( $line_item->TXN_ID() ) {
1287
-			$total_line_item = $line_item->transaction()->total_line_item( false );
1288
-			if ( $total_line_item instanceof EE_Line_Item ) {
1285
+	public static function find_transaction_grand_total_for_line_item(EE_Line_Item $line_item) {
1286
+		if ($line_item->TXN_ID()) {
1287
+			$total_line_item = $line_item->transaction()->total_line_item(false);
1288
+			if ($total_line_item instanceof EE_Line_Item) {
1289 1289
 				return $total_line_item;
1290 1290
 			}
1291 1291
 		} else {
1292 1292
 			$line_item_parent = $line_item->parent();
1293
-			if ( $line_item_parent instanceof EE_Line_Item ) {
1294
-				if ( $line_item_parent->is_total() ) {
1293
+			if ($line_item_parent instanceof EE_Line_Item) {
1294
+				if ($line_item_parent->is_total()) {
1295 1295
 					return $line_item_parent;
1296 1296
 				}
1297
-				return EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item_parent );
1297
+				return EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item_parent);
1298 1298
 			}
1299 1299
 		}
1300 1300
 		throw new EE_Error(
1301 1301
 			sprintf(
1302
-				__( 'A valid grand total for line item %1$d was not found.', 'event_espresso' ),
1302
+				__('A valid grand total for line item %1$d was not found.', 'event_espresso'),
1303 1303
 				$line_item->ID()
1304 1304
 			)
1305 1305
 		);
@@ -1316,31 +1316,31 @@  discard block
 block discarded – undo
1316 1316
 	 * @return void
1317 1317
 	 * @throws \EE_Error
1318 1318
 	 */
1319
-	public static function visualize( EE_Line_Item $line_item, $indentation = 0 ){
1319
+	public static function visualize(EE_Line_Item $line_item, $indentation = 0) {
1320 1320
 		echo defined('EE_TESTS_DIR') ? "\n" : '<br />';
1321
-		if ( ! $indentation ) {
1322
-			echo defined( 'EE_TESTS_DIR' ) ? "\n" : '<br />';
1321
+		if ( ! $indentation) {
1322
+			echo defined('EE_TESTS_DIR') ? "\n" : '<br />';
1323 1323
 		}
1324
-		for( $i = 0; $i < $indentation; $i++ ){
1324
+		for ($i = 0; $i < $indentation; $i++) {
1325 1325
 			echo ". ";
1326 1326
 		}
1327 1327
 		$breakdown = '';
1328
-		if ( $line_item->is_line_item()){
1329
-			if ( $line_item->is_percent() ) {
1328
+		if ($line_item->is_line_item()) {
1329
+			if ($line_item->is_percent()) {
1330 1330
 				$breakdown = "{$line_item->percent()}%";
1331 1331
 			} else {
1332
-				$breakdown = '$' . "{$line_item->unit_price()} x {$line_item->quantity()}";
1332
+				$breakdown = '$'."{$line_item->unit_price()} x {$line_item->quantity()}";
1333 1333
 			}
1334 1334
 		}
1335
-		echo $line_item->name() . " ( ID:{$line_item->ID()} ) : {$line_item->type()} " . '$' . "{$line_item->total()}";
1336
-		if ( $breakdown ) {
1335
+		echo $line_item->name()." ( ID:{$line_item->ID()} ) : {$line_item->type()} ".'$'."{$line_item->total()}";
1336
+		if ($breakdown) {
1337 1337
 			echo " ( {$breakdown} )";
1338 1338
 		}
1339
-		if( $line_item->is_taxable() ){
1339
+		if ($line_item->is_taxable()) {
1340 1340
 			echo "  * taxable";
1341 1341
 		}
1342
-		if( $line_item->children() ){
1343
-			foreach($line_item->children() as $child){
1342
+		if ($line_item->children()) {
1343
+			foreach ($line_item->children() as $child) {
1344 1344
 				self::visualize($child, $indentation + 1);
1345 1345
 			}
1346 1346
 		}
@@ -1381,97 +1381,97 @@  discard block
 block discarded – undo
1381 1381
 	 *                                          is theirs, which can be done with
1382 1382
 	 *                                          `EEM_Line_Item::instance()->get_line_item_for_registration( $registration );`
1383 1383
 	 */
1384
-	public static function calculate_reg_final_prices_per_line_item( EE_Line_Item $line_item, $billable_ticket_quantities = array() ) {
1384
+	public static function calculate_reg_final_prices_per_line_item(EE_Line_Item $line_item, $billable_ticket_quantities = array()) {
1385 1385
 		//init running grand total if not already
1386
-		if ( ! isset( $running_totals[ 'total' ] ) ) {
1387
-			$running_totals[ 'total' ] = 0;
1386
+		if ( ! isset($running_totals['total'])) {
1387
+			$running_totals['total'] = 0;
1388 1388
 		}
1389
-		if( ! isset( $running_totals[ 'taxable' ] ) ) {
1390
-			$running_totals[ 'taxable' ] = array( 'total' => 0 );
1389
+		if ( ! isset($running_totals['taxable'])) {
1390
+			$running_totals['taxable'] = array('total' => 0);
1391 1391
 		}
1392
-		foreach ( $line_item->children() as $child_line_item ) {
1393
-			switch ( $child_line_item->type() ) {
1392
+		foreach ($line_item->children() as $child_line_item) {
1393
+			switch ($child_line_item->type()) {
1394 1394
 
1395 1395
 				case EEM_Line_Item::type_sub_total :
1396
-					$running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $child_line_item, $billable_ticket_quantities );
1396
+					$running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item($child_line_item, $billable_ticket_quantities);
1397 1397
 					//combine arrays but preserve numeric keys
1398
-					$running_totals = array_replace_recursive( $running_totals_from_subtotal, $running_totals );
1399
-					$running_totals[ 'total' ] += $running_totals_from_subtotal[ 'total' ];
1400
-					$running_totals[ 'taxable'][ 'total' ] += $running_totals_from_subtotal[ 'taxable' ][ 'total' ];
1398
+					$running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals);
1399
+					$running_totals['total'] += $running_totals_from_subtotal['total'];
1400
+					$running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total'];
1401 1401
 					break;
1402 1402
 
1403 1403
 				case EEM_Line_Item::type_tax_sub_total :
1404 1404
 
1405 1405
 					//find how much the taxes percentage is
1406
-					if ( $child_line_item->percent() !== 0 ) {
1406
+					if ($child_line_item->percent() !== 0) {
1407 1407
 						$tax_percent_decimal = $child_line_item->percent() / 100;
1408 1408
 					} else {
1409 1409
 						$tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100;
1410 1410
 					}
1411 1411
 					//and apply to all the taxable totals, and add to the pretax totals
1412
-					foreach ( $running_totals as $line_item_id => $this_running_total ) {
1412
+					foreach ($running_totals as $line_item_id => $this_running_total) {
1413 1413
 						//"total" and "taxable" array key is an exception
1414
-						if ( $line_item_id === 'taxable' ) {
1414
+						if ($line_item_id === 'taxable') {
1415 1415
 							continue;
1416 1416
 						}
1417
-						$taxable_total = $running_totals[ 'taxable' ][ $line_item_id ];
1418
-						$running_totals[ $line_item_id ] += ( $taxable_total * $tax_percent_decimal );
1417
+						$taxable_total = $running_totals['taxable'][$line_item_id];
1418
+						$running_totals[$line_item_id] += ($taxable_total * $tax_percent_decimal);
1419 1419
 					}
1420 1420
 					break;
1421 1421
 
1422 1422
 				case EEM_Line_Item::type_line_item :
1423 1423
 
1424 1424
 					// ticket line items or ????
1425
-					if ( $child_line_item->OBJ_type() === 'Ticket' ) {
1425
+					if ($child_line_item->OBJ_type() === 'Ticket') {
1426 1426
 						// kk it's a ticket
1427
-						if ( isset( $running_totals[ $child_line_item->ID() ] ) ) {
1427
+						if (isset($running_totals[$child_line_item->ID()])) {
1428 1428
 							//huh? that shouldn't happen.
1429
-							$running_totals[ 'total' ] += $child_line_item->total();
1429
+							$running_totals['total'] += $child_line_item->total();
1430 1430
 						} else {
1431 1431
 							//its not in our running totals yet. great.
1432
-							if ( $child_line_item->is_taxable() ) {
1432
+							if ($child_line_item->is_taxable()) {
1433 1433
 								$taxable_amount = $child_line_item->unit_price();
1434 1434
 							} else {
1435 1435
 								$taxable_amount = 0;
1436 1436
 							}
1437 1437
 							// are we only calculating totals for some tickets?
1438
-							if ( isset( $billable_ticket_quantities[ $child_line_item->OBJ_ID() ] ) ) {
1439
-								$quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ];
1440
-								$running_totals[ $child_line_item->ID() ] = $quantity
1438
+							if (isset($billable_ticket_quantities[$child_line_item->OBJ_ID()])) {
1439
+								$quantity = $billable_ticket_quantities[$child_line_item->OBJ_ID()];
1440
+								$running_totals[$child_line_item->ID()] = $quantity
1441 1441
 									? $child_line_item->unit_price()
1442 1442
 									: 0;
1443
-								$running_totals[ 'taxable' ][ $child_line_item->ID() ] = $quantity
1443
+								$running_totals['taxable'][$child_line_item->ID()] = $quantity
1444 1444
 									? $taxable_amount
1445 1445
 									: 0;
1446 1446
 							} else {
1447 1447
 								$quantity = $child_line_item->quantity();
1448
-								$running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price();
1449
-								$running_totals[ 'taxable' ][ $child_line_item->ID() ] = $taxable_amount;
1448
+								$running_totals[$child_line_item->ID()] = $child_line_item->unit_price();
1449
+								$running_totals['taxable'][$child_line_item->ID()] = $taxable_amount;
1450 1450
 							}
1451
-							$running_totals[ 'taxable' ][ 'total' ] += $taxable_amount * $quantity;
1452
-							$running_totals[ 'total' ] += $child_line_item->unit_price() * $quantity;
1451
+							$running_totals['taxable']['total'] += $taxable_amount * $quantity;
1452
+							$running_totals['total'] += $child_line_item->unit_price() * $quantity;
1453 1453
 						}
1454 1454
 					} else {
1455 1455
 						// it's some other type of item added to the cart
1456 1456
 						// it should affect the running totals
1457 1457
 						// basically we want to convert it into a PERCENT modifier. Because
1458 1458
 						// more clearly affect all registration's final price equally
1459
-						$line_items_percent_of_running_total = $running_totals[ 'total' ] > 0
1460
-							? ( $child_line_item->total() / $running_totals[ 'total' ] ) + 1
1459
+						$line_items_percent_of_running_total = $running_totals['total'] > 0
1460
+							? ($child_line_item->total() / $running_totals['total']) + 1
1461 1461
 							: 1;
1462
-						foreach ( $running_totals as $line_item_id => $this_running_total ) {
1462
+						foreach ($running_totals as $line_item_id => $this_running_total) {
1463 1463
 							//the "taxable" array key is an exception
1464
-							if ( $line_item_id === 'taxable' ) {
1464
+							if ($line_item_id === 'taxable') {
1465 1465
 								continue;
1466 1466
 							}
1467 1467
 							// update the running totals
1468 1468
 							// yes this actually even works for the running grand total!
1469
-							$running_totals[ $line_item_id ] =
1469
+							$running_totals[$line_item_id] =
1470 1470
 								$line_items_percent_of_running_total * $this_running_total;
1471 1471
 
1472
-							if ( $child_line_item->is_taxable() ) {
1473
-								$running_totals[ 'taxable' ][ $line_item_id ] =
1474
-									$line_items_percent_of_running_total * $running_totals[ 'taxable' ][ $line_item_id ];
1472
+							if ($child_line_item->is_taxable()) {
1473
+								$running_totals['taxable'][$line_item_id] =
1474
+									$line_items_percent_of_running_total * $running_totals['taxable'][$line_item_id];
1475 1475
 							}
1476 1476
 						}
1477 1477
 					}
@@ -1489,16 +1489,16 @@  discard block
 block discarded – undo
1489 1489
 	 * @return float | null
1490 1490
 	 * @throws \OutOfRangeException
1491 1491
 	 */
1492
-	public static function calculate_final_price_for_ticket_line_item( \EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item ) {
1492
+	public static function calculate_final_price_for_ticket_line_item(\EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item) {
1493 1493
 		static $final_prices_per_ticket_line_item = array();
1494
-		if ( empty( $final_prices_per_ticket_line_item ) ) {
1494
+		if (empty($final_prices_per_ticket_line_item)) {
1495 1495
 			$final_prices_per_ticket_line_item = \EEH_Line_Item::calculate_reg_final_prices_per_line_item(
1496 1496
 				$total_line_item
1497 1497
 			);
1498 1498
 		}
1499 1499
 		//ok now find this new registration's final price
1500
-		if ( isset( $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ] ) ) {
1501
-			return $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ];
1500
+		if (isset($final_prices_per_ticket_line_item[$ticket_line_item->ID()])) {
1501
+			return $final_prices_per_ticket_line_item[$ticket_line_item->ID()];
1502 1502
 		}
1503 1503
 		$message = sprintf(
1504 1504
 			__(
@@ -1507,10 +1507,10 @@  discard block
 block discarded – undo
1507 1507
 			),
1508 1508
 			$ticket_line_item->ID()
1509 1509
 		);
1510
-		if ( WP_DEBUG ) {
1511
-			throw new \OutOfRangeException( $message );
1510
+		if (WP_DEBUG) {
1511
+			throw new \OutOfRangeException($message);
1512 1512
 		} else {
1513
-			EE_Log::instance()->log( __CLASS__, __FUNCTION__, $message );
1513
+			EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message);
1514 1514
 		}
1515 1515
 		return null;
1516 1516
 	}
@@ -1526,15 +1526,15 @@  discard block
 block discarded – undo
1526 1526
 	 * @return \EE_Line_Item
1527 1527
 	 * @throws \EE_Error
1528 1528
 	 */
1529
-	public static function billable_line_item_tree( EE_Line_Item $line_item, $registrations ) {
1530
-		$copy_li = EEH_Line_Item::billable_line_item( $line_item, $registrations );
1531
-		foreach ( $line_item->children() as $child_li ) {
1532
-			$copy_li->add_child_line_item( EEH_Line_Item::billable_line_item_tree( $child_li, $registrations ) );
1529
+	public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations) {
1530
+		$copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations);
1531
+		foreach ($line_item->children() as $child_li) {
1532
+			$copy_li->add_child_line_item(EEH_Line_Item::billable_line_item_tree($child_li, $registrations));
1533 1533
 		}
1534 1534
 		//if this is the grand total line item, make sure the totals all add up
1535 1535
 		//(we could have duplicated this logic AS we copied the line items, but
1536 1536
 		//it seems DRYer this way)
1537
-		if ( $copy_li->type() === EEM_Line_Item::type_total ) {
1537
+		if ($copy_li->type() === EEM_Line_Item::type_total) {
1538 1538
 			$copy_li->recalculate_total_including_taxes();
1539 1539
 		}
1540 1540
 		return $copy_li;
@@ -1551,24 +1551,24 @@  discard block
 block discarded – undo
1551 1551
 	 * @throws \EE_Error
1552 1552
 	 * @param EE_Registration[] $registrations
1553 1553
 	 */
1554
-	public static function billable_line_item( EE_Line_Item $line_item, $registrations ) {
1554
+	public static function billable_line_item(EE_Line_Item $line_item, $registrations) {
1555 1555
 		$new_li_fields = $line_item->model_field_array();
1556
-		if ( $line_item->type() === EEM_Line_Item::type_line_item &&
1556
+		if ($line_item->type() === EEM_Line_Item::type_line_item &&
1557 1557
 			$line_item->OBJ_type() === 'Ticket'
1558 1558
 		) {
1559 1559
 			$count = 0;
1560
-			foreach ( $registrations as $registration ) {
1561
-				if ( $line_item->OBJ_ID() === $registration->ticket_ID() &&
1562
-					in_array( $registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment() )
1560
+			foreach ($registrations as $registration) {
1561
+				if ($line_item->OBJ_ID() === $registration->ticket_ID() &&
1562
+					in_array($registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment())
1563 1563
 				) {
1564 1564
 					$count++;
1565 1565
 				}
1566 1566
 			}
1567
-			$new_li_fields[ 'LIN_quantity' ] = $count;
1567
+			$new_li_fields['LIN_quantity'] = $count;
1568 1568
 		}
1569 1569
 		//don't set the total. We'll leave that up to the code that calculates it
1570
-		unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ], $new_li_fields[ 'LIN_total' ] );
1571
-		return EE_Line_Item::new_instance( $new_li_fields );
1570
+		unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent'], $new_li_fields['LIN_total']);
1571
+		return EE_Line_Item::new_instance($new_li_fields);
1572 1572
 	}
1573 1573
 
1574 1574
 
@@ -1581,19 +1581,19 @@  discard block
 block discarded – undo
1581 1581
 	 * @return \EE_Line_Item|null
1582 1582
 	 * @throws \EE_Error
1583 1583
 	 */
1584
-	public static function non_empty_line_items( EE_Line_Item $line_item ) {
1585
-		$copied_li = EEH_Line_Item::non_empty_line_item( $line_item );
1586
-		if ( $copied_li === null ) {
1584
+	public static function non_empty_line_items(EE_Line_Item $line_item) {
1585
+		$copied_li = EEH_Line_Item::non_empty_line_item($line_item);
1586
+		if ($copied_li === null) {
1587 1587
 			return null;
1588 1588
 		}
1589 1589
 		//if this is an event subtotal, we want to only include it if it
1590 1590
 		//has a non-zero total and at least one ticket line item child
1591 1591
 		$ticket_children = 0;
1592
-		foreach ( $line_item->children() as $child_li ) {
1593
-			$child_li_copy = EEH_Line_Item::non_empty_line_items( $child_li );
1594
-			if ( $child_li_copy !== null ) {
1595
-				$copied_li->add_child_line_item( $child_li_copy );
1596
-				if ( $child_li_copy->type() === EEM_Line_Item::type_line_item &&
1592
+		foreach ($line_item->children() as $child_li) {
1593
+			$child_li_copy = EEH_Line_Item::non_empty_line_items($child_li);
1594
+			if ($child_li_copy !== null) {
1595
+				$copied_li->add_child_line_item($child_li_copy);
1596
+				if ($child_li_copy->type() === EEM_Line_Item::type_line_item &&
1597 1597
 					$child_li_copy->OBJ_type() === 'Ticket'
1598 1598
 				) {
1599 1599
 					$ticket_children++;
@@ -1623,8 +1623,8 @@  discard block
 block discarded – undo
1623 1623
 	 * @return EE_Line_Item
1624 1624
 	 * @throws \EE_Error
1625 1625
 	 */
1626
-	public static function non_empty_line_item( EE_Line_Item $line_item ) {
1627
-		if ( $line_item->type() === EEM_Line_Item::type_line_item &&
1626
+	public static function non_empty_line_item(EE_Line_Item $line_item) {
1627
+		if ($line_item->type() === EEM_Line_Item::type_line_item &&
1628 1628
 			$line_item->OBJ_type() === 'Ticket' &&
1629 1629
 			$line_item->quantity() === 0
1630 1630
 		) {
@@ -1632,8 +1632,8 @@  discard block
 block discarded – undo
1632 1632
 		}
1633 1633
 		$new_li_fields = $line_item->model_field_array();
1634 1634
 		//don't set the total. We'll leave that up to the code that calculates it
1635
-		unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ] );
1636
-		return EE_Line_Item::new_instance( $new_li_fields );
1635
+		unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent']);
1636
+		return EE_Line_Item::new_instance($new_li_fields);
1637 1637
 	}
1638 1638
 
1639 1639
 
@@ -1645,9 +1645,9 @@  discard block
 block discarded – undo
1645 1645
 	 * @return \EE_Line_Item
1646 1646
 	 * @throws \EE_Error
1647 1647
 	 */
1648
-	public static function get_items_subtotal( EE_Line_Item $total_line_item ){
1649
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0' );
1650
-		return self::get_pre_tax_subtotal( $total_line_item );
1648
+	public static function get_items_subtotal(EE_Line_Item $total_line_item) {
1649
+		EE_Error::doing_it_wrong('EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0');
1650
+		return self::get_pre_tax_subtotal($total_line_item);
1651 1651
 	}
1652 1652
 
1653 1653
 
@@ -1658,9 +1658,9 @@  discard block
 block discarded – undo
1658 1658
 	 * @return \EE_Line_Item
1659 1659
 	 * @throws \EE_Error
1660 1660
 	 */
1661
-	public static function create_default_total_line_item( $transaction = NULL) {
1662
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0' );
1663
-		return self::create_total_line_item( $transaction );
1661
+	public static function create_default_total_line_item($transaction = NULL) {
1662
+		EE_Error::doing_it_wrong('EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0');
1663
+		return self::create_total_line_item($transaction);
1664 1664
 	}
1665 1665
 
1666 1666
 
@@ -1672,9 +1672,9 @@  discard block
 block discarded – undo
1672 1672
 	 * @return \EE_Line_Item
1673 1673
 	 * @throws \EE_Error
1674 1674
 	 */
1675
-	public static function create_default_tickets_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) {
1676
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0' );
1677
-		return self::create_pre_tax_subtotal( $total_line_item, $transaction );
1675
+	public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
1676
+		EE_Error::doing_it_wrong('EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0');
1677
+		return self::create_pre_tax_subtotal($total_line_item, $transaction);
1678 1678
 	}
1679 1679
 
1680 1680
 
@@ -1686,9 +1686,9 @@  discard block
 block discarded – undo
1686 1686
 	 * @return \EE_Line_Item
1687 1687
 	 * @throws \EE_Error
1688 1688
 	 */
1689
-	public static function create_default_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) {
1690
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0' );
1691
-		return self::create_taxes_subtotal( $total_line_item, $transaction );
1689
+	public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
1690
+		EE_Error::doing_it_wrong('EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0');
1691
+		return self::create_taxes_subtotal($total_line_item, $transaction);
1692 1692
 	}
1693 1693
 
1694 1694
 
@@ -1700,9 +1700,9 @@  discard block
 block discarded – undo
1700 1700
 	 * @return \EE_Line_Item
1701 1701
 	 * @throws \EE_Error
1702 1702
 	 */
1703
-	public static function create_default_event_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) {
1704
-		EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0' );
1705
-		return self::create_event_subtotal( $total_line_item, $transaction );
1703
+	public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) {
1704
+		EE_Error::doing_it_wrong('EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0');
1705
+		return self::create_event_subtotal($total_line_item, $transaction);
1706 1706
 	}
1707 1707
 
1708 1708
 
Please login to merge, or discard this patch.
core/helpers/EEH_File.helper.php 1 patch
Spacing   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
  * @ version		 	4.0
13 13
  *
14 14
  */
15
-require_once( EE_HELPERS . 'EEH_Base.helper.php' );
16
-require_once( EE_INTERFACES . 'EEI_Interfaces.php' );
15
+require_once(EE_HELPERS.'EEH_Base.helper.php');
16
+require_once(EE_INTERFACES.'EEI_Interfaces.php');
17 17
 /**
18 18
  *
19 19
  * Class EEH_File
@@ -52,30 +52,30 @@  discard block
 block discarded – undo
52 52
 	 * @throws EE_Error if filesystem credentials are required
53 53
 	 * @return WP_Filesystem_Base
54 54
 	 */
55
-	private static function _get_wp_filesystem( $filepath = null) {
56
-		if( apply_filters(
55
+	private static function _get_wp_filesystem($filepath = null) {
56
+		if (apply_filters(
57 57
 				'FHEE__EEH_File___get_wp_filesystem__allow_using_filesystem_direct',
58
-				$filepath && EEH_File::is_in_uploads_folder( $filepath ),
59
-				$filepath ) ) {
60
-			if( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct ) {
61
-				require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php');
58
+				$filepath && EEH_File::is_in_uploads_folder($filepath),
59
+				$filepath )) {
60
+			if ( ! EEH_File::$_wp_filesystem_direct instanceof WP_Filesystem_Direct) {
61
+				require_once(ABSPATH.'wp-admin/includes/class-wp-filesystem-base.php');
62 62
 				$method = 'direct';
63
-				$wp_filesystem_direct_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method );
63
+				$wp_filesystem_direct_file = apply_filters('filesystem_method_file', ABSPATH.'wp-admin/includes/class-wp-filesystem-'.$method.'.php', $method);
64 64
 				//check constants defined, just like in wp-admin/includes/file.php's WP_Filesystem()
65
-				if ( ! defined('FS_CHMOD_DIR') ) {
66
-					define('FS_CHMOD_DIR', ( fileperms( ABSPATH ) & 0777 | 0755 ) );
65
+				if ( ! defined('FS_CHMOD_DIR')) {
66
+					define('FS_CHMOD_DIR', (fileperms(ABSPATH) & 0777 | 0755));
67 67
 				}
68
-				if ( ! defined('FS_CHMOD_FILE') ) {
69
-					define('FS_CHMOD_FILE', ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ) );
68
+				if ( ! defined('FS_CHMOD_FILE')) {
69
+					define('FS_CHMOD_FILE', (fileperms(ABSPATH.'index.php') & 0777 | 0644));
70 70
 				}
71
-				require_once( $wp_filesystem_direct_file );
72
-				EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct( array() );
71
+				require_once($wp_filesystem_direct_file);
72
+				EEH_File::$_wp_filesystem_direct = new WP_Filesystem_Direct(array());
73 73
 			}
74 74
 			return EEH_File::$_wp_filesystem_direct;
75 75
 		}
76 76
 		global $wp_filesystem;
77 77
 		// no filesystem setup ???
78
-		if ( ! $wp_filesystem instanceof WP_Filesystem_Base ) {
78
+		if ( ! $wp_filesystem instanceof WP_Filesystem_Base) {
79 79
 			// if some eager beaver's just trying to get in there too early...
80 80
 			// let them do it, because we are one of those eager beavers! :P
81 81
 			/**
@@ -88,34 +88,34 @@  discard block
 block discarded – undo
88 88
 			 * and there may be troubles if the WP files are owned by a different user
89 89
 			 * than the server user. But both of these issues should exist in 4.4 and earlier too
90 90
 			 */
91
-			if ( FALSE && ! did_action( 'wp_loaded' )) {
91
+			if (FALSE && ! did_action('wp_loaded')) {
92 92
 				$msg = __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso');
93
-				if ( WP_DEBUG ) {
94
-					$msg .= '<br />' .  __('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
93
+				if (WP_DEBUG) {
94
+					$msg .= '<br />'.__('The WP Filesystem can not be accessed until after the "wp_loaded" hook has run, so it\'s best not to attempt access until the "admin_init" hookpoint.', 'event_espresso');
95 95
 				}
96
-				throw new EE_Error( $msg );
96
+				throw new EE_Error($msg);
97 97
 			} else {
98 98
 				// should be loaded if we are past the wp_loaded hook...
99
-				if ( ! function_exists( 'WP_Filesystem' )) {
100
-					require_once( ABSPATH . 'wp-admin/includes/file.php' );
101
-					require_once( ABSPATH . 'wp-admin/includes/template.php' );
99
+				if ( ! function_exists('WP_Filesystem')) {
100
+					require_once(ABSPATH.'wp-admin/includes/file.php');
101
+					require_once(ABSPATH.'wp-admin/includes/template.php');
102 102
 				}
103 103
 				// turn on output buffering so that we can capture the credentials form
104 104
 				ob_start();
105
-				$credentials = request_filesystem_credentials( '' );
105
+				$credentials = request_filesystem_credentials('');
106 106
 				// store credentials form for the time being
107 107
 				EEH_File::$_credentials_form = ob_get_clean();
108 108
 				// basically check for direct or previously configured access
109
-				if ( ! WP_Filesystem( $credentials ) ) {
109
+				if ( ! WP_Filesystem($credentials)) {
110 110
 					// if credentials do NOT exist
111
-					if ( $credentials === FALSE ) {
112
-						add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 );
113
-						throw new EE_Error( __('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
114
-					} elseif( is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
115
-						add_action( 'admin_notices', array( 'EEH_File', 'display_request_filesystem_credentials_form' ), 999 );
111
+					if ($credentials === FALSE) {
112
+						add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
113
+						throw new EE_Error(__('An attempt to access and/or write to a file on the server could not be completed due to a lack of sufficient credentials.', 'event_espresso'));
114
+					} elseif (is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
115
+						add_action('admin_notices', array('EEH_File', 'display_request_filesystem_credentials_form'), 999);
116 116
 						throw new EE_Error(
117 117
 								sprintf(
118
-										__( 'WP Filesystem Error: $1%s', 'event_espresso' ),
118
+										__('WP Filesystem Error: $1%s', 'event_espresso'),
119 119
 										$wp_filesystem->errors->get_error_message() ) );
120 120
 					}
121 121
 				}
@@ -128,8 +128,8 @@  discard block
 block discarded – undo
128 128
 	 * display_request_filesystem_credentials_form
129 129
 	 */
130 130
 	public static function display_request_filesystem_credentials_form() {
131
-		if ( ! empty( EEH_File::$_credentials_form )) {
132
-			echo '<div class="updated espresso-notices-attention"><p>' . EEH_File::$_credentials_form . '</p></div>';
131
+		if ( ! empty(EEH_File::$_credentials_form)) {
132
+			echo '<div class="updated espresso-notices-attention"><p>'.EEH_File::$_credentials_form.'</p></div>';
133 133
 		}
134 134
 	}
135 135
 
@@ -147,29 +147,29 @@  discard block
 block discarded – undo
147 147
 	 * @throws EE_Error if filesystem credentials are required
148 148
 	 * @return bool
149 149
 	 */
150
-	public static function verify_filepath_and_permissions( $full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '' ) {
150
+	public static function verify_filepath_and_permissions($full_file_path = '', $file_name = '', $file_ext = '', $type_of_file = '') {
151 151
 		// load WP_Filesystem and set file permissions
152
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
153
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
154
-		if ( ! $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) )) {
155
-			$file_name = ! empty( $type_of_file ) ? $file_name . ' ' . $type_of_file : $file_name;
156
-			$file_name .= ! empty( $file_ext ) ? ' file' : ' folder';
152
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
153
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
154
+		if ( ! $wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
155
+			$file_name = ! empty($type_of_file) ? $file_name.' '.$type_of_file : $file_name;
156
+			$file_name .= ! empty($file_ext) ? ' file' : ' folder';
157 157
 			$msg = sprintf(
158
-				__( 'The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso' ),
158
+				__('The requested %1$s could not be found or is not readable, possibly due to an incorrect filepath, or incorrect file permissions.%2$s', 'event_espresso'),
159 159
 				$file_name,
160 160
 				'<br />'
161 161
 			);
162
-			if ( EEH_File::exists( $full_file_path )) {
163
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, $type_of_file );
162
+			if (EEH_File::exists($full_file_path)) {
163
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, $type_of_file);
164 164
 			} else {
165 165
 				// no file permissions means the file was not found
166 166
 				$msg .= sprintf(
167
-					__( 'Please ensure the following path is correct: "%s".', 'event_espresso' ),
167
+					__('Please ensure the following path is correct: "%s".', 'event_espresso'),
168 168
 					$full_file_path
169 169
 				);
170 170
 			}
171
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
172
-				throw new EE_Error( $msg . '||' . $msg );
171
+			if (defined('WP_DEBUG') && WP_DEBUG) {
172
+				throw new EE_Error($msg.'||'.$msg);
173 173
 			}
174 174
 			return FALSE;
175 175
 		}
@@ -187,24 +187,24 @@  discard block
 block discarded – undo
187 187
 	 * @throws EE_Error if filesystem credentials are required
188 188
 	 * @return string
189 189
 	 */
190
-	private static function _permissions_error_for_unreadable_filepath( $full_file_path = '', $type_of_file = '' ){
190
+	private static function _permissions_error_for_unreadable_filepath($full_file_path = '', $type_of_file = '') {
191 191
 		// load WP_Filesystem and set file permissions
192
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
192
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
193 193
 		// check file permissions
194
-		$perms = $wp_filesystem->getchmod( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) );
195
-		if ( $perms ) {
194
+		$perms = $wp_filesystem->getchmod(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
195
+		if ($perms) {
196 196
 			// file permissions exist, but way be set incorrectly
197
-			$type_of_file = ! empty( $type_of_file ) ? $type_of_file . ' ' : '';
198
-			$type_of_file .= ! empty( $type_of_file ) ? 'file' : 'folder';
197
+			$type_of_file = ! empty($type_of_file) ? $type_of_file.' ' : '';
198
+			$type_of_file .= ! empty($type_of_file) ? 'file' : 'folder';
199 199
 			return sprintf(
200
-				__( 'File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso' ),
200
+				__('File permissions for the requested %1$s are currently set at "%2$s". The recommended permissions are 644 for files and 755 for folders.', 'event_espresso'),
201 201
 				$type_of_file,
202 202
 				$perms
203 203
 			);
204 204
 		} else {
205 205
 			// file exists but file permissions could not be read ?!?!
206 206
 			return sprintf(
207
-				__( 'Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso' ),
207
+				__('Please ensure that the server and/or PHP configuration allows the current process to access the following file: "%s".', 'event_espresso'),
208 208
 				$full_file_path
209 209
 			);
210 210
 		}
@@ -222,35 +222,35 @@  discard block
 block discarded – undo
222 222
 	 * can't write to it
223 223
 	 * @return bool false if folder isn't writable; true if it exists and is writeable,
224 224
 	 */
225
-	public static function ensure_folder_exists_and_is_writable( $folder = '' ){
226
-		if ( empty( $folder )) {
225
+	public static function ensure_folder_exists_and_is_writable($folder = '') {
226
+		if (empty($folder)) {
227 227
 			return false;
228 228
 		}
229 229
 		// remove ending DS
230
-		$folder = EEH_File::standardise_directory_separators( rtrim( $folder, '/\\' ));
231
-		$parent_folder = EEH_File::get_parent_folder( $folder );
230
+		$folder = EEH_File::standardise_directory_separators(rtrim($folder, '/\\'));
231
+		$parent_folder = EEH_File::get_parent_folder($folder);
232 232
 		// add DS to folder
233
-		$folder = EEH_File::end_with_directory_separator( $folder );
234
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $folder );
235
-		if ( ! $wp_filesystem->is_dir( EEH_File::convert_local_filepath_to_remote_filepath( $folder ) ) ) {
233
+		$folder = EEH_File::end_with_directory_separator($folder);
234
+		$wp_filesystem = EEH_File::_get_wp_filesystem($folder);
235
+		if ( ! $wp_filesystem->is_dir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
236 236
 			//ok so it doesn't exist. Does its parent? Can we write to it?
237
-			if(	! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) {
237
+			if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
238 238
 				return false;
239 239
 			}
240
-			if ( ! EEH_File::verify_is_writable( $parent_folder, 'folder' )) {
240
+			if ( ! EEH_File::verify_is_writable($parent_folder, 'folder')) {
241 241
 				return false;
242 242
 			} else {
243
-				if ( ! $wp_filesystem->mkdir( EEH_File::convert_local_filepath_to_remote_filepath(  $folder ) ) ) {
244
-					if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
245
-						$msg = sprintf( __( '"%s" could not be created.', 'event_espresso' ), $folder );
246
-						$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $folder );
247
-						throw new EE_Error( $msg );
243
+				if ( ! $wp_filesystem->mkdir(EEH_File::convert_local_filepath_to_remote_filepath($folder))) {
244
+					if (defined('WP_DEBUG') && WP_DEBUG) {
245
+						$msg = sprintf(__('"%s" could not be created.', 'event_espresso'), $folder);
246
+						$msg .= EEH_File::_permissions_error_for_unreadable_filepath($folder);
247
+						throw new EE_Error($msg);
248 248
 					}
249 249
 					return false;
250 250
 				}
251
-				EEH_File::add_index_file( $folder );
251
+				EEH_File::add_index_file($folder);
252 252
 			}
253
-		} elseif ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
253
+		} elseif ( ! EEH_File::verify_is_writable($folder, 'folder')) {
254 254
 			return false;
255 255
 		}
256 256
 		return true;
@@ -265,15 +265,15 @@  discard block
 block discarded – undo
265 265
 	 * @throws EE_Error if filesystem credentials are required
266 266
 	 * @return bool
267 267
 	 */
268
-	public static function verify_is_writable( $full_path = '', $file_or_folder = 'folder' ){
268
+	public static function verify_is_writable($full_path = '', $file_or_folder = 'folder') {
269 269
 		// load WP_Filesystem and set file permissions
270
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_path );
271
-		$full_path = EEH_File::standardise_directory_separators( $full_path );
272
-		if ( ! $wp_filesystem->is_writable( EEH_File::convert_local_filepath_to_remote_filepath( $full_path ) ) ) {
273
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
274
-				$msg = sprintf( __( 'The "%1$s" %2$s is not writable.', 'event_espresso' ), $full_path, $file_or_folder );
275
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_path );
276
-				throw new EE_Error( $msg );
270
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_path);
271
+		$full_path = EEH_File::standardise_directory_separators($full_path);
272
+		if ( ! $wp_filesystem->is_writable(EEH_File::convert_local_filepath_to_remote_filepath($full_path))) {
273
+			if (defined('WP_DEBUG') && WP_DEBUG) {
274
+				$msg = sprintf(__('The "%1$s" %2$s is not writable.', 'event_espresso'), $full_path, $file_or_folder);
275
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_path);
276
+				throw new EE_Error($msg);
277 277
 			}
278 278
 			return FALSE;
279 279
 		}
@@ -290,25 +290,25 @@  discard block
 block discarded – undo
290 290
 	 * @throws EE_Error if filesystem credentials are required
291 291
 	 * @return bool
292 292
 	 */
293
-	public static function ensure_file_exists_and_is_writable( $full_file_path = '' ) {
293
+	public static function ensure_file_exists_and_is_writable($full_file_path = '') {
294 294
 		// load WP_Filesystem and set file permissions
295
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
296
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
297
-		$parent_folder = EEH_File::get_parent_folder( $full_file_path );
298
-		if ( ! EEH_File::exists( $full_file_path )) {
299
-			if( ! EEH_File::ensure_folder_exists_and_is_writable( $parent_folder ) ) {
295
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
296
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
297
+		$parent_folder = EEH_File::get_parent_folder($full_file_path);
298
+		if ( ! EEH_File::exists($full_file_path)) {
299
+			if ( ! EEH_File::ensure_folder_exists_and_is_writable($parent_folder)) {
300 300
 				return false;
301 301
 			}
302
-			if ( ! $wp_filesystem->touch( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ) {
303
-				if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
304
-					$msg = sprintf( __( 'The "%s" file could not be created.', 'event_espresso' ), $full_file_path );
305
-					$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path );
306
-					throw new EE_Error( $msg );
302
+			if ( ! $wp_filesystem->touch(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
303
+				if (defined('WP_DEBUG') && WP_DEBUG) {
304
+					$msg = sprintf(__('The "%s" file could not be created.', 'event_espresso'), $full_file_path);
305
+					$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
306
+					throw new EE_Error($msg);
307 307
 				}
308 308
 				return false;
309 309
 			}
310 310
 		}
311
-		if ( ! EEH_File::verify_is_writable( $full_file_path, 'file' )) {
311
+		if ( ! EEH_File::verify_is_writable($full_file_path, 'file')) {
312 312
 			return false;
313 313
 		}
314 314
 		return true;
@@ -320,12 +320,12 @@  discard block
 block discarded – undo
320 320
 	 * @param string $file_or_folder_path
321 321
 	 * @return string parent folder, ENDING with a directory separator
322 322
 	 */
323
-	public static function get_parent_folder( $file_or_folder_path ) {
323
+	public static function get_parent_folder($file_or_folder_path) {
324 324
 		//find the last DS, ignoring a DS on the very end
325 325
 		//eg if given "/var/something/somewhere/", we want to get "somewhere"'s
326 326
 		//parent folder, "/var/something/"
327
-		$ds = strlen($file_or_folder_path) > 1 ? strrpos( $file_or_folder_path, DS, -2 ) : $file_or_folder_path;
328
-		return substr( $file_or_folder_path, 0, $ds + 1 );
327
+		$ds = strlen($file_or_folder_path) > 1 ? strrpos($file_or_folder_path, DS, -2) : $file_or_folder_path;
328
+		return substr($file_or_folder_path, 0, $ds + 1);
329 329
 	}
330 330
 
331 331
 	// public static function ensure_folder_exists_recursively( $folder ) {
@@ -340,12 +340,12 @@  discard block
 block discarded – undo
340 340
 	 * @throws EE_Error if filesystem credentials are required
341 341
 	 * @return string
342 342
 	 */
343
-	public static function get_file_contents( $full_file_path = '' ){
344
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
345
-		if ( EEH_File::verify_filepath_and_permissions( $full_file_path, EEH_File::get_filename_from_filepath( $full_file_path ) , EEH_File::get_file_extension( $full_file_path ))) {
343
+	public static function get_file_contents($full_file_path = '') {
344
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
345
+		if (EEH_File::verify_filepath_and_permissions($full_file_path, EEH_File::get_filename_from_filepath($full_file_path), EEH_File::get_file_extension($full_file_path))) {
346 346
 			// load WP_Filesystem and set file permissions
347
-			$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
348
-			return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) );
347
+			$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
348
+			return $wp_filesystem->get_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path));
349 349
 		}
350 350
 		return '';
351 351
 	}
@@ -360,26 +360,26 @@  discard block
 block discarded – undo
360 360
 	 * @throws EE_Error if filesystem credentials are required
361 361
 	 * @return bool
362 362
 	 */
363
-	public static function write_to_file( $full_file_path = '', $file_contents = '', $file_type = '' ){
364
-		$full_file_path = EEH_File::standardise_directory_separators( $full_file_path );
365
-		$file_type = ! empty( $file_type ) ? rtrim( $file_type, ' ' ) . ' ' : '';
366
-		$folder = EEH_File::remove_filename_from_filepath( $full_file_path );
367
-		if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
368
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
369
-				$msg = sprintf( __( 'The %1$sfile located at "%2$s" is not writable.', 'event_espresso' ), $file_type, $full_file_path );
370
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path );
371
-				throw new EE_Error( $msg );
363
+	public static function write_to_file($full_file_path = '', $file_contents = '', $file_type = '') {
364
+		$full_file_path = EEH_File::standardise_directory_separators($full_file_path);
365
+		$file_type = ! empty($file_type) ? rtrim($file_type, ' ').' ' : '';
366
+		$folder = EEH_File::remove_filename_from_filepath($full_file_path);
367
+		if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
368
+			if (defined('WP_DEBUG') && WP_DEBUG) {
369
+				$msg = sprintf(__('The %1$sfile located at "%2$s" is not writable.', 'event_espresso'), $file_type, $full_file_path);
370
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path);
371
+				throw new EE_Error($msg);
372 372
 			}
373 373
 			return FALSE;
374 374
 		}
375 375
 		// load WP_Filesystem and set file permissions
376
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
376
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
377 377
 		// write the file
378
-		if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ), $file_contents )) {
379
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
380
-				$msg = sprintf( __( 'The %1$sfile located at "%2$s" could not be written to.', 'event_espresso' ), $file_type, $full_file_path );
381
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_file_path, 'f' );
382
-				throw new EE_Error( $msg );
378
+		if ( ! $wp_filesystem->put_contents(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path), $file_contents)) {
379
+			if (defined('WP_DEBUG') && WP_DEBUG) {
380
+				$msg = sprintf(__('The %1$sfile located at "%2$s" could not be written to.', 'event_espresso'), $file_type, $full_file_path);
381
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_file_path, 'f');
382
+				throw new EE_Error($msg);
383 383
 			}
384 384
 			return FALSE;
385 385
 		}
@@ -395,9 +395,9 @@  discard block
 block discarded – undo
395 395
 	 * @throws EE_Error if filesystem credentials are required
396 396
 	 * @return boolean
397 397
 	 */
398
-	public static function delete( $filepath, $recursive = false, $type = false ) {
398
+	public static function delete($filepath, $recursive = false, $type = false) {
399 399
 		$wp_filesystem = EEH_File::_get_wp_filesystem();
400
-		return $wp_filesystem->delete( $filepath, $recursive, $type ) ? TRUE : FALSE;
400
+		return $wp_filesystem->delete($filepath, $recursive, $type) ? TRUE : FALSE;
401 401
 	}
402 402
 
403 403
 
@@ -409,9 +409,9 @@  discard block
 block discarded – undo
409 409
 	 * @throws EE_Error if filesystem credentials are required
410 410
 	 * @return bool
411 411
 	 */
412
-	public static function exists( $full_file_path = '' ) {
413
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
414
-		return $wp_filesystem->exists( EEH_File::convert_local_filepath_to_remote_filepath( $full_file_path ) ) ? TRUE : FALSE;
412
+	public static function exists($full_file_path = '') {
413
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
414
+		return $wp_filesystem->exists(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path)) ? TRUE : FALSE;
415 415
 	}
416 416
 
417 417
 
@@ -424,9 +424,9 @@  discard block
 block discarded – undo
424 424
 	 * @throws EE_Error if filesystem credentials are required
425 425
 	 * @return bool
426 426
 	 */
427
-	public static function is_readable( $full_file_path = '' ) {
428
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $full_file_path );
429
-		if( $wp_filesystem->is_readable( EEH_File::convert_local_filepath_to_remote_filepath(  $full_file_path ) ) ) {
427
+	public static function is_readable($full_file_path = '') {
428
+		$wp_filesystem = EEH_File::_get_wp_filesystem($full_file_path);
429
+		if ($wp_filesystem->is_readable(EEH_File::convert_local_filepath_to_remote_filepath($full_file_path))) {
430 430
 			return true;
431 431
 		} else {
432 432
 			return false;
@@ -442,8 +442,8 @@  discard block
 block discarded – undo
442 442
 	 * @param string $full_file_path
443 443
 	 * @return string
444 444
 	 */
445
-	public static function remove_filename_from_filepath( $full_file_path = '' ) {
446
-		return pathinfo( $full_file_path, PATHINFO_DIRNAME );
445
+	public static function remove_filename_from_filepath($full_file_path = '') {
446
+		return pathinfo($full_file_path, PATHINFO_DIRNAME);
447 447
 	}
448 448
 
449 449
 
@@ -453,8 +453,8 @@  discard block
 block discarded – undo
453 453
 	 * @param string $full_file_path
454 454
 	 * @return string
455 455
 	 */
456
-	public static function get_filename_from_filepath( $full_file_path = '' ) {
457
-		return pathinfo( $full_file_path, PATHINFO_BASENAME );
456
+	public static function get_filename_from_filepath($full_file_path = '') {
457
+		return pathinfo($full_file_path, PATHINFO_BASENAME);
458 458
 	}
459 459
 
460 460
 
@@ -464,8 +464,8 @@  discard block
 block discarded – undo
464 464
 	 * @param string $full_file_path
465 465
 	 * @return string
466 466
 	 */
467
-	public static function get_file_extension( $full_file_path = '' ) {
468
-		return pathinfo( $full_file_path, PATHINFO_EXTENSION );
467
+	public static function get_file_extension($full_file_path = '') {
468
+		return pathinfo($full_file_path, PATHINFO_EXTENSION);
469 469
 	}
470 470
 
471 471
 
@@ -476,10 +476,10 @@  discard block
 block discarded – undo
476 476
 	 * @throws EE_Error if filesystem credentials are required
477 477
 	 * @return bool
478 478
 	 */
479
-	public static function add_htaccess_deny_from_all( $folder = '' ) {
480
-		$folder = EEH_File::standardise_and_end_with_directory_separator( $folder );
481
-		if ( ! EEH_File::exists( $folder . '.htaccess' ) ) {
482
-			if ( ! EEH_File::write_to_file( $folder . '.htaccess', 'deny from all', '.htaccess' )) {
479
+	public static function add_htaccess_deny_from_all($folder = '') {
480
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
481
+		if ( ! EEH_File::exists($folder.'.htaccess')) {
482
+			if ( ! EEH_File::write_to_file($folder.'.htaccess', 'deny from all', '.htaccess')) {
483 483
 				return FALSE;
484 484
 			}
485 485
 		}
@@ -493,10 +493,10 @@  discard block
 block discarded – undo
493 493
 	 * @throws EE_Error if filesystem credentials are required
494 494
 	 * @return boolean
495 495
 	 */
496
-	public static function add_index_file( $folder ) {
497
-		$folder = EEH_File::standardise_and_end_with_directory_separator( $folder );
498
-		if ( ! EEH_File::exists( $folder . 'index.php' ) ) {
499
-			if ( ! EEH_File::write_to_file( $folder . 'index.php', 'You are not permitted to read from this folder', '.php' )) {
496
+	public static function add_index_file($folder) {
497
+		$folder = EEH_File::standardise_and_end_with_directory_separator($folder);
498
+		if ( ! EEH_File::exists($folder.'index.php')) {
499
+			if ( ! EEH_File::write_to_file($folder.'index.php', 'You are not permitted to read from this folder', '.php')) {
500 500
 				return false;
501 501
 			}
502 502
 		}
@@ -511,11 +511,11 @@  discard block
 block discarded – undo
511 511
 	 * @param string $file_path
512 512
 	 * @return string
513 513
 	 */
514
-	public static function get_classname_from_filepath_with_standard_filename( $file_path ){
514
+	public static function get_classname_from_filepath_with_standard_filename($file_path) {
515 515
 		//extract file from path
516
-		$filename = basename( $file_path );
516
+		$filename = basename($file_path);
517 517
 		//now remove the first period and everything after
518
-		$pos_of_first_period = strpos( $filename,'.' );
518
+		$pos_of_first_period = strpos($filename, '.');
519 519
 		return substr($filename, 0, $pos_of_first_period);
520 520
 	}
521 521
 
@@ -527,8 +527,8 @@  discard block
 block discarded – undo
527 527
 	 * @param string $file_path
528 528
 	 * @return string
529 529
 	 */
530
-	public static function standardise_directory_separators( $file_path ){
531
-		return str_replace( array( '\\', '/' ), DS, $file_path );
530
+	public static function standardise_directory_separators($file_path) {
531
+		return str_replace(array('\\', '/'), DS, $file_path);
532 532
 	}
533 533
 
534 534
 
@@ -539,8 +539,8 @@  discard block
 block discarded – undo
539 539
 	 * @param string $file_path
540 540
 	 * @return string
541 541
 	 */
542
-	public static function end_with_directory_separator( $file_path ){
543
-		return rtrim( $file_path, '/\\' ) . DS;
542
+	public static function end_with_directory_separator($file_path) {
543
+		return rtrim($file_path, '/\\').DS;
544 544
 	}
545 545
 
546 546
 
@@ -550,8 +550,8 @@  discard block
 block discarded – undo
550 550
 	 * @param $file_path
551 551
 	 * @return string
552 552
 	 */
553
-	public static function standardise_and_end_with_directory_separator( $file_path ){
554
-		return self::end_with_directory_separator( self::standardise_directory_separators( $file_path ));
553
+	public static function standardise_and_end_with_directory_separator($file_path) {
554
+		return self::end_with_directory_separator(self::standardise_directory_separators($file_path));
555 555
 	}
556 556
 
557 557
 
@@ -568,21 +568,21 @@  discard block
 block discarded – undo
568 568
 	 *		if $index_numerically == FALSE (Default) keys are what the class names SHOULD be;
569 569
 	 *		 and values are their filepaths
570 570
 	 */
571
-	public static function get_contents_of_folders( $folder_paths = array(), $index_numerically = FALSE ){
571
+	public static function get_contents_of_folders($folder_paths = array(), $index_numerically = FALSE) {
572 572
 		$class_to_folder_path = array();
573
-		foreach( $folder_paths as $folder_path ){
574
-			$folder_path = self::standardise_and_end_with_directory_separator( $folder_path );
573
+		foreach ($folder_paths as $folder_path) {
574
+			$folder_path = self::standardise_and_end_with_directory_separator($folder_path);
575 575
 			// load WP_Filesystem and set file permissions
576
-			$files_in_folder = glob( $folder_path . '*' );
576
+			$files_in_folder = glob($folder_path.'*');
577 577
 			$class_to_folder_path = array();
578
-			if ( $files_in_folder ) {
579
-				foreach( $files_in_folder as $file_path ){
578
+			if ($files_in_folder) {
579
+				foreach ($files_in_folder as $file_path) {
580 580
 					//only add files, not folders
581
-					if ( ! is_dir( $file_path )) {
582
-						if ( $index_numerically ) {
581
+					if ( ! is_dir($file_path)) {
582
+						if ($index_numerically) {
583 583
 							$class_to_folder_path[] = $file_path;
584 584
 						} else {
585
-							$classname = self::get_classname_from_filepath_with_standard_filename( $file_path );
585
+							$classname = self::get_classname_from_filepath_with_standard_filename($file_path);
586 586
 							$class_to_folder_path[$classname] = $file_path;
587 587
 						}
588 588
 					}
@@ -602,39 +602,39 @@  discard block
 block discarded – undo
602 602
 	 * @throws EE_Error if filesystem credentials are required
603 603
 	 * @return boolean success
604 604
 	 */
605
-	public static function copy( $source_file, $destination_file, $overwrite = FALSE ){
606
-		$full_source_path = EEH_File::standardise_directory_separators( $source_file );
607
-		if( ! EEH_File::exists( $full_source_path ) ){
608
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
609
-				$msg = sprintf( __( 'The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso' ), $full_source_path );
610
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path );
611
-				throw new EE_Error( $msg );
605
+	public static function copy($source_file, $destination_file, $overwrite = FALSE) {
606
+		$full_source_path = EEH_File::standardise_directory_separators($source_file);
607
+		if ( ! EEH_File::exists($full_source_path)) {
608
+			if (defined('WP_DEBUG') && WP_DEBUG) {
609
+				$msg = sprintf(__('The file located at "%2$s" is not readable or doesn\'t exist.', 'event_espresso'), $full_source_path);
610
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path);
611
+				throw new EE_Error($msg);
612 612
 			}
613 613
 			return FALSE;
614 614
 		}
615 615
 
616
-		$full_dest_path = EEH_File::standardise_directory_separators( $destination_file );
617
-		$folder = EEH_File::remove_filename_from_filepath( $full_dest_path );
618
-		if ( ! EEH_File::verify_is_writable( $folder, 'folder' )) {
619
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
620
-				$msg = sprintf( __( 'The file located at "%2$s" is not writable.', 'event_espresso' ), $full_dest_path );
621
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_dest_path );
622
-				throw new EE_Error( $msg );
616
+		$full_dest_path = EEH_File::standardise_directory_separators($destination_file);
617
+		$folder = EEH_File::remove_filename_from_filepath($full_dest_path);
618
+		if ( ! EEH_File::verify_is_writable($folder, 'folder')) {
619
+			if (defined('WP_DEBUG') && WP_DEBUG) {
620
+				$msg = sprintf(__('The file located at "%2$s" is not writable.', 'event_espresso'), $full_dest_path);
621
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_dest_path);
622
+				throw new EE_Error($msg);
623 623
 			}
624 624
 			return FALSE;
625 625
 		}
626 626
 
627 627
 		// load WP_Filesystem and set file permissions
628
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $destination_file );
628
+		$wp_filesystem = EEH_File::_get_wp_filesystem($destination_file);
629 629
 		// write the file
630 630
 		if ( ! $wp_filesystem->copy(
631
-						EEH_File::convert_local_filepath_to_remote_filepath( $full_source_path ),
632
-						EEH_File::convert_local_filepath_to_remote_filepath( $full_dest_path ),
631
+						EEH_File::convert_local_filepath_to_remote_filepath($full_source_path),
632
+						EEH_File::convert_local_filepath_to_remote_filepath($full_dest_path),
633 633
 						$overwrite )) {
634
-			if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
635
-				$msg = sprintf( __( 'Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso' ), $full_source_path );
636
-				$msg .= EEH_File::_permissions_error_for_unreadable_filepath( $full_source_path, 'f' );
637
-				throw new EE_Error( $msg );
634
+			if (defined('WP_DEBUG') && WP_DEBUG) {
635
+				$msg = sprintf(__('Attempted writing to file %1$s, but could not, probably because of permissions issues', 'event_espresso'), $full_source_path);
636
+				$msg .= EEH_File::_permissions_error_for_unreadable_filepath($full_source_path, 'f');
637
+				throw new EE_Error($msg);
638 638
 			}
639 639
 			return FALSE;
640 640
 		}
@@ -646,9 +646,9 @@  discard block
 block discarded – undo
646 646
 	 * @param string $filepath
647 647
 	 * @return boolean
648 648
 	 */
649
-	public static function is_in_uploads_folder( $filepath ) {
649
+	public static function is_in_uploads_folder($filepath) {
650 650
 		$uploads = wp_upload_dir();
651
-		return strpos( $filepath, $uploads[ 'basedir' ] ) === 0 ? true : false;
651
+		return strpos($filepath, $uploads['basedir']) === 0 ? true : false;
652 652
 	}
653 653
 
654 654
 	/**
@@ -663,9 +663,9 @@  discard block
 block discarded – undo
663 663
 	 * @return string the remote filepath (eg the filepath the filesystem method, eg
664 664
 	 * ftp or ssh, will use to access the folder
665 665
 	 */
666
-	public static function convert_local_filepath_to_remote_filepath( $local_filepath ) {
667
-		$wp_filesystem = EEH_File::_get_wp_filesystem( $local_filepath );
668
-		return str_replace( WP_CONTENT_DIR . DS, $wp_filesystem->wp_content_dir(), $local_filepath );
666
+	public static function convert_local_filepath_to_remote_filepath($local_filepath) {
667
+		$wp_filesystem = EEH_File::_get_wp_filesystem($local_filepath);
668
+		return str_replace(WP_CONTENT_DIR.DS, $wp_filesystem->wp_content_dir(), $local_filepath);
669 669
 	}
670 670
 }
671 671
 // End of file EEH_File.helper.php
Please login to merge, or discard this patch.