GetCollection   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 84.62%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 25
ccs 11
cts 13
cp 0.8462
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 21 3
1
<?php
2
/**
3
 * This file is part of the Drest package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author Lee Davis
9
 * @copyright Copyright (c) Lee Davis <@leedavis81>
10
 * @link https://github.com/leedavis81/drest/blob/master/LICENSE
11
 * @license http://opensource.org/licenses/MIT The MIT X License (MIT)
12
 */
13
namespace Drest\Service\Action;
14
15
use Doctrine\ORM;
16
use DrestCommon\Response\Response;
17
18
class GetCollection extends AbstractAction
19
{
20
21 14
    public function execute()
22
    {
23 14
        $classMetaData = $this->getMatchedRoute()->getClassMetaData();
24 14
        $em = $this->getEntityManager();
25
26 14
        $qb = $em->createQueryBuilder()->from($classMetaData->getClassName(), $classMetaData->getEntityAlias());
27 14
        $this->registerExposeFromMetaData($qb, $em->getClassMetadata($classMetaData->getClassName()));
28
29 14
        foreach ($this->getMatchedRoute()->getRouteParams() as $key => $value) {
30
            $qb->andWhere($classMetaData->getEntityAlias() . '.' . $key . ' = :' . $key);
31
            $qb->setParameter($key, $value);
32 14
        }
33
34
        try {
35 14
            $resultSet = $this->createResultSet($qb->getQuery()->getResult(ORM\Query::HYDRATE_ARRAY));
36 14
        } catch (\Exception $e) {
37 1
            return $this->handleError($e, Response::STATUS_CODE_404);
38
        }
39
40 13
        return $resultSet;
41
    }
42
}
43