EmojiHelper   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 26
ccs 11
cts 11
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A filter() 0 17 3
1
<?php
2
3
namespace Fatindeed\EmojiHelper;
4
5
class EmojiHelper
6
{
7
    /**
8
     * Remove emoji characters from a given string.
9
     *
10
     * @param string $value Input value.
11
     *
12
     * @return string|null
13
     */
14 6
    public static function filter($value)
15
    {
16 6
        static $patterns = null;
17 6
        static $replacements = null;
18 6
        if (is_null($patterns)) {
19 1
            $data = include __DIR__ . '/../config/emoji-data.php';
20 1
            $patterns = array_map(
21
                function ($code) {
22 1
                    return '/[' . $code . ']/u';
23 1
                },
24
                $data
25
            );
26
        }
27 6
        if (is_null($replacements)) {
28 1
            $replacements = array_pad([], count($patterns), '');
29
        }
30 6
        return preg_replace($patterns, $replacements, $value);
31
    }
32
}
33