DeleteCollection   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 7
dl 0
loc 26
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 23 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 DrestCommon\Response\Response;
16
use DrestCommon\ResultSet;
17
18
class DeleteCollection extends AbstractAction
19
{
20 3
    public function execute()
21
    {
22 3
        $matchedRoute = $this->getMatchedRoute();
23 3
        $classMetaData = $matchedRoute->getClassMetaData();
24 3
        $elementName = $classMetaData->getEntityAlias();
25
26 3
        $em = $this->getEntityManager();
27
28 3
        $qb = $em->createQueryBuilder()->delete($classMetaData->getClassName(), $elementName);
29 3
        foreach ($matchedRoute->getRouteParams() as $key => $value) {
30 2
            $qb->andWhere($elementName . '.' . $key . ' = :' . $key);
31 2
            $qb->setParameter($key, $value);
32 3
        }
33
34
        try {
35 3
            $qb->getQuery()->execute();
36 2
            $this->getResponse()->setStatusCode(Response::STATUS_CODE_200);
37
38 2
            return ResultSet::create(['successfully deleted'], 'response');
39 1
        } catch (\Exception $e) {
40 1
            return $this->handleError($e, Response::STATUS_CODE_500);
41
        }
42
    }
43
}
44