GameResultTextExtractor   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 38
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
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