Completed
Push — master ( fc64c3...80f34d )
by Rémi
12:40
created

MiniGameMessageTextExtractor::extractMessage()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 22
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
rs 8.6737
cc 5
eloc 10
nc 5
nop 2
1
<?php
2
3
namespace MiniGameMessageApp\Message;
4
5
use MessageApp\Event\UnableToCreateUserEvent;
6
use MessageApp\Event\UserEvent;
7
use MessageApp\Message\MessageTextExtractor;
8
use MessageApp\Parser\Exception\MessageParserException;
9
use MiniGame\GameResult;
10
11
class MiniGameMessageTextExtractor implements MessageTextExtractor
12
{
13
    /**
14
     * Extract the message from the game result.
15
     *
16
     * @param  object $object
17
     * @param  string $languageIso
18
     * @return string
19
     */
20
    public function extractMessage($object, $languageIso)
21
    {
22
        // TODO retrieve and translate the message / remove getAsMessage
23
24
        if ($object instanceof GameResult) {
25
            return $object->getAsMessage();
26
        }
27
28
        if ($object instanceof UnableToCreateUserEvent) {
29
            return $object->getReason();
30
        }
31
32
        if ($object instanceof UserEvent) {
33
            return $object->getAsMessage();
34
        }
35
36
        if ($object instanceof MessageParserException) {
37
            return $object->getMessage();
38
        }
39
40
        return null;
41
    }
42
}
43