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

MethodAggregateIdExtractor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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