Dictionary::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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