EmojiGenerator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getEmoji() 0 11 3
A createCrapScoreEmojiGenerator() 0 14 1
1
<?php
2
3
4
namespace TheCodingMachine\WashingMachine\Gitlab;
5
6
/**
7
 * Class in charge of choosing the appropriate Emoji.
8
 */
9
class EmojiGenerator
10
{
11
    private $emojiMap;
12
13
    public function __construct(array $emojiMap)
14
    {
15
        $this->emojiMap = $emojiMap;
16
    }
17
18
    public function getEmoji(float $score) : string
19
    {
20
        $lastValue = '';
21
        foreach ($this->emojiMap as $priority => $value) {
22
            if ($priority > $score) {
23
                return $lastValue;
24
            }
25
            $lastValue = $value;
26
        }
27
        return $lastValue;
28
    }
29
30
    public static function createCrapScoreEmojiGenerator() : self
31
    {
32
        $emojiMap = [
33
            1 => ':innocent:',
34
            31 => ':neutral_face:',
35
            50 => ':sweat:',
36
            80 => ':slight_frown:',
37
            120 => ':sob:',
38
            300 => ':scream:',
39
            600 => ':radioactive:',
40
            900 => ':skull_crossbones:'
41
        ];
42
        return new self($emojiMap);
43
    }
44
}
45