Passed
Push — master ( 57938a...4f08c0 )
by Takashi
06:38
created

EmojiManager::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Ttskch\Esa;
4
5
class EmojiManager
6
{
7
    /**
8
     * @var Proxy
9
     */
10
    private $esa;
11
12
    /**
13
     * @var array
14
     */
15
    private $emojis;
16
17
    public function __construct(Proxy $esa)
18
    {
19
        $this->esa = $esa;
20
        $this->emojis = $this->esa->getEmojis();
21
    }
22
23
    /**
24
     * @param $code
25
     * @return string
26
     */
27
    public function getImageUrl($code)
28
    {
29
        foreach ($this->emojis as $emoji) {
30
            if ($emoji['code'] === $code) {
31
                return $emoji['url'];
32
            }
33
34
            foreach ($emoji['aliases'] as $alias) {
35
                if ($alias === $code) {
36
                    return $emoji['url'];
37
                }
38
            }
39
        }
40
41
        throw new \LogicException('Undefined emoji code.');
42
    }
43
}
44