DefaultHydrator::hydrate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
namespace Swm\Bundle\MailHookBundle\Hydrator;
4
5
use Swm\Bundle\MailHookBundle\Event\HookEventInterface;
6
use Swm\Bundle\MailHookBundle\Hook\HookInterface;
7
use Swm\Bundle\MailHookBundle\Hydrator\HydratorInterface;
8
9
class DefaultHydrator implements HydratorInterface
10
{
11
    /**
12
     * @param  HookInterface $apiService
13
     * @param  string        $entityName
14
     * @return mixed $entityName instance
15
     */
16
    public function hydrate(HookInterface $apiService, $entityName)
17
    {
18
        $hydratedEntity = new $entityName();
19
20
        if (!$hydratedEntity instanceof HookEventInterface) {
21
            throw new LogicException("Can't hydrate this event");
22
        }
23
24
        $hydratedEntity->setEmail($apiService->getEmail());
25
        $hydratedEntity->setName($apiService->getService());
26
        $hydratedEntity->setMetaData($apiService->getMetaData());
27
28
        return $hydratedEntity;
29
    }
30
}
31