Conditions | 9 |
Paths | 9 |
Total Lines | 32 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 9 |
Changes | 0 |
1 | <?php |
||
29 | 5 | public static function contains( $type, $text ) { |
|
30 | |||
31 | 5 | if ( $type === self::CYRILLIC ) { |
|
32 | 1 | return preg_match('/\p{Cyrillic}/u', $text ) > 0; |
|
33 | } |
||
34 | |||
35 | 5 | if ( $type === self::LATIN ) { |
|
36 | 3 | return preg_match('/\p{Latin}/u', $text ) > 0; |
|
37 | } |
||
38 | |||
39 | 4 | if ( $type === self::HAN ) { |
|
40 | 3 | return preg_match('/\p{Han}/u', $text ) > 0; |
|
41 | } |
||
42 | |||
43 | 4 | if ( $type === self::HIRAGANA_KATAKANA ) { |
|
44 | 1 | return preg_match('/[\x{3040}-\x{309F}]/u', $text ) > 0 || preg_match('/[\x{30A0}-\x{30FF}]/u', $text ) > 0; // isHiragana || isKatakana |
|
45 | } |
||
46 | |||
47 | 3 | if ( $type === self::HANGUL ) { |
|
48 | 1 | return preg_match('/[\x{3130}-\x{318F}]/u', $text ) > 0 || preg_match('/[\x{AC00}-\x{D7AF}]/u', $text ) > 0; |
|
49 | } |
||
50 | |||
51 | // @see https://en.wikipedia.org/wiki/CJK_Unified_Ideographs |
||
52 | // Chinese, Japanese and Korean (CJK) scripts share common characters |
||
53 | // known as CJK characters |
||
54 | |||
55 | 2 | if ( $type === self::CJK_UNIFIED ) { |
|
56 | 1 | return preg_match('/[\x{4e00}-\x{9fa5}]/u', $text ) > 0; |
|
57 | } |
||
58 | |||
59 | 1 | return false; |
|
60 | } |
||
61 | |||
63 |