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

UserEventTextExtractor::__construct()   A

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 1
Bugs 0 Features 0
Metric Value
c 1
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 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