Completed
Push — 1.0 ( 6b593a...b97499 )
by David
02:19
created

EmojiGenerator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getEmoji() 0 11 3
A createCrapScoreEmojiGenerator() 0 13 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
            10 => ':neutral_face:',
35
            20 => ':sweat:',
36
            30 => ':slight_frown:',
37
            100 => ':sob:',
38
            300 => ':scream:',
39
            900 => ':skull_crossbones::interrobang::radioactive:'
40
        ];
41
        return new self($emojiMap);
42
    }
43
}