EpicEmoji   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 71
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 9 2
A createDevice() 0 11 2
A buildDevice() 0 4 1
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
use Questocat\EpicEmoji\Devices\AbstractDevice;
15
use InvalidArgumentException;
16
17
class EpicEmoji
18
{
19
    /**
20
     * The array of created devices.
21
     *
22
     * @var array
23
     */
24
    protected $devices = [];
25
26
    /**
27
     * The initial devices.
28
     *
29
     * @var array
30
     */
31
    protected $initialUnicode = [
32
        'unified' => 'Unified',
33
        'softbank' => 'Softbank',
34
        'kddi' => 'Kddi',
35
        'google' => 'Google',
36
        'docomo' => 'Docomo',
37
    ];
38
39
    /**
40
     * @param string $name
41
     * @param string $arguments
42
     *
43
     * @return mixed
44
     */
45 16
    public function __call($name, $arguments)
46
    {
47 16
        if (!isset($this->devices[$name])) {
48 16
            $text = implode('', $arguments);
49 16
            $this->devices[$name] = $this->createDevice($name, $text);
50 15
        }
51
52 15
        return $this->devices[$name];
53
    }
54
55
    /**
56
     * Create a new devices instance.
57
     *
58
     * @param string $device
59
     * @param string $text
60
     *
61
     * @return mixed
62
     */
63 16
    protected function createDevice($device, $text)
64
    {
65 16
        if (isset($this->initialUnicode[$device])) {
66 15
            $device = ucfirst($device);
67 15
            $deviceClass = __NAMESPACE__.'\\Devices\\'.$device;
68
69 15
            return $this->buildDevice($deviceClass, $text);
70
        }
71
72 1
        throw new InvalidArgumentException("Devices [$device] not supported.");
73
    }
74
75
    /**
76
     * Build a device instance.
77
     *
78
     * @param string $device
79
     * @param string $text
80
     *
81
     * @return AbstractDevice
82
     */
83 15
    protected function buildDevice($device, $text)
84
    {
85 15
        return new $device($text);
86
    }
87
}
88