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

MethodAggregateIdExtractor::extract()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace DDDominio\EventSourcing\Common;
4
5
class MethodAggregateIdExtractor implements AggregateIdExtractorInterface
6
{
7
    /**
8
     * @var string
9
     */
10
    private $method;
11
12
    /**
13
     * @param string $method
14
     */
15 15
    public function __construct($method)
16
    {
17 15
        $this->method = $method;
18 15
    }
19
20
    /**
21
     * @param object $aggregate
22
     * @return string
23
     */
24 9
    public function extract($aggregate)
25
    {
26 9
        if (!method_exists($aggregate, $this->method)) {
27 1
            throw new AggregateIdNotFoundException(sprintf('No method "%s" found in %s', $this->method, get_class($aggregate)));
28
        }
29 8
        return (string) $aggregate->{$this->method}();
30
    }
31
}
32