Code Duplication    Length = 20-22 lines in 2 locations

core/Container/Container.php 1 location

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

core/Field/Field.php 1 location

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