Code Duplication    Length = 35-35 lines in 2 locations

model/versioning/Versioned.php 1 location

@@ 2520-2554 (lines=35) @@
2517
	 * @param $fieldName string
2518
	 * @return string | null - will return null on a missing value
2519
	 */
2520
	public function relField($fieldName) {
2521
		$component = $this;
2522
2523
		// We're dealing with relations here so we traverse the dot syntax
2524
		if(strpos($fieldName, '.') !== false) {
2525
			$relations = explode('.', $fieldName);
2526
			$fieldName = array_pop($relations);
2527
			foreach($relations as $relation) {
2528
				// Inspect $component for element $relation
2529
				if($component->hasMethod($relation)) {
2530
					// Check nested method
2531
						$component = $component->$relation();
2532
				} elseif($component instanceof SS_List) {
2533
					// Select adjacent relation from DataList
2534
						$component = $component->relation($relation);
2535
				} elseif($component instanceof DataObject
2536
					&& ($dbObject = $component->dbObject($relation))
2537
				) {
2538
					// Select db object
2539
					$component = $dbObject;
2540
				} else {
2541
					user_error("$relation is not a relation/field on ".get_class($component), E_USER_ERROR);
2542
				}
2543
			}
2544
		}
2545
2546
		// Bail if the component is null
2547
		if(!$component) {
2548
			return null;
2549
		}
2550
		if ($component->hasMethod($fieldName)) {
2551
			return $component->$fieldName();
2552
		}
2553
		return $component->$fieldName;
2554
	}
2555
}
2556

model/DataObject.php 1 location

@@ 3073-3107 (lines=35) @@
3070
	 * @param $fieldName string
3071
	 * @return string | null - will return null on a missing value
3072
	 */
3073
	public function relField($fieldName) {
3074
		$component = $this;
3075
3076
		// We're dealing with relations here so we traverse the dot syntax
3077
		if(strpos($fieldName, '.') !== false) {
3078
			$relations = explode('.', $fieldName);
3079
			$fieldName = array_pop($relations);
3080
			foreach($relations as $relation) {
3081
				// Inspect $component for element $relation
3082
				if($component->hasMethod($relation)) {
3083
					// Check nested method
3084
					$component = $component->$relation();
3085
				} elseif($component instanceof SS_List) {
3086
					// Select adjacent relation from DataList
3087
					$component = $component->relation($relation);
3088
				} elseif($component instanceof DataObject
3089
					&& ($dbObject = $component->dbObject($relation))
3090
				) {
3091
					// Select db object
3092
					$component = $dbObject;
3093
				} else {
3094
					user_error("$relation is not a relation/field on ".get_class($component), E_USER_ERROR);
3095
				}
3096
			}
3097
		}
3098
3099
		// Bail if the component is null
3100
		if(!$component) {
3101
			return null;
3102
		}
3103
		if($component->hasMethod($fieldName)) {
3104
			return $component->$fieldName();
3105
		}
3106
		return $component->$fieldName;
3107
	}
3108
3109
	/**
3110
	 * Temporary hack to return an association name, based on class, to get around the mangle