CompositeTextExtractor   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

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
use RemiSan\Intl\TranslatableResource;
6
7
class CompositeTextExtractor implements MessageTextExtractor
8
{
9
    /**
10
     * @var MessageTextExtractor[]
11
     */
12
    private $extractors;
13
14
    /**
15
     * Constructor.
16
     *
17
     * @param array $extractors
18
     */
19 6
    public function __construct(array $extractors = [])
20
    {
21 6
        $this->extractors = $extractors;
22 6
    }
23
24
    /**
25
     * @param MessageTextExtractor $extractor
26
     */
27 3
    public function addExtractor(MessageTextExtractor $extractor)
28
    {
29 3
        $this->extractors[] = $extractor;
30 3
    }
31
32
    /**
33
     * Extract the message from the game result.
34
     *
35
     * @param  object $object
36
     * @return TranslatableResource
37
     */
38 6
    public function extractMessage($object)
39
    {
40 6
        foreach ($this->extractors as $extractor) {
41 3
            if ($message = $extractor->extractMessage($object)) {
42 3
                return $message;
43
            }
44 4
        }
45
46 3
        return null;
47
    }
48
}
49