Completed
Push — master ( a5631d...69c428 )
by Daniel
03:14
created

ChainAggregateIdExtractor::extract()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
crap 3
1
<?php
2
3
namespace DDDominio\EventSourcing\Common;
4
5
class ChainAggregateIdExtractor implements AggregateIdExtractorInterface
6
{
7
    /**
8
     * @var AggregateIdExtractorInterface[]
9
     */
10
    private $extractors = [];
11
12
    /**
13
     * @param AggregateIdExtractorInterface $aggregateIdExtractor
14
     */
15 4
    public function add(AggregateIdExtractorInterface $aggregateIdExtractor)
16
    {
17 4
        $this->extractors[] = $aggregateIdExtractor;
18 4
    }
19
20
    /**
21
     * @param object $aggregate
22
     * @return string
23
     */
24 5
    public function extract($aggregate)
25
    {
26 5
        foreach ($this->extractors as $extractor) {
27
            try {
28 4
                return $extractor->extract($aggregate);
29 2
            } catch (AggregateIdNotFoundException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
30
            }
31
        }
32 2
        throw new AggregateIdNotFoundException(sprintf('Id cannot be extracted from %s', get_class($aggregate)));
33
    }
34
}
35