Completed
Push — master ( 7b9134...0b8956 )
by Rémi
02:47
created

UserEventTextExtractor::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 2
Bugs 0 Features 0
Metric Value
c 2
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 MessageApp\Message\TextExtractor;
4
5
use MessageApp\Event\UserEvent;
6
7
class UserEventTextExtractor implements MessageTextExtractor
8
{
9
    /**
10
     * @var MessageTextExtractor[]
11
     */
12
    private $gameResultExtractors;
13
14
    /**
15
     * Constructor.
16
     *
17
     * @param $gameResultExtractors
18
     */
19 9
    public function __construct(array $gameResultExtractors = [])
20
    {
21 9
        $this->gameResultExtractors = $gameResultExtractors;
22 9
    }
23
24
    /**
25
     * Extract the message from the game result.
26
     *
27
     * @param  object $object
28
     * @param  string $languageIso
29
     * @return string
30
     */
31 9
    public function extractMessage($object, $languageIso)
32
    {
33 9
        if (!$object instanceof UserEvent) {
34 3
            return null;
35
        }
36
37 6
        foreach ($this->gameResultExtractors as $extractor) {
38 3
            if ($message = $extractor->extractMessage($object, $languageIso)) {
39 3
                return $message;
40
            }
41 2
        }
42
43 3
        throw new \InvalidArgumentException('Unsupported User Event');
44
    }
45
}
46