Completed
Pull Request — develop (#1350)
by Naveen
03:09
created

Parser_Factory::get_parser()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Wordlift\Videoobject\Parser;
4
/**
5
 * @since 3.31.0
6
 * @author Naveen Muthusamy <[email protected]>
7
 */
8
class Parser_Factory {
9
10
	const BLOCK_EDITOR = 'block-editor';
11
12
	const CLASSIC_EDITOR = 'classic-editor';
13
14
	/**
15
	 * @param $parser_config
16
	 *
17
	 * @return Parser
18
	 */
19
	public static function get_parser( $parser_config ) {
20
		if ( self::BLOCK_EDITOR === $parser_config ) {
21
			return new Block_Editor_Parser();
22
		} else if ( self::CLASSIC_EDITOR === $parser_config ) {
23
			return new Classic_Editor_Parser();
24
		}
25
26
	}
27
28
	public static function get_parser_from_content( $post_content ) {
29
		if ( function_exists( 'has_blocks' )
30
		     && function_exists( 'parse_blocks' ) && has_blocks( $post_content ) ) {
31
			return self::get_parser( self::BLOCK_EDITOR );
32
		} else {
33
			return self::get_parser( self::CLASSIC_EDITOR );
34
		}
35
	}
36
37
}