Completed
Push — master ( 2c00e6...dd60cc )
by Rémi
03:55 queued 01:55
created

GameResultTextExtractor   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 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 39
ccs 11
cts 11
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 GameResultTextExtractor implements MessageTextExtractor
9
{
10
    /**
11
     * @var MessageTextExtractor[]
12
     */
13
    private $gameResultExtractors;
14
15
    /**
16
     * Constructor.
17
     *
18
     * @param $gameResultExtractors
19
     */
20 9
    public function __construct(array $gameResultExtractors = [])
21
    {
22 9
        $this->gameResultExtractors = $gameResultExtractors;
23 9
    }
24
25
    /**
26
     * Extract the message from the game result.
27
     *
28
     * @param  object $object
29
     * @param  string $languageIso
30
     * @return string
31
     */
32 9
    public function extractMessage($object, $languageIso)
33
    {
34 9
        if (!$object instanceof GameResult) {
35 3
            return null;
36
        }
37
38 6
        foreach ($this->gameResultExtractors as $extractor) {
39 3
            if ($message = $extractor->extractMessage($object, $languageIso)) {
40 3
                return $message;
41
            }
42 2
        }
43
44 3
        throw new \InvalidArgumentException('Unsupported Game Result');
45
    }
46
}
47