Completed
Push — master ( cd391d...67f3cd )
by Pavel
01:53
created

DeleteAction::delete()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 12
loc 12
ccs 7
cts 7
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php namespace Pz\Doctrine\Rest\Action;
2
3
use Pz\Doctrine\Rest\Request\DeleteRequestInterface;
4
use Pz\Doctrine\Rest\RestRepository;
5
use Pz\Doctrine\Rest\RestResponseInterface;
6
7 View Code Duplication
trait DeleteAction
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
{
9
    /**
10
     * Doctrine repository from where get data.
11
     *
12
     * @return RestRepository
13
     */
14
    abstract protected function repository();
15
16
    /**
17
     * @return RestResponseInterface
18
     */
19
    abstract protected function response();
20
21
    /**
22
     * @param DeleteRequestInterface $request
23
     *
24
     * @return array
25
     */
26 2
    public function delete(DeleteRequestInterface $request)
27
    {
28 2
        if (null === ($entity = $this->repository()->find($request->getId()))) {
29 1
            return $this->response()->notFound($request);
30
        }
31
32 1
        $request->authorize($entity);
33
34 1
        $this->repository()->em()->remove($entity);
35 1
        $this->repository()->em()->flush();
36
37 1
        return $this->response()->delete($request, $entity);
38
    }
39
}
40