GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Emoji   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 0
dl 0
loc 121
rs 10
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setCode() 0 4 1
A setName() 0 31 1
A getName() 0 4 1
A getCode() 0 4 1
A getCleanName() 0 4 1
A getConst() 0 4 1
A getMethod() 0 4 1
A toArray() 0 10 1
A jsonSerialize() 0 4 1
A offsetExists() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
1
<?php
2
3
namespace Spatie\Emoji\Generator;
4
5
use ArrayAccess;
6
use JsonSerializable;
7
8
class Emoji implements JsonSerializable, ArrayAccess
9
{
10
    /** @var string */
11
    protected $name;
12
13
    /** @var string */
14
    protected $code;
15
16
    /** @var string */
17
    protected $cleanName;
18
19
    /** @var string */
20
    protected $const;
21
22
    /** @var string */
23
    protected $method;
24
25
    public function __construct(string $name, string $code)
26
    {
27
        $this->setName($name);
28
        $this->setCode($code);
29
    }
30
31
    protected function setCode(string $code)
32
    {
33
        $this->code = '\u{'.implode('}\u{', explode(' ', $code)).'}';
34
    }
35
36
    protected function setName(string $name)
37
    {
38
        $name = str_replace([
39
            '*',
40
            '#',
41
            '1st',
42
            '2nd',
43
            '3rd',
44
            '&',
45
            'U.S.',
46
        ], [
47
            'asterisk',
48
            'hash',
49
            'first',
50
            'second',
51
            'third',
52
            'and',
53
            'US',
54
        ], $name);
55
56
        $name = strtr($name, [
57
            'Š'=>'S', 'š'=>'s', 'Đ'=>'Dj', 'đ'=>'dj', 'Ž'=>'Z', 'ž'=>'z', 'Č'=>'C', 'č'=>'c', 'Ć'=>'C', 'ć'=>'c', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'Ŕ'=>'R', 'ŕ'=>'r',
58
        ]);
59
60
        $name = preg_replace('/E[0-9]+\.[0-9] /', null, $name);
61
62
        $this->name = $name;
63
        $this->cleanName = mb_strtolower(preg_replace("/\s+/", ' ', preg_replace("/[^\w]+/", ' ', $this->name)));
64
        $this->const = 'CHARACTER_'.mb_strtoupper(preg_replace("/\s+/", '', preg_replace('/(.)(?= [a-z0-9])/', '$1_', $this->cleanName)));
65
        $this->method = lcfirst(preg_replace("/\s+/", '', ucwords($this->cleanName)));
66
    }
67
68
    public function getName(): string
69
    {
70
        return $this->name;
71
    }
72
73
    public function getCode(): string
74
    {
75
        return $this->code;
76
    }
77
78
    public function getCleanName(): string
79
    {
80
        return $this->cleanName;
81
    }
82
83
    public function getConst(): string
84
    {
85
        return $this->const;
86
    }
87
88
    public function getMethod(): string
89
    {
90
        return $this->method;
91
    }
92
93
    public function toArray(): array
94
    {
95
        return [
96
            'name' => $this->name,
97
            'code' => $this->code,
98
            'clean_name' => $this->cleanName,
99
            'const' => $this->const,
100
            'method' => $this->method,
101
        ];
102
    }
103
104
    public function jsonSerialize()
105
    {
106
        return $this->toArray();
107
    }
108
109
    public function offsetExists($offset)
110
    {
111
        return in_array($offset, array_keys($this->toArray()));
112
    }
113
114
    public function offsetGet($offset)
115
    {
116
        return $this->toArray()[$offset];
117
    }
118
119
    public function offsetSet($offset, $value)
120
    {
121
        // no public set allowed
122
    }
123
124
    public function offsetUnset($offset)
125
    {
126
        // no public unset allowed
127
    }
128
}
129