Completed
Push — master ( 13e9af...c4aa22 )
by Rémi
03:22
created

CompositeTextExtractor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 43
ccs 0
cts 12
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addExtractor() 0 4 1
A extractMessage() 0 10 3
1
<?php
2
3
namespace MessageApp\Message\TextExtractor;
4
5
class CompositeTextExtractor implements MessageTextExtractor
6
{
7
    /**
8
     * @var MessageTextExtractor[]
9
     */
10
    private $extractors;
11
12
    /**
13
     * Constructor.
14
     *
15
     * @param array $extractors
16
     */
17
    public function __construct(array $extractors = [])
18
    {
19
        $this->extractors = $extractors;
20
    }
21
22
    /**
23
     * @param MessageTextExtractor $extractor
24
     */
25
    public function addExtractor(MessageTextExtractor $extractor)
26
    {
27
        $this->extractors[] = $extractor;
28
    }
29
30
    /**
31
     * Extract the message from the game result.
32
     *
33
     * @param  object $object
34
     * @param  string $languageIso
35
     * @return string
36
     */
37
    public function extractMessage($object, $languageIso)
38
    {
39
        foreach ($this->extractors as $extractor) {
40
            if ($message = $extractor->extractMessage($object, $languageIso)) {
41
                return $message;
42
            }
43
        }
44
45
        return null;
46
    }
47
}
48