Passed
Branch master (4f08c0)
by Takashi
07:18 queued 05:07
created

EmojiManager::getImageUrl()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 7
nc 2
nop 1
dl 0
loc 15
rs 8.8571
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