| Conditions | 4 |
| Paths | 6 |
| Total Lines | 20 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | 3 | public function extract($aggregate) |
|
| 15 | { |
||
| 16 | 3 | $reflection = new \ReflectionClass($aggregate); |
|
| 17 | 3 | $annotationReader = new AnnotationReader(); |
|
| 18 | 3 | $aggregateIdMethodName = null; |
|
| 19 | 3 | foreach ($reflection->getMethods() as $reflectionMethod) { |
|
| 20 | 2 | $annotation = $annotationReader->getMethodAnnotation( |
|
| 21 | $reflectionMethod, |
||
| 22 | 2 | AggregateId::class |
|
| 23 | ); |
||
| 24 | 2 | if (!is_null($annotation)) { |
|
| 25 | 2 | $aggregateIdMethodName = $reflectionMethod->getName(); |
|
|
|
|||
| 26 | 2 | break; |
|
| 27 | } |
||
| 28 | } |
||
| 29 | 3 | if (is_null($aggregateIdMethodName)) { |
|
| 30 | 1 | throw new AggregateIdNotFoundException(sprintf('No "@AggregateId" annotation found in %s', get_class($aggregate))); |
|
| 31 | } |
||
| 32 | 2 | return (string) $aggregate->{$aggregateIdMethodName}(); |
|
| 33 | } |
||
| 34 | } |
||
| 35 |