Completed
Push — master ( 0f3bb4...97a511 )
by mw
02:24
created

CharacterExaminer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 87.5%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B contains() 0 14 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_CHINESE', 'ONOI_TESA_CHAR_EXAMINER_CHINESE' );
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 3
	public static function contains( $type, $text ) {
36
37 3
		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 2
		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 1
		if ( $type === ONOI_TESA_CHAR_EXAMINER_CHINESE ) {
46 1
			return preg_match('/[\x{4e00}-\x{9fa5}]/u', $text ) > 0;
47
		}
48
	}
49
50
}
51