Test Setup Failed
Pull Request — latest (#3)
by Mark
31:31
created

Emoji   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
eloc 17
c 1
b 0
f 1
dl 0
loc 57
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getParsedValue() 0 3 1
A __construct() 0 6 1
A getSkin() 0 9 2
A getParsedType() 0 3 1
A __call() 0 6 1
A __get() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace UnicornFail\Emoji\Node;
6
7
use UnicornFail\Emoji\Dataset\Dataset;
8
use UnicornFail\Emoji\Dataset\Emoji as DatasetEmoji;
9
use UnicornFail\Emoji\Emojibase\EmojibaseSkinsInterface;
10
11
/**
12
 * @property ?string $annotation
13
 * @property ?string $emoji
14
 * @property ?string $emoticon
15
 * @property ?int $gender
16
 * @property ?int $group
17
 * @property ?string $hexcode
18
 * @property ?string $htmlEntity
19
 * @property ?int $order
20
 * @property ?string $shortcode
21
 * @property string[] $shortcodes
22
 * @property Dataset $skins
23
 * @property ?int $subgroup
24
 * @property string[] $tags
25
 * @property ?string $text
26
 * @property int[] $tone
27
 * @property int $type
28
 * @property ?string $unicode
29
 * @property ?float $version
30
 *
31
 * @method string|null getShortcode(?array $exclude = null, bool $wrap = false)
32
 * @method string[] getShortcodes(?array $exclude = null)
33
 * @method string|\Stringable render()
34
 * @method void setRenderer(callable $renderer)
35
 */
36
final class Emoji extends AbstractStringContainer
37
{
38
    /** @var DatasetEmoji */
39
    private $datasetEmoji;
40
41
    /** @var int */
42
    private $parsedType;
43
44
    /** @var string */
45
    private $parsedValue;
46
47
    public function __construct(int $parsedType, string $parsedValue, DatasetEmoji $emoji)
48
    {
49
        parent::__construct($parsedValue);
50
        $this->datasetEmoji = $emoji;
51
        $this->parsedType   = $parsedType;
52
        $this->parsedValue  = $parsedValue;
53
    }
54
55
    /**
56
     * @param mixed[] $arguments
57
     *
58
     * @return ?mixed
59
     */
60
    public function __call(string $name, array $arguments)
61
    {
62
        /** @var callable $method */
63
        $method = [$this->datasetEmoji, $name];
64
65
        return \call_user_func_array($method, $arguments);
66
    }
67
68
    /** @return ?mixed */
69
    public function __get(string $name)
70
    {
71
        return $this->datasetEmoji->$name;
72
    }
73
74
    public function getParsedType(): int
75
    {
76
        return $this->parsedType;
77
    }
78
79
    public function getParsedValue(): string
80
    {
81
        return $this->parsedValue;
82
    }
83
84
    public function getSkin(int $tone = EmojibaseSkinsInterface::LIGHT_SKIN): ?self
85
    {
86
        $skin = $this->datasetEmoji->getSkin($tone);
87
88
        if ($skin === null) {
89
            return null;
90
        }
91
92
        return new self($this->parsedType, $this->parsedValue, $skin);
93
    }
94
}
95