Completed
Push — master ( 7a82a2...eef030 )
by Pavel
02:12
created

CanHydrate   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A hydrate() 0 6 2
1
<?php namespace Pz\Doctrine\Rest\Action;
2
3
use App\JsonApiHydrator;
4
use Doctrine\ORM\EntityManager;
5
use pmill\Doctrine\Hydrator\ArrayHydrator;
6
use Pz\Doctrine\Rest\RestRequestAbstract;
7
8
trait CanHydrate
9
{
10
    /**
11
     * @param string|object       $entity
12
     * @param EntityManager       $em
13
     * @param RestRequestAbstract $request
14
     *
15
     * @return object
16
     * @throws \Exception
17
     */
18
    protected function hydrate($entity, EntityManager $em, RestRequestAbstract $request)
19
    {
20
        $hydrator = $request->getContentType() === RestRequestAbstract::JSON_API_CONTENT_TYPE ?
21
            new JsonApiHydrator($em) : new ArrayHydrator($em);
22
23
        return $hydrator->hydrate($entity, $request->request->all());
24
    }
25
}
26