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

MiniGameMessageTextExtractor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 32
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B extractMessage() 0 22 5
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