GameResultTextExtractor::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace MiniGameMessageApp\Message;
4
5
use MessageApp\Message\TextExtractor\MessageTextExtractor;
6
use MiniGame\GameResult;
7
use RemiSan\Intl\TranslatableResource;
8
9
class GameResultTextExtractor implements MessageTextExtractor
10
{
11
    /**
12
     * @var MessageTextExtractor[]
13
     */
14
    private $gameResultExtractors;
15
16
    /**
17
     * Constructor.
18
     *
19
     * @param $gameResultExtractors
20
     */
21 9
    public function __construct(array $gameResultExtractors = [])
22
    {
23 9
        $this->gameResultExtractors = $gameResultExtractors;
24 9
    }
25
26
    /**
27
     * Extract the message from the game result.
28
     *
29
     * @param  object $object
30
     * @return TranslatableResource
31
     */
32 9
    public function extractMessage($object)
33
    {
34 9
        if (!$object instanceof GameResult) {
35 3
            return null;
36
        }
37
38 6
        foreach ($this->gameResultExtractors as $extractor) {
39 6
            if ($message = $extractor->extractMessage($object)) {
40 4
                return $message;
41
            }
42 2
        }
43
44 3
        throw new \InvalidArgumentException('Unsupported Game Result');
45
    }
46
}
47