LaravelEmoji::covertEmojiToName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 7 and the first side effect is on line 5.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
namespace BahriCanli\LaravelEmoji;
3
4
use App\Http\Controllers\Controller;
5
require_once 'Emoji.php';
6
7
class LaravelEmoji extends Controller {
8
9
	static public function covertEmojiToName($data) {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
10
		$data = emoji_docomo_to_unified($data);   # DoCoMo devices
11
	    $data = emoji_kddi_to_unified($data);     # KDDI & Au devices
12
    	$data = emoji_softbank_to_unified($data); # Softbank & (iPhone) Apple devices
13
	    $data = emoji_google_to_unified($data);   # Google Android devices
14
		$data = emoji_unified_to_name($data);
15
		$data = emoji_unified_to_key($data);
16
		return $data;
17
	}
18
19
	static public function covertNameToEmoji($data) {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
20
		$data = emoji_name_to_unified($data);
21
		return $data;
22
	}
23
24
	static public function covertNameToEmpty($data) {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
25
		$data = emoji_name_to_empty($data);
26
		return $data;
27
	}
28
29
	static public function covertUnifiedToEmpty($data) {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
30
		$data = emoji_unified_to_empty($data);
31
		return $data;
32
	}
33
34
	static public function covertHtmlToEmoji($data) {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
35
		$data = emoji_html_to_unified($data);
36
		return $data;
37
	}
38
39
	static private function uniChr($u) {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
40
 	   return mb_convert_encoding('&#' . intval($u) . ';', 'UTF-8', 'HTML-ENTITIES');
41
	}
42
43
	static private function uniChrCode($data) {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
44
	   list(, $ord) = unpack('N', mb_convert_encoding($data, 'UCS-4BE', 'UTF-8'));
45
	   return $ord;
46
	}
47
48
	static public function textWithEmoji($data) {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
49
		if($data=="") return false;
50
51
		$data = LaravelEmoji::covertEmojiToName($data);
52
		$data = LaravelEmoji::covertNameToEmoji($data);
53
54
		$CPString = "";
55
		$haut = 0;
56
		$n = 0;
0 ignored issues
show
Unused Code introduced by
$n is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
57
58
		$strLen = mb_strlen($data, 'UTF-8');
59
		for($i=0; $i<$strLen; $i++) {
60
			$char = mb_substr($data, $i, 1, 'UTF-8');
61
			$charCode = LaravelEmoji::uniChrCode($char);
62
63
			if($charCode>1000) {				
64
65
				if ($haut != 0) {
66
					if (0xDC00 <= $charCode&& $charCode<= 0xDFFF) {
67
						$CPString .= ' imgFront'. strtolower(dechex(0x10000 + (($haut - 0xD800) << 10) + ($charCode  - 0xDC00))) . 'imgBack ';
68
						$haut = 0;
69
						continue;
70
					}
71
					else {
72
						$CPString .=  'Error2' . strtolower(dechex($haut)) . '!';
73
						$haut = 0;
74
					}
75
				}
76
77
				if (0xD800 <= $charCode  && $charCode <= 0xDBFF) {
78
					$haut = $charCode;
79
				}
80
				else {
81
					$CPString .= ' imgFront'. strtolower(dechex($charCode)) . 'imgBack ';
82
				}
83
			}
84
			else {
85
				$CPString .= LaravelEmoji::uniChr($charCode);
86
			}
87
		}
88
89
		$CPString = str_replace('imgFront', '<img class="emoji-img" width="16" src="http://twemoji.maxcdn.com/16x16/', $CPString);
90
		$CPString = str_replace('imgBack', '.png"/>', $CPString);
91
		return $CPString;
92
	}
93
}
94