Automattic\WooCommerce\Blueprint

ClassExtractor::get_codepublicWC 1.0

Generates the processed PHP code with applied replacements and prefixes.

Method of the class: ClassExtractor{}

No Hooks.

Returns

String. The modified PHP code.

Usage

$ClassExtractor = new ClassExtractor();
$ClassExtractor->get_code();

ClassExtractor::get_code() code WC 9.9.5

public function get_code() {
	// Security check: Check if we can replace this with a more secure function.
	$file_content = file_get_contents( $this->file_path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents

	$file_content = preg_replace( '/<\?php\s*/', '', $file_content );

	if ( preg_match( '/declare\s*\(\s*strict_types\s*=\s*1\s*\)\s*;/', $file_content ) ) {
		$this->has_strict_types_declaration = true;
		$file_content                       = preg_replace( '/declare\s*\(\s*strict_types\s*=\s*1\s*\)\s*;/', '', $file_content );
	}

	$file_content = preg_replace( '/\/\*.*?\*\/|\/\/.*?(?=\r?\n)/s', '', $file_content );

	foreach ( $this->class_variable_replacements as $variable => $value ) {
		$file_content = $this->apply_class_variable_replacement( $file_content, $variable, $value );
	}

	foreach ( $this->method_variable_replacements as $replacement ) {
		$file_content = $this->apply_variable_replacement(
			$file_content,
			$replacement['method'],
			$replacement['variable'],
			$replacement['value']
		);
	}

	return $this->prefix . trim( $file_content );
}