Code Duplication    Length = 21-23 lines in 2 locations

core/Container/Container.php 1 location

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

core/Field/Field.php 1 location

@@ 165-185 (lines=21) @@
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
		$field->add_template( $field->get_type(), array( $field, 'template' ) );
183
184
		return $field;
185
	}
186
187
	/**
188
	 * An alias of factory().