Dictionary   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 81
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A shorthandDict() 0 4 1
A unicodeDict() 0 6 1
A htmlDict() 0 6 1
A getDictByName() 0 12 2
1
<?php
2
3
/*
4
 * This file is part of questocat/epic-emoji package.
5
 *
6
 * (c) questocat <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Questocat\EpicEmoji;
13
14
class Dictionary implements DictionaryInterface
15
{
16
    /**
17
     * The dictionary path.
18
     *
19
     * @var string
20
     */
21
    protected $path;
22
23
    /**
24
     * Dictionary constructor.
25
     *
26
     * @param string $path
27
     */
28 4
    public function __construct($path)
29
    {
30 4
        $this->path = $path;
31 4
    }
32
33
    /**
34
     * Returns the name of shorthand dictionary.
35
     *
36
     * @param string $name
37
     *
38
     * @return array
39
     */
40 1
    public function shorthandDict($name)
41
    {
42 1
        return $this->getDictByName($name);
43
    }
44
45
    /**
46
     * Returns the name of unicode dictionary.
47
     *
48
     * @param string $name
49
     *
50
     * @return array
51
     */
52 2
    public function unicodeDict($name)
53
    {
54 2
        $name = sprintf('emoji_%s', $name);
55
56 2
        return $this->getDictByName($name);
57
    }
58
59
    /**
60
     * Returns the name of html dictionary.
61
     *
62
     * @param string $name
63
     *
64
     * @return array
65
     */
66 1
    public function htmlDict($name)
67
    {
68 1
        $name = sprintf('images16/%s_html', $name);
69
70 1
        return $this->getDictByName($name);
71
    }
72
73
    /**
74
     * Returns the dictionary.
75
     *
76
     * @param string $name
77
     *
78
     * @throws FileNotFoundException
79
     *
80
     * @return array
81
     */
82 4
    protected function getDictByName($name)
83
    {
84 4
        $path = $this->path.'/'.$name;
85
86 4
        if (file_exists($path)) {
87 3
            $dict = (array) include $path;
88
89 3
            return $dict;
90
        }
91
92 1
        throw new FileNotFoundException("Dictionary does not exist at path {$path}");
93
    }
94
}
95