Completed
Push — master ( 361a80...57c765 )
by Atanas
07:10
created

Delimiter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 42
rs 10
wmc 3
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A quote() 0 3 1
A unquote() 0 3 1
A split() 0 3 1
1
<?php
2
3
namespace Carbon_Fields\Helper;
4
5
/**
6
 * Delimiter functions
7
 */
8
class Delimiter {
9
	/**
10
	 * Character to escape delimiters with
11
	 * We're using an uncommon escape character as to not clash with stripslashes
12
	 *
13
	 * @var string
14
	 */
15
	protected static $escape_character = '!';
16
17
	/**
18
	 * Quote a delimiter in the passed value
19
	 *
20
	 * @param  string $value
21
	 * @param  string $delimiter
22
	 * @return string
23
	 */
24
	public static function quote( $value, $delimiter ) {
25
		return str_replace( $delimiter, static::$escape_character . $delimiter, $value );
26
	}
27
28
	/**
29
	 * Unquote a delimiter in the passed value
30
	 *
31
	 * @param  string $value
32
	 * @param  string $delimiter
33
	 * @return string
34
	 */
35
	public static function unquote( $value, $delimiter ) {
36
		return str_replace( static::$escape_character . $delimiter, $delimiter, $value );
37
	}
38
39
	/**
40
	 * Split the passed value by a delimiter
41
	 *
42
	 * @param  string $value
43
	 * @param  string $delimiter
44
	 * @return array
45
	 */
46
	public static function split( $value, $delimiter ) {
47
		return preg_split( '~(?<!' . preg_quote( static::$escape_character, '~' ) . ')' . preg_quote( $delimiter, '~' ) . '~', $value );
48
	}
49
}
50