Total Complexity | 9 |
Total Lines | 73 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
5 | class Emoticon |
||
6 | { |
||
7 | private $list; |
||
8 | |||
9 | 8 | public function __construct() |
|
12 | 8 | } |
|
13 | |||
14 | /** |
||
15 | * Get a single emoji. |
||
16 | * |
||
17 | * @param string $name |
||
18 | * |
||
19 | * @return bool|mixed |
||
20 | */ |
||
21 | 6 | public function get(string $name) |
|
29 | } |
||
30 | |||
31 | /** |
||
32 | * Replace all :emoji: with the actual emoji. |
||
33 | * |
||
34 | * @param string $text |
||
35 | * |
||
36 | * @return string |
||
37 | */ |
||
38 | public function emojify(string $text): string |
||
39 | { |
||
40 | 4 | return preg_replace_callback('/:([a-zA-Z0-9_\-+]+):/', function ($match) { |
|
41 | 4 | $emoji = $this->get($match[1]); |
|
42 | |||
43 | 4 | return false !== $emoji ? $emoji : $match[0]; |
|
44 | 4 | }, $text); |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * Returns array of items with matching emoji. |
||
49 | * |
||
50 | * @param string $emoji |
||
51 | * |
||
52 | * @return array |
||
53 | */ |
||
54 | public function search(string $emoji): array |
||
55 | { |
||
56 | 1 | return array_filter($this->list, function ($item) use ($emoji) { |
|
57 | 1 | return strpos($item, $emoji) !== false; |
|
58 | 1 | }, ARRAY_FILTER_USE_KEY); |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * Generate a random emoji. |
||
63 | */ |
||
64 | 1 | public function random() |
|
67 | } |
||
68 | |||
69 | 6 | protected function stripColons(string $item): string |
|
80 |