Code Duplication    Length = 20-22 lines in 2 locations

core/Container/Container.php 1 location

@@ 134-155 (lines=22) @@
131
	 * @param string $name Human-readable name of the container
132
	 * @return object $container
133
	 **/
134
	public static function factory( $type, $name ) {
135
		// backward compatibility: post_meta container used to be called custom_fields
136
		if ( $type === 'custom_fields' ) {
137
			$type = 'post_meta';
138
		}
139
140
		$type = str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $type ) ) );
141
142
		$class = __NAMESPACE__ . '\\' . $type . '_Container';
143
144
		if ( ! class_exists( $class ) ) {
145
			Incorrect_Syntax_Exception::raise( 'Unknown container "' . $type . '".' );
146
			$class = __NAMESPACE__ . '\\Broken_Container';
147
		}
148
149
		$container = new $class( $name );
150
		$container->type = $type;
151
152
		self::$init_containers[] = $container;
153
154
		return $container;
155
	}
156
157
	/**
158
	 * An alias of factory().

core/Field/Field.php 1 location

@@ 165-184 (lines=20) @@
162
	 * @param string $label (optional) Automatically generated from $name if not present
163
	 * @return object $field
164
	 **/
165
	public static function factory( $type, $name, $label = null ) {
166
		// backward compatibility: `file` type used to be called `attachment`
167
		if ( $type === 'attachment' ) {
168
			$type = 'file';
169
		}
170
171
		$type = str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $type ) ) );
172
173
		$class = __NAMESPACE__ . '\\' . $type . '_Field';
174
175
		if ( ! class_exists( $class ) ) {
176
			Incorrect_Syntax_Exception::raise( 'Unknown field "' . $type . '".' );
177
			$class = __NAMESPACE__ . '\\Broken_Field';
178
		}
179
180
		$field = new $class( $name, $label );
181
		$field->type = $type;
182
183
		return $field;
184
	}
185
186
	/**
187
	 * An alias of factory().