Completed
Push — master ( 97a511...3b1ecb )
by mw
02:09
created

CharacterExaminer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 0
cbo 0
dl 0
loc 33
ccs 8
cts 8
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B contains() 0 20 6
1
<?php
2
3
namespace Onoi\Tesa;
4
5
/**
6
 * @since 0.1
7
 *
8
 * @{
9
 */
10
// @codeCoverageIgnoreStart
11
define( 'ONOI_TESA_CHAR_EXAMINER_HIRAGANA_KATAKANA', 'ONOI_TESA_CHAR_EXAMINER_HIRAGANA_KATAKANA' );
12
define( 'ONOI_TESA_CHAR_EXAMINER_HANGUL', 'ONOI_TESA_CHAR_EXAMINER_HANGUL' );
13
define( 'ONOI_TESA_CHAR_EXAMINER_CJK_UNIFIED', 'ONOI_TESA_CHAR_EXAMINER_CJK_UNIFIED' );
14
// @codeCoverageIgnoreEnd
15
/**@}
16
 */
17
18
/**
19
 * @license GNU GPL v2+
20
 * @since 0.1
21
 *
22
 * @author mwjames
23
 */
24
class CharacterExaminer {
25
26
	/**
27
	 * @see http://jrgraphix.net/research/unicode_blocks.php
28
	 * @since 0.1
29
	 *
30
	 * @param string $type
31
	 * @param string $text
32
	 *
33
	 * @return boolean
34
	 */
35 4
	public static function contains( $type, $text ) {
36
37 4
		if ( $type === ONOI_TESA_CHAR_EXAMINER_HIRAGANA_KATAKANA ) {
38 1
			return preg_match('/[\x{3040}-\x{309F}]/u', $text ) > 0 || preg_match('/[\x{30A0}-\x{30FF}]/u', $text ) > 0; // isHiragana || isKatakana
39
		}
40
41 3
		if ( $type === ONOI_TESA_CHAR_EXAMINER_HANGUL ) {
42 1
			return preg_match('/[\x{3130}-\x{318F}]/u', $text ) > 0 || preg_match('/[\x{AC00}-\x{D7AF}]/u', $text ) > 0;
43
		}
44
45
		// @see https://en.wikipedia.org/wiki/CJK_Unified_Ideographs
46
		// Chinese, Japanese and Korean (CJK) scripts share common characters
47
		// known as CJK characters
48
49 2
		if ( $type === ONOI_TESA_CHAR_EXAMINER_CJK_UNIFIED ) {
50 1
			return preg_match('/[\x{4e00}-\x{9fa5}]/u', $text ) > 0;
51
		}
52
53 1
		return false;
54
	}
55
56
}
57