Passed
Branch php70 (a6ded4)
by Dennis
08:04
created

EmojiMapping::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * (c) Dennis Meckel
5
 *
6
 * For the full copyright and license information,
7
 * please view the LICENSE file that was distributed with this source code.
8
 */
9
10
namespace Rayne\Ecoji;
11
12
use InvalidArgumentException;
13
use OutOfBoundsException;
14
15
/**
16
 * Mapping implementation with the default emoji set defined by the "Ecoji/Encoji Standard".
17
 *
18
 * @see https://github.com/keith-turner/ecoji
19
 */
20
class EmojiMapping implements EmojiMappingInterface
21
{
22
    /**
23
     * @var string[]
24
     */
25
    private $emojis;
26
27
    /**
28
     * @var string[]
29
     */
30
    private $revEmojis;
31
32
    /**
33
     * @var string
34
     */
35
    private $padding = '☕';
36
37
    /**
38
     * @var string
39
     */
40
    private $padding40 = '⚜';
41
42
    /**
43
     * @var string
44
     */
45
    private $padding41 = '🏍';
46
47
    /**
48
     * @var string
49
     */
50
    private $padding42 = '📑';
51
52
    /**
53
     * @var string
54
     */
55
    private $padding43 = '🙋';
56
57
    /**
58
     *
59
     */
60 1605
    public function __construct()
61
    {
62 1605
        $this->emojis = require dirname(__DIR__) . '/assets/emojis.php';
63
64 1605
        $this->revEmojis = array_flip($this->emojis);
65 1605
        $this->revEmojis[$this->padding] = 0;
66 1605
    }
67
68
    /**
69
     * @inheritdoc
70
     */
71 792
    public function getEmoji(int $id): string
72
    {
73 792
        if (!isset($this->emojis[$id])) {
74 6
            throw new OutOfBoundsException('Invalid ID: ' . $id);
75
        }
76
77 786
        return $this->emojis[$id];
78
    }
79
80
    /**
81
     * @inheritdoc
82
     */
83 798
    public function getId(string $emoji): int
84
    {
85 798
        if (!isset($this->revEmojis[$emoji])) {
86 3
            throw new InvalidArgumentException('Invalid rune: ' . $emoji);
87
        }
88
89 795
        return $this->revEmojis[$emoji];
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->revEmojis[$emoji] returns the type string which is incompatible with the type-hinted return integer.
Loading history...
90
    }
91
92
    /**
93
     * @inheritdoc
94
     */
95 1188
    public function getPadding(): string
96
    {
97 1188
        return $this->padding;
98
    }
99
100
    /**
101
     * @inheritdoc
102
     */
103 888
    public function getPadding40(): string
104
    {
105 888
        return $this->padding40;
106
    }
107
108
    /**
109
     * @inheritdoc
110
     */
111 807
    public function getPadding41(): string
112
    {
113 807
        return $this->padding41;
114
    }
115
116
    /**
117
     * @inheritdoc
118
     */
119 702
    public function getPadding42(): string
120
    {
121 702
        return $this->padding42;
122
    }
123
124
    /**
125
     * @inheritdoc
126
     */
127 600
    public function getPadding43(): string
128
    {
129 600
        return $this->padding43;
130
    }
131
}
132