Code Duplication    Length = 19-25 lines in 2 locations

model/base.php 2 locations

@@ 228-252 (lines=25) @@
225
		return $model;
226
	}
227
228
	public static function find_all_by_where( $where ) {
229
		global $wpdb;
230
		
231
		$class = get_called_class();
232
		$models = array();
233
		
234
		$rows = $wpdb->get_results(
235
			'SELECT * FROM ' . static::table_name() . ' WHERE ' . $where
236
		);
237
		
238
		if ( ! $rows ) {
239
			return array();
240
		}
241
		
242
		foreach ( $rows as $row ) {
243
			$model = new $class();
244
			$model->flag_as_not_new();
245
			foreach ( $row as $property => $value ) {
246
				$model->$property = static::unserialize_property($value);
247
			}
248
			$models[] = $model;
249
		}
250
		
251
		return $models;
252
	}
253
	
254
	public static function find_one_by_where( $where ) {
255
		global $wpdb;
@@ 281-299 (lines=19) @@
278
	 * @param  string $sql_suffix optional SQL, appended after FROM clause
279
	 * @return array list of model objects
280
	 */
281
	public static function all( $sql_suffix = '' ) {
282
		global $wpdb;
283
		
284
		$class = get_called_class();
285
		$models = array();
286
		
287
		$rows = $wpdb->get_results( 'SELECT * FROM ' . static::table_name() . ' ' . $sql_suffix );
288
289
		foreach ( $rows as $row ) {
290
			$model = new $class();
291
			$model->flag_as_not_new();
292
			foreach ( $row as $property => $value ) {
293
				$model->$property = static::unserialize_property($value);
294
			}
295
			$models[] = $model;
296
		}
297
		
298
		return $models;
299
	}
300
	
301
	/**
302
	 * True if not yet saved to database. Else false.