Completed
Push — master ( 11be54...2c00e6 )
by Rémi
03:02
created

MiniGameMessageTextExtractor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 1
cbo 1
dl 0
loc 39
ccs 4
cts 4
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A extractMessage() 0 14 4
1
<?php
2
3
namespace MiniGameMessageApp\Message;
4
5
use MessageApp\Message\TextExtractor\MessageTextExtractor;
6
use MiniGame\GameResult;
7
8
class MiniGameMessageTextExtractor implements MessageTextExtractor
9
{
10
    /**
11
     * @var MessageTextExtractor[]
12
     */
13
    private $gameResultExtractors;
14
15
    /**
16
     * Constructor.
17 6
     *
18
     * @param $gameResultExtractors
19 6
     */
20 3
    public function __construct(array $gameResultExtractors = [])
21
    {
22
        $this->gameResultExtractors = $gameResultExtractors;
23 3
    }
24
25
    /**
26
     * Extract the message from the game result.
27
     *
28
     * @param  object $object
29
     * @param  string $languageIso
30
     * @return string
31
     */
32
    public function extractMessage($object, $languageIso)
33
    {
34
        if (!$object instanceof GameResult) {
35
            return null;
36
        }
37
38
        foreach ($this->gameResultExtractors as $extractor) {
39
            if ($message = $extractor->extractMessage($object, $languageIso)) {
40
                return $message;
41
            }
42
        }
43
44
        throw new \InvalidArgumentException('Unsupported Game Result');
45
    }
46
}
47