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

GameResultTextExtractor::extractMessage()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.2
cc 4
eloc 7
nc 4
nop 2
crap 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