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

UserEventTextExtractor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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