Code Duplication    Length = 18-18 lines in 4 locations

core/libraries/rest_api/calculations/Datetime.php 1 location

@@ 35-52 (lines=18) @@
32
	 * @return int
33
	 * @throws \EE_Error
34
	 */
35
	public static function spaces_remaining_considering_tickets( $wpdb_row, $request, $controller ){
36
		if( is_array( $wpdb_row ) && isset( $wpdb_row[ 'Datetime.DTT_ID' ] ) ) {
37
			$dtt_obj = \EEM_Datetime::instance()->get_one_by_ID( $wpdb_row[ 'Datetime.DTT_ID' ] );
38
		} else {
39
			$dtt_obj = null;
40
		}
41
		if( $dtt_obj instanceof \EE_Datetime ) {
42
			return $dtt_obj->spaces_remaining( true );
43
		} else {
44
			throw new \EE_Error(
45
				sprintf(
46
					__( 'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found', 'event_espresso' ),
47
					$wpdb_row[ 'Datetime.DTT_ID' ],
48
					print_r( $wpdb_row, true )
49
				)
50
			);
51
		}
52
	}
53
54
55

core/libraries/rest_api/calculations/Event.php 3 locations

@@ 35-52 (lines=18) @@
32
	 * @return int
33
	 * @throws \EE_Error
34
	 */
35
	public static function optimum_sales_at_start( $wpdb_row, $request, $controller ){
36
		if( is_array( $wpdb_row ) && isset( $wpdb_row[ 'Event_CPT.ID' ] ) ) {
37
			$event_obj = \EEM_Event::instance()->get_one_by_ID( $wpdb_row[ 'Event_CPT.ID' ] );
38
		} else {
39
			$event_obj = null;
40
		}
41
		if( $event_obj instanceof \EE_Event ) {
42
			return $event_obj->total_available_spaces( true );
43
		} else {
44
			throw new \EE_Error(
45
				sprintf(
46
					__( 'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found', 'event_espresso' ),
47
					$wpdb_row[ 'Event_CPT.ID' ],
48
					print_r( $wpdb_row, true )
49
				)
50
			);
51
		}
52
	}
53
54
55
@@ 67-84 (lines=18) @@
64
	 * @return int
65
	 * @throws \EE_Error
66
	 */
67
	public static function optimum_sales_now( $wpdb_row, $request, $controller ){
68
		if( is_array( $wpdb_row ) && isset( $wpdb_row[ 'Event_CPT.ID' ] ) ) {
69
			$event_obj = \EEM_Event::instance()->get_one_by_ID( $wpdb_row[ 'Event_CPT.ID' ] );
70
		} else {
71
			$event_obj = null;
72
		}
73
		if( $event_obj instanceof \EE_Event ) {
74
			return $event_obj->total_available_spaces( false );
75
		} else {
76
			throw new \EE_Error(
77
				sprintf(
78
					__( 'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found', 'event_espresso' ),
79
					$wpdb_row[ 'Event_CPT.ID' ],
80
					print_r( $wpdb_row, true )
81
				)
82
			);
83
		}
84
	}
85
86
87
@@ 98-115 (lines=18) @@
95
	 * @return int
96
	 * @throws \EE_Error
97
	 */
98
	public static function spaces_remaining( $wpdb_row, $request, $controller ){
99
		if( is_array( $wpdb_row ) && isset( $wpdb_row[ 'Event_CPT.ID' ] ) ) {
100
			$event_obj = \EEM_Event::instance()->get_one_by_ID( $wpdb_row[ 'Event_CPT.ID' ] );
101
		} else {
102
			$event_obj = null;
103
		}
104
		if( $event_obj instanceof \EE_Event ) {
105
			return $event_obj->spaces_remaining_for_sale();
106
		} else {
107
			throw new \EE_Error(
108
				sprintf(
109
					__( 'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found', 'event_espresso' ),
110
					$wpdb_row[ 'Event_CPT.ID' ],
111
					print_r( $wpdb_row, true )
112
				)
113
			);
114
		}
115
	}
116
117
118